Class EstablishedSas
- All Implemented Interfaces:
AutoCloseable
An EstablishedSas is obtained by calling
Sas.diffieHellman(String) with the other party's public key. Once
established, it can be used to:
- Generate
SasBytes(emoji indices, decimal numbers, raw bytes) for visual key verification viabytes(String) - Generate and verify MACs to cryptographically confirm the shared
secret via
calculateMac(String, String)andverifyMac(String, String, String)
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
-
Method Summary
Modifier and TypeMethodDescriptionGeneratesSasBytesusing HKDF with the shared secret as the input key material.byte[]Generates the given number of bytes using HKDF with the shared secret as the input key material.calculateMac(String input, String info) Calculates a MAC for the given input using the info string as additional data.calculateMacInvalidBase64(String input, String info) Calculates a MAC for the given input using the info string as additional data, returning the MAC as an invalid base64-encoded string.Returns the public key that was created by us, that was used to establish the shared secret.Returns the public key that was created by the other party, that was used to establish the shared secret.voidVerifies a MAC that was previously created usingcalculateMac(String, String).Methods inherited from class NativeHandle
checkNotClosed, close, invalidate, nativePtr
-
Method Details
-
bytes
GeneratesSasBytesusing HKDF with the shared secret as the input key material.The info string should be agreed upon beforehand — both parties need to use the same info string.
- Parameters:
info- the info string, agreed upon by both parties- Returns:
- a new
SasBytescontaining emoji indices, decimals, and raw bytes - Throws:
IllegalStateException- if thisEstablishedSashas been closed
-
bytesRaw
Generates the given number of bytes using HKDF with the shared secret as the input key material.The info string should be agreed upon beforehand — both parties need to use the same info string. The number of bytes that can be generated is limited to 32 * 255 = 8160 bytes.
- Parameters:
info- the info string, agreed upon by both partiescount- the number of bytes to generate- Returns:
- an array of bytes
- Throws:
IllegalStateException- if thisEstablishedSashas been closedSasException- if the requested count exceeds the maximum
-
calculateMac
Calculates a MAC for the given input using the info string as additional data.This should be used to calculate a MAC of the Ed25519 identity key of an
Account.- Parameters:
input- the input string to MACinfo- the info string, agreed upon by both parties- Returns:
- the MAC as a base64-encoded string
- Throws:
IllegalStateException- if thisEstablishedSashas been closed
-
calculateMacInvalidBase64
Calculates a MAC for the given input using the info string as additional data, returning the MAC as an invalid base64-encoded string.Warning: This method should never be used unless you require libolm compatibility. Libolm used to incorrectly encode their MAC because the input buffer was reused as the output buffer. This method replicates the buggy behaviour.
- Parameters:
input- the input string to MACinfo- the info string, agreed upon by both parties- Returns:
- the MAC as an invalid base64-encoded string
- Throws:
IllegalStateException- if thisEstablishedSashas been closed
-
verifyMac
Verifies a MAC that was previously created usingcalculateMac(String, String).Users should calculate a MAC and send it to the other side, they should then verify each other's MAC using this method.
- Parameters:
input- the input string that was MAC-edinfo- the info string, agreed upon by both partiesmac- the MAC received from the other user, as a base64-encoded string- Throws:
IllegalStateException- if thisEstablishedSashas been closedSasException- if the MAC verification fails
-
ourPublicKey
Returns the public key that was created by us, that was used to establish the shared secret.- Returns:
- the base64-encoded public key
- Throws:
IllegalStateException- if thisEstablishedSashas been closed
-
theirPublicKey
Returns the public key that was created by the other party, that was used to establish the shared secret.- Returns:
- the base64-encoded public key
- Throws:
IllegalStateException- if thisEstablishedSashas been closed
-