Class SignalOmemoKeyUtil


  • public class SignalOmemoKeyUtil
    extends OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
    Concrete implementation of the KeyUtil for an implementation using the Signal library.
    • Method Detail

      • generateOmemoIdentityKeyPair

        public org.whispersystems.libsignal.IdentityKeyPair generateOmemoIdentityKeyPair()
        Description copied from class: OmemoKeyUtil
        Generate a new IdentityKeyPair. We should always have only one pair and usually keep this for a long time.
        Specified by:
        generateOmemoIdentityKeyPair in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Returns:
        deserialized identity key pair
      • generateOmemoPreKeys

        public TreeMap<Integer,​org.whispersystems.libsignal.state.PreKeyRecord> generateOmemoPreKeys​(int currentPreKeyId,
                                                                                                           int count)
        Description copied from class: OmemoKeyUtil
        Generate 'count' new PreKeys beginning with id 'startId'. These preKeys are published and can be used by contacts to establish sessions with us.
        Specified by:
        generateOmemoPreKeys in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        currentPreKeyId - start id
        count - how many keys do we want to generate
        Returns:
        Map of new preKeys
      • generateOmemoSignedPreKey

        public org.whispersystems.libsignal.state.SignedPreKeyRecord generateOmemoSignedPreKey​(org.whispersystems.libsignal.IdentityKeyPair identityKeyPair,
                                                                                               int currentPreKeyId)
                                                                                        throws CorruptedOmemoKeyException
        Description copied from class: OmemoKeyUtil
        Generate a new signed preKey.
        Specified by:
        generateOmemoSignedPreKey in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKeyPair - identityKeyPair used to sign the preKey
        currentPreKeyId - id that the preKey will have
        Returns:
        deserialized signed preKey
        Throws:
        CorruptedOmemoKeyException - when the identityKeyPair is invalid
      • signedPreKeyFromBytes

        public org.whispersystems.libsignal.state.SignedPreKeyRecord signedPreKeyFromBytes​(byte[] data)
                                                                                    throws IOException
        Description copied from class: OmemoKeyUtil
        Deserialize a signedPreKey from a byte array.
        Specified by:
        signedPreKeyFromBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        data - byte array
        Returns:
        deserialized signed preKey
        Throws:
        IOException - when something goes wrong
      • signedPreKeyToBytes

        public byte[] signedPreKeyToBytes​(org.whispersystems.libsignal.state.SignedPreKeyRecord signedPreKeyRecord)
        Description copied from class: OmemoKeyUtil
        Serialize a signedPreKey into a byte array.
        Specified by:
        signedPreKeyToBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        signedPreKeyRecord - signedPreKey
        Returns:
        byte array
      • rawSessionFromBytes

        public org.whispersystems.libsignal.state.SessionRecord rawSessionFromBytes​(byte[] data)
                                                                             throws IOException
        Description copied from class: OmemoKeyUtil
        Deserialize a raw OMEMO Session from bytes.
        Specified by:
        rawSessionFromBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        data - bytes
        Returns:
        raw OMEMO Session
        Throws:
        IOException - when something goes wrong
      • rawSessionToBytes

        public byte[] rawSessionToBytes​(org.whispersystems.libsignal.state.SessionRecord session)
        Description copied from class: OmemoKeyUtil
        Serialize a raw OMEMO session into a byte array.
        Specified by:
        rawSessionToBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        session - raw session
        Returns:
        byte array
      • identityKeyPairFromBytes

        public org.whispersystems.libsignal.IdentityKeyPair identityKeyPairFromBytes​(byte[] data)
                                                                              throws CorruptedOmemoKeyException
        Description copied from class: OmemoKeyUtil
        Deserialize an identityKeyPair from a byte array.
        Specified by:
        identityKeyPairFromBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        data - byte array
        Returns:
        IdentityKeyPair (T_IdKeyPair)
        Throws:
        CorruptedOmemoKeyException - if the key is damaged of malformed
      • identityKeyFromBytes

        public org.whispersystems.libsignal.IdentityKey identityKeyFromBytes​(byte[] data)
                                                                      throws CorruptedOmemoKeyException
        Description copied from class: OmemoKeyUtil
        Deserialize an identityKey from a byte array.
        Specified by:
        identityKeyFromBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        data - byte array
        Returns:
        identityKey (T_IdKey)
        Throws:
        CorruptedOmemoKeyException - if the key is damaged or malformed
      • ellipticCurvePublicKeyFromBytes

        public org.whispersystems.libsignal.ecc.ECPublicKey ellipticCurvePublicKeyFromBytes​(byte[] data)
                                                                                     throws CorruptedOmemoKeyException
        Description copied from class: OmemoKeyUtil
        Deserialize an elliptic curve public key from bytes.
        Specified by:
        ellipticCurvePublicKeyFromBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        data - bytes
        Returns:
        elliptic curve public key (T_ECPub)
        Throws:
        CorruptedOmemoKeyException - if the key is damaged or malformed
      • preKeyToBytes

        public byte[] preKeyToBytes​(org.whispersystems.libsignal.state.PreKeyRecord preKeyRecord)
        Description copied from class: OmemoKeyUtil
        Serialize a preKey into a byte array.
        Specified by:
        preKeyToBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        preKeyRecord - preKey
        Returns:
        byte[]
      • preKeyFromBytes

        public org.whispersystems.libsignal.state.PreKeyRecord preKeyFromBytes​(byte[] bytes)
                                                                        throws IOException
        Description copied from class: OmemoKeyUtil
        Deserialize a preKey from a byte array.
        Specified by:
        preKeyFromBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        bytes - byte array
        Returns:
        deserialized preKey
        Throws:
        IOException - when something goes wrong
      • bundleFromOmemoBundle

        public org.whispersystems.libsignal.state.PreKeyBundle bundleFromOmemoBundle​(OmemoBundleElement bundle,
                                                                                     OmemoDevice contact,
                                                                                     int preKeyId)
                                                                              throws CorruptedOmemoKeyException
        Description copied from class: OmemoKeyUtil
        Build a crypto-lib specific PreKeyBundle (T_Bundle) using a PreKey from the OmemoBundleElement 'bundle'. The PreKeyBundle will contain the identityKey, signedPreKey and signature, as well as a preKey from the OmemoBundleElement.
        Specified by:
        bundleFromOmemoBundle in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        bundle - OmemoBundleElement
        contact - Contact that the bundle belongs to
        preKeyId - id of the preKey that will be selected from the OmemoBundleElement and that the PreKeyBundle will contain
        Returns:
        PreKeyBundle (T_PreKey)
        Throws:
        CorruptedOmemoKeyException - if some key is damaged or malformed
      • signedPreKeySignatureFromKey

        public byte[] signedPreKeySignatureFromKey​(org.whispersystems.libsignal.state.SignedPreKeyRecord signedPreKey)
        Description copied from class: OmemoKeyUtil
        Extract the signature from a signedPreKey.
        Specified by:
        signedPreKeySignatureFromKey in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        signedPreKey - signedPreKey
        Returns:
        signature as byte array
      • signedPreKeyIdFromKey

        public int signedPreKeyIdFromKey​(org.whispersystems.libsignal.state.SignedPreKeyRecord signedPreKey)
        Description copied from class: OmemoKeyUtil
        return the id of the given signedPreKey.
        Specified by:
        signedPreKeyIdFromKey in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        signedPreKey - key
        Returns:
        id of the key
      • identityKeyPairToBytes

        public byte[] identityKeyPairToBytes​(org.whispersystems.libsignal.IdentityKeyPair identityKeyPair)
        Description copied from class: OmemoKeyUtil
        serialize an identityKeyPair into bytes.
        Specified by:
        identityKeyPairToBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKeyPair - identityKeyPair
        Returns:
        byte array
      • identityKeyFromPair

        public org.whispersystems.libsignal.IdentityKey identityKeyFromPair​(org.whispersystems.libsignal.IdentityKeyPair identityKeyPair)
        Description copied from class: OmemoKeyUtil
        Extract the public identityKey from an identityKeyPair.
        Specified by:
        identityKeyFromPair in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKeyPair - keyPair
        Returns:
        public key of the pair
      • identityKeyForBundle

        public byte[] identityKeyForBundle​(org.whispersystems.libsignal.IdentityKey identityKey)
        Description copied from class: OmemoKeyUtil
        Prepare an identityKey for transport in an OmemoBundleElement (serialize it).
        Specified by:
        identityKeyForBundle in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKey - identityKey that will be transported
        Returns:
        key as byte array
      • identityKeyToBytes

        public byte[] identityKeyToBytes​(org.whispersystems.libsignal.IdentityKey identityKey)
        Description copied from class: OmemoKeyUtil
        Serialize an identityKey into bytes.
        Specified by:
        identityKeyToBytes in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKey - idKey
        Returns:
        byte array representation of the identity key.
      • preKeyPublicKeyForBundle

        public byte[] preKeyPublicKeyForBundle​(org.whispersystems.libsignal.ecc.ECPublicKey preKey)
        Description copied from class: OmemoKeyUtil
        Prepare an elliptic curve preKey for transport in an OmemoBundleElement.
        Specified by:
        preKeyPublicKeyForBundle in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        preKey - key
        Returns:
        key as byte array
      • preKeyForBundle

        public byte[] preKeyForBundle​(org.whispersystems.libsignal.state.PreKeyRecord preKeyRecord)
        Description copied from class: OmemoKeyUtil
        Prepare a preKey for transport in an OmemoBundleElement.
        Specified by:
        preKeyForBundle in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        preKeyRecord - preKey
        Returns:
        key as byte array
      • signedPreKeyPublicForBundle

        public byte[] signedPreKeyPublicForBundle​(org.whispersystems.libsignal.state.SignedPreKeyRecord signedPreKey)
        Description copied from class: OmemoKeyUtil
        Prepare a public signedPreKey for transport in a bundle.
        Specified by:
        signedPreKeyPublicForBundle in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        signedPreKey - signedPreKey
        Returns:
        signedPreKey as byte array
      • getFingerprintOfIdentityKey

        public OmemoFingerprint getFingerprintOfIdentityKey​(org.whispersystems.libsignal.IdentityKey identityKey)
        Description copied from class: OmemoKeyUtil
        Return the fingerprint of an identityKey.
        Specified by:
        getFingerprintOfIdentityKey in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKey - identityKey
        Returns:
        fingerprint of the key
      • getFingerprintOfIdentityKeyPair

        public OmemoFingerprint getFingerprintOfIdentityKeyPair​(org.whispersystems.libsignal.IdentityKeyPair identityKeyPair)
        Description copied from class: OmemoKeyUtil
        Returns the fingerprint of the public key of an identityKeyPair.
        Specified by:
        getFingerprintOfIdentityKeyPair in class OmemoKeyUtil<org.whispersystems.libsignal.IdentityKeyPair,​org.whispersystems.libsignal.IdentityKey,​org.whispersystems.libsignal.state.PreKeyRecord,​org.whispersystems.libsignal.state.SignedPreKeyRecord,​org.whispersystems.libsignal.state.SessionRecord,​org.whispersystems.libsignal.ecc.ECPublicKey,​org.whispersystems.libsignal.state.PreKeyBundle>
        Parameters:
        identityKeyPair - IdentityKeyPair.
        Returns:
        fingerprint of the public key.