Class OmemoStore<T_IdKeyPair,​T_IdKey,​T_PreKey,​T_SigPreKey,​T_Sess,​T_Addr,​T_ECPub,​T_Bundle,​T_Ciph>

  • Type Parameters:
    T_IdKeyPair - IdentityKeyPair class
    T_IdKey - IdentityKey class
    T_PreKey - PreKey class
    T_SigPreKey - SignedPreKey class
    T_Sess - Session class
    T_Addr - Address class
    T_ECPub - Elliptic Curve PublicKey class
    T_Bundle - Bundle class
    T_Ciph - Cipher class
    Direct Known Subclasses:
    CachingOmemoStore, FileBasedOmemoStore, SignalOmemoStore

    public abstract class OmemoStore<T_IdKeyPair,​T_IdKey,​T_PreKey,​T_SigPreKey,​T_Sess,​T_Addr,​T_ECPub,​T_Bundle,​T_Ciph>
    extends java.lang.Object
    Class that presents some methods that are used to load/generate/store keys and session data needed for OMEMO.
    • Constructor Detail

      • OmemoStore

        public OmemoStore()
        Create a new OmemoStore.
    • Method Detail

      • localDeviceIdsOf

        public abstract java.util.SortedSet<java.lang.Integer> localDeviceIdsOf​(BareJid localUser)
        Returns a sorted set of all the deviceIds, the localUser has had data stored under in the store. Basically this returns the deviceIds of all "accounts" of localUser, which are known to the store.
        Parameters:
        localUser - BareJid of the user.
        Returns:
        set of deviceIds with available data.
      • generateOmemoIdentityKeyPair

        public T_IdKeyPair generateOmemoIdentityKeyPair()
        Generate a new IdentityKeyPair. We should always have only one pair and usually keep this for a long time.
        Returns:
        a fresh identityKeyPair
      • storeOmemoIdentityKeyPair

        public abstract void storeOmemoIdentityKeyPair​(OmemoDevice userDevice,
                                                       T_IdKeyPair identityKeyPair)
                                                throws java.io.IOException
        Store our identityKeyPair in storage. It would be a cool feature, if the key could be stored in a encrypted database or something similar.
        Parameters:
        userDevice - our OmemoDevice.
        identityKeyPair - identityKeyPair
        Throws:
        java.io.IOException - if an I/O error occurred.
      • loadOmemoIdentityKey

        public abstract T_IdKey loadOmemoIdentityKey​(OmemoDevice userDevice,
                                                     OmemoDevice contactsDevice)
                                              throws CorruptedOmemoKeyException,
                                                     java.io.IOException
        Load the public identityKey of a device.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - the device of which we want to load the identityKey.
        Returns:
        loaded identityKey
        Throws:
        CorruptedOmemoKeyException - when the key in question is corrupted and cant be deserialized.
        java.io.IOException - if an I/O error occurred.
      • storeOmemoIdentityKey

        public abstract void storeOmemoIdentityKey​(OmemoDevice userDevice,
                                                   OmemoDevice contactsDevice,
                                                   T_IdKey contactsKey)
                                            throws java.io.IOException
        Store the public identityKey of the device.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - device.
        contactsKey - identityKey belonging to the contactsDevice.
        Throws:
        java.io.IOException - if an I/O error occurred.
      • removeOmemoIdentityKey

        public abstract void removeOmemoIdentityKey​(OmemoDevice userDevice,
                                                    OmemoDevice contactsDevice)
        Removes the identityKey of a device.
        Parameters:
        userDevice - our omemoDevice.
        contactsDevice - device of which we want to delete the identityKey.
      • storeOmemoMessageCounter

        public abstract void storeOmemoMessageCounter​(OmemoDevice userDevice,
                                                      OmemoDevice contactsDevice,
                                                      int counter)
                                               throws java.io.IOException
        Store the number of messages we sent to a device since we last received a message back. This counter gets reset to 0 whenever we receive a message from the contacts device.
        Parameters:
        userDevice - our omemoDevice.
        contactsDevice - device of which we want to set the message counter.
        counter - counter value.
        Throws:
        java.io.IOException - if an I/O error occurred.
      • loadOmemoMessageCounter

        public abstract int loadOmemoMessageCounter​(OmemoDevice userDevice,
                                                    OmemoDevice contactsDevice)
                                             throws java.io.IOException
        Return the current value of the message counter. This counter represents the number of message we sent to the contactsDevice without getting a reply back. The default value for this counter is 0.
        Parameters:
        userDevice - our omemoDevice
        contactsDevice - device of which we want to get the message counter.
        Returns:
        counter value.
        Throws:
        java.io.IOException - if an I/O error occurred.
      • setDateOfLastReceivedMessage

        public abstract void setDateOfLastReceivedMessage​(OmemoDevice userDevice,
                                                          OmemoDevice contactsDevice,
                                                          java.util.Date date)
                                                   throws java.io.IOException
        Set the date of the last message that was received from a device.
        Parameters:
        userDevice - omemoManager of our device.
        contactsDevice - device in question
        date - date of the last received message
        Throws:
        java.io.IOException - if an I/O error occurred.
      • getDateOfLastReceivedMessage

        public abstract java.util.Date getDateOfLastReceivedMessage​(OmemoDevice userDevice,
                                                                    OmemoDevice contactsDevice)
                                                             throws java.io.IOException
        Return the date of the last message that was received from device 'from'.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - device in question
        Returns:
        date if existent, null
        Throws:
        java.io.IOException - if an I/O error occurred.
      • setDateOfLastDeviceIdPublication

        public abstract void setDateOfLastDeviceIdPublication​(OmemoDevice userDevice,
                                                              OmemoDevice contactsDevice,
                                                              java.util.Date date)
                                                       throws java.io.IOException
        Set the date of the last time the deviceId was published. This method only gets called, when the deviceId was inactive/non-existent before it was published.
        Parameters:
        userDevice - our OmemoDevice
        contactsDevice - OmemoDevice in question
        date - date of the last publication after not being published
        Throws:
        java.io.IOException - if an I/O error occurred.
      • getDateOfLastDeviceIdPublication

        public abstract java.util.Date getDateOfLastDeviceIdPublication​(OmemoDevice userDevice,
                                                                        OmemoDevice contactsDevice)
                                                                 throws java.io.IOException
        Return the date of the last time the deviceId was published after previously being not published. (Point in time, where the status of the deviceId changed from inactive/non-existent to active).
        Parameters:
        userDevice - our OmemoDevice
        contactsDevice - OmemoDevice in question
        Returns:
        date of the last publication after not being published
        Throws:
        java.io.IOException - if an I/O error occurred.
      • setDateOfLastSignedPreKeyRenewal

        public abstract void setDateOfLastSignedPreKeyRenewal​(OmemoDevice userDevice,
                                                              java.util.Date date)
                                                       throws java.io.IOException
        Set the date of the last time the signed preKey was renewed.
        Parameters:
        userDevice - our OmemoDevice.
        date - date
        Throws:
        java.io.IOException - if an I/O error occurred.
      • getDateOfLastSignedPreKeyRenewal

        public abstract java.util.Date getDateOfLastSignedPreKeyRenewal​(OmemoDevice userDevice)
                                                                 throws java.io.IOException
        Get the date of the last time the signed preKey was renewed.
        Parameters:
        userDevice - our OmemoDevice.
        Returns:
        date if existent, otherwise null
        Throws:
        java.io.IOException - if an I/O error occurred.
      • generateOmemoPreKeys

        public java.util.TreeMap<java.lang.Integer,​T_PreKeygenerateOmemoPreKeys​(int startId,
                                                                                        int count)
        Generate 'count' new PreKeys beginning with id 'startId'. These preKeys are published and can be used by contacts to establish sessions with us.
        Parameters:
        startId - start id
        count - how many keys do we want to generate
        Returns:
        Map of new preKeys
      • loadOmemoPreKey

        public abstract T_PreKey loadOmemoPreKey​(OmemoDevice userDevice,
                                                 int preKeyId)
                                          throws java.io.IOException
        Load the preKey with id 'preKeyId' from storage.
        Parameters:
        userDevice - our OmemoDevice.
        preKeyId - id of the key to be loaded
        Returns:
        loaded preKey
        Throws:
        java.io.IOException - if an I/O error occurred.
      • storeOmemoPreKey

        public abstract void storeOmemoPreKey​(OmemoDevice userDevice,
                                              int preKeyId,
                                              T_PreKey preKey)
                                       throws java.io.IOException
        Store a PreKey in storage.
        Parameters:
        userDevice - our OmemoDevice.
        preKeyId - id of the key
        preKey - key
        Throws:
        java.io.IOException - if an I/O error occurred.
      • storeOmemoPreKeys

        public void storeOmemoPreKeys​(OmemoDevice userDevice,
                                      java.util.TreeMap<java.lang.Integer,​T_PreKey> preKeyHashMap)
                               throws java.io.IOException
        Store a whole bunch of preKeys.
        Parameters:
        userDevice - our OmemoDevice.
        preKeyHashMap - HashMap of preKeys
        Throws:
        java.io.IOException - if an I/O error occurred.
      • removeOmemoPreKey

        public abstract void removeOmemoPreKey​(OmemoDevice userDevice,
                                               int preKeyId)
        Remove a preKey from storage. This is called, when a contact used one of our preKeys to establish a session with us.
        Parameters:
        userDevice - our OmemoDevice.
        preKeyId - id of the used key that will be deleted
      • loadOmemoPreKeys

        public abstract java.util.TreeMap<java.lang.Integer,​T_PreKeyloadOmemoPreKeys​(OmemoDevice userDevice)
                                                                                      throws java.io.IOException
        Return all our current OmemoPreKeys.
        Parameters:
        userDevice - our OmemoDevice.
        Returns:
        Map containing our preKeys
        Throws:
        java.io.IOException - if an I/O error occurred.
      • loadOmemoSignedPreKey

        public abstract T_SigPreKey loadOmemoSignedPreKey​(OmemoDevice userDevice,
                                                          int signedPreKeyId)
                                                   throws java.io.IOException
        Return the signedPreKey with the id 'singedPreKeyId'.
        Parameters:
        userDevice - our OmemoDevice.
        signedPreKeyId - id of the key
        Returns:
        loaded signed preKey
        Throws:
        java.io.IOException - if an I/O error occurred.
      • loadOmemoSignedPreKeys

        public abstract java.util.TreeMap<java.lang.Integer,​T_SigPreKeyloadOmemoSignedPreKeys​(OmemoDevice userDevice)
                                                                                               throws java.io.IOException
        Load all our signed PreKeys.
        Parameters:
        userDevice - our OmemoDevice.
        Returns:
        HashMap of our singedPreKeys
        Throws:
        java.io.IOException - if an I/O error occurred.
      • storeOmemoSignedPreKey

        public abstract void storeOmemoSignedPreKey​(OmemoDevice userDevice,
                                                    int signedPreKeyId,
                                                    T_SigPreKey signedPreKey)
                                             throws java.io.IOException
        Store a signedPreKey in storage.
        Parameters:
        userDevice - our OmemoDevice.
        signedPreKeyId - id of the signedPreKey
        signedPreKey - the key itself
        Throws:
        java.io.IOException - if an I/O error occurred.
      • removeOmemoSignedPreKey

        public abstract void removeOmemoSignedPreKey​(OmemoDevice userDevice,
                                                     int signedPreKeyId)
        Remove a signedPreKey from storage.
        Parameters:
        userDevice - our OmemoDevice.
        signedPreKeyId - id of the key that will be removed
      • loadRawSession

        public abstract T_Sess loadRawSession​(OmemoDevice userDevice,
                                              OmemoDevice contactsDevice)
                                       throws java.io.IOException
        Load the crypto-lib specific session object of the device from storage.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - device whose session we want to load
        Returns:
        crypto related session
        Throws:
        java.io.IOException - if an I/O error occurred.
      • loadAllRawSessionsOf

        public abstract java.util.HashMap<java.lang.Integer,​T_SessloadAllRawSessionsOf​(OmemoDevice userDevice,
                                                                                               BareJid contact)
                                                                                        throws java.io.IOException
        Load all crypto-lib specific session objects of contact 'contact'.
        Parameters:
        userDevice - our OmemoDevice.
        contact - BareJid of the contact we want to get all sessions from
        Returns:
        TreeMap of deviceId and sessions of the contact
        Throws:
        java.io.IOException - if an I/O error occurred.
      • storeRawSession

        public abstract void storeRawSession​(OmemoDevice userDevice,
                                             OmemoDevice contactsDevice,
                                             T_Sess session)
                                      throws java.io.IOException
        Store a crypto-lib specific session to storage.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - OmemoDevice whose session we want to store
        session - session
        Throws:
        java.io.IOException - if an I/O error occurred.
      • removeRawSession

        public abstract void removeRawSession​(OmemoDevice userDevice,
                                              OmemoDevice contactsDevice)
        Remove a crypto-lib specific session from storage.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - device whose session we want to delete
      • removeAllRawSessionsOf

        public abstract void removeAllRawSessionsOf​(OmemoDevice userDevice,
                                                    BareJid contact)
        Remove all crypto-lib specific session of a contact.
        Parameters:
        userDevice - our OmemoDevice.
        contact - BareJid of the contact
      • containsRawSession

        public abstract boolean containsRawSession​(OmemoDevice userDevice,
                                                   OmemoDevice contactsDevice)
        Return true, if we have a session with the device, otherwise false. Hint for Signal: Do not try 'return getSession() != null' since this will create a new session.
        Parameters:
        userDevice - our OmemoDevice.
        contactsDevice - device
        Returns:
        true if we have session, otherwise false
      • loadCachedDeviceList

        public abstract OmemoCachedDeviceList loadCachedDeviceList​(OmemoDevice userDevice,
                                                                   BareJid contact)
                                                            throws java.io.IOException
        Load a list of deviceIds from contact 'contact' from the local cache.
        Parameters:
        userDevice - our OmemoDevice.
        contact - contact we want to get the deviceList of
        Returns:
        CachedDeviceList of the contact
        Throws:
        java.io.IOException - if an I/O error occurred.
      • loadCachedDeviceList

        public OmemoCachedDeviceList loadCachedDeviceList​(OmemoDevice userDevice)
                                                   throws java.io.IOException
        Load a list of deviceIds from our own devices.
        Parameters:
        userDevice - our own OMEMO device
        Returns:
        the cached OMEMO device list.
        Throws:
        java.io.IOException - if an I/O error occurred.
      • storeCachedDeviceList

        public abstract void storeCachedDeviceList​(OmemoDevice userDevice,
                                                   BareJid contact,
                                                   OmemoCachedDeviceList contactsDeviceList)
                                            throws java.io.IOException
        Store the DeviceList of the contact in local storage. See this as a cache.
        Parameters:
        userDevice - our OmemoDevice.
        contact - Contact
        contactsDeviceList - list of the contacts devices' ids.
        Throws:
        java.io.IOException - if an I/O error occurred.
      • purgeOwnDeviceKeys

        public abstract void purgeOwnDeviceKeys​(OmemoDevice userDevice)
        Delete this device's IdentityKey, PreKeys, SignedPreKeys and Sessions.
        Parameters:
        userDevice - our OmemoDevice.