Class Sas

java.lang.Object
io.github.fherbreteau.vodozemac.NativeHandle
io.github.fherbreteau.vodozemac.sas.Sas
All Implemented Interfaces:
AutoCloseable

public final class Sas extends NativeHandle
User-friendly key verification using short authentication strings (SAS).

The verification process is heavily inspired by Phil Zimmermann's ZRTP key agreement handshake. A core part of key agreement in ZRTP is the hash commitment: the party that begins the key sharing process sends a hash of their part of the Diffie-Hellman exchange but does not send the part itself until they have received the other party's part.

The verification process can be used to verify the Ed25519 identity key of an Account.

This class implements AutoCloseable and should be used in a try-with-resources block to ensure native resources are properly released.

Author:
François HERBRETEAU
  • Constructor Details

    • Sas

      public Sas()
      Creates a new random verification object.

      This creates an ephemeral curve25519 keypair that can be used to establish a shared secret.

  • Method Details

    • publicKey

      public String publicKey()
      Returns the public key that can be used to establish a shared secret.
      Returns:
      the base64-encoded public key
      Throws:
      IllegalStateException - if this Sas has been closed or consumed by diffieHellman(String)
    • diffieHellman

      public EstablishedSas diffieHellman(String theirPublicKey)
      Establishes a SAS secret by performing a Diffie-Hellman handshake with another public key.

      This method consumes the Sas object — after this call, the Sas is invalidated and can no longer be used. The native resources are transferred to the returned EstablishedSas.

      Parameters:
      theirPublicKey - a base64-encoded Curve25519 public key
      Returns:
      a new EstablishedSas which can be used to generate SasBytes and calculate MACs
      Throws:
      IllegalStateException - if this Sas has already been closed or consumed
      KeyException - if the given public key is invalid or cannot be decoded