Class OpenPgpManager

    • Method Detail

      • getInstanceFor

        public static OpenPgpManager getInstanceFor​(org.jivesoftware.smack.XMPPConnection connection)
        Get the instance of the OpenPgpManager which belongs to the connection.
        Parameters:
        connection - xmpp connection.
        Returns:
        instance of the manager.
      • getJidOrThrow

        public org.jxmpp.jid.BareJid getJidOrThrow()
                                            throws org.jivesoftware.smack.SmackException.NotLoggedInException
        Return our own BareJid.
        Returns:
        our bareJid
        Throws:
        org.jivesoftware.smack.SmackException.NotLoggedInException - in case our connection is not logged in, which means our BareJid is unknown.
      • setOpenPgpProvider

        public void setOpenPgpProvider​(OpenPgpProvider provider)
        Set the OpenPgpProvider which will be used to process incoming OpenPGP elements, as well as to execute cryptographic operations.
        Parameters:
        provider - OpenPgpProvider.
      • getOpenPgpSelf

        public OpenPgpSelf getOpenPgpSelf()
                                   throws org.jivesoftware.smack.SmackException.NotLoggedInException
        Get our OpenPGP self.
        Returns:
        self TODO javadoc me please
        Throws:
        org.jivesoftware.smack.SmackException.NotLoggedInException - if we are not logged in
      • announceSupportAndPublish

        public void announceSupportAndPublish()
                                       throws java.security.NoSuchAlgorithmException,
                                              java.security.NoSuchProviderException,
                                              java.lang.InterruptedException,
                                              org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                              org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                              org.jivesoftware.smack.SmackException.NotConnectedException,
                                              org.jivesoftware.smack.SmackException.NoResponseException,
                                              java.io.IOException,
                                              java.security.InvalidAlgorithmParameterException,
                                              org.jivesoftware.smack.SmackException.NotLoggedInException,
                                              org.bouncycastle.openpgp.PGPException
        Generate a fresh OpenPGP key pair, given we don't have one already. Publish the public key to the Public Key Node and update the Public Key Metadata Node with our keys fingerprint. Lastly register a PepListener which listens for updates to Public Key Metadata Nodes.
        Throws:
        java.security.NoSuchAlgorithmException - if we are missing an algorithm to generate a fresh key pair.
        java.security.NoSuchProviderException - if we are missing a suitable Provider.
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if one of the PubSub nodes is not a LeafNode.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        java.io.IOException - IO is dangerous.
        java.security.InvalidAlgorithmParameterException - if illegal algorithm parameters are used for key generation.
        org.jivesoftware.smack.SmackException.NotLoggedInException - if we are not logged in.
        org.bouncycastle.openpgp.PGPException - if something goes wrong during key loading/generating
      • generateAndImportKeyPair

        public org.pgpainless.key.OpenPgpV4Fingerprint generateAndImportKeyPair​(org.jxmpp.jid.BareJid ourJid)
                                                                         throws java.security.NoSuchAlgorithmException,
                                                                                java.security.InvalidAlgorithmParameterException,
                                                                                java.security.NoSuchProviderException,
                                                                                org.bouncycastle.openpgp.PGPException,
                                                                                java.io.IOException
        Generate a fresh OpenPGP key pair and import it.
        Parameters:
        ourJid - our BareJid.
        Returns:
        OpenPgpV4Fingerprint of the generated key.
        Throws:
        java.security.NoSuchAlgorithmException - if the JVM doesn't support one of the used algorithms.
        java.security.InvalidAlgorithmParameterException - if the used algorithm parameters are invalid.
        java.security.NoSuchProviderException - if we are missing a cryptographic provider.
        org.bouncycastle.openpgp.PGPException - PGP is brittle.
        java.io.IOException - IO is dangerous.
      • generateKeyRing

        public org.pgpainless.key.collection.PGPKeyRing generateKeyRing​(org.jxmpp.jid.BareJid ourJid)
                                                                 throws org.bouncycastle.openpgp.PGPException,
                                                                        java.security.NoSuchAlgorithmException,
                                                                        java.security.NoSuchProviderException,
                                                                        java.security.InvalidAlgorithmParameterException
        Throws:
        org.bouncycastle.openpgp.PGPException
        java.security.NoSuchAlgorithmException
        java.security.NoSuchProviderException
        java.security.InvalidAlgorithmParameterException
      • getOurFingerprint

        public org.pgpainless.key.OpenPgpV4Fingerprint getOurFingerprint()
                                                                  throws org.jivesoftware.smack.SmackException.NotLoggedInException,
                                                                         java.io.IOException,
                                                                         org.bouncycastle.openpgp.PGPException
        Return the upper-case hex encoded OpenPGP v4 fingerprint of our key pair.
        Returns:
        fingerprint.
        Throws:
        org.jivesoftware.smack.SmackException.NotLoggedInException - in case we are not logged in.
        java.io.IOException - IO is dangerous.
        org.bouncycastle.openpgp.PGPException - PGP is brittle.
      • getOpenPgpContact

        public OpenPgpContact getOpenPgpContact​(org.jxmpp.jid.EntityBareJid jid)
        Return an OpenPGP capable contact. This object can be used as an entry point to OpenPGP related API.
        Parameters:
        jid - BareJid of the contact.
        Returns:
        OpenPgpContact.
      • hasSecretKeysAvailable

        public boolean hasSecretKeysAvailable()
                                       throws org.jivesoftware.smack.SmackException.NotLoggedInException,
                                              org.bouncycastle.openpgp.PGPException,
                                              java.io.IOException
        Return true, if we have a secret key available, otherwise false.
        Returns:
        true if secret key available
        Throws:
        org.jivesoftware.smack.SmackException.NotLoggedInException - If we are not logged in (we need to know our jid in order to look up our keys in the key store.
        org.bouncycastle.openpgp.PGPException - in case the keys in the store are damaged somehow.
        java.io.IOException - IO is dangerous.
      • serverSupportsSecretKeyBackups

        public static boolean serverSupportsSecretKeyBackups​(org.jivesoftware.smack.XMPPConnection connection)
                                                      throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                             org.jivesoftware.smack.SmackException.NotConnectedException,
                                                             java.lang.InterruptedException,
                                                             org.jivesoftware.smack.SmackException.NoResponseException
        Determine, if we can sync secret keys using private PEP nodes as described in the XEP. Requirements on the server side are support for PEP and support for the whitelist access model of PubSub.
        Parameters:
        connection - XMPP connection
        Returns:
        true, if the server supports secret key backups, otherwise false.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected.
        java.lang.InterruptedException - if the thread is interrupted.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        See Also:
        XEP-0373 §5
      • stopMetadataListener

        public void stopMetadataListener()
        Remove the metadata listener. This method is mainly used in tests.
      • backupSecretKeyToServer

        public OpenPgpSecretKeyBackupPassphrase backupSecretKeyToServer​(SecretKeyBackupSelectionCallback selectKeyCallback)
                                                                 throws java.lang.InterruptedException,
                                                                        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                                                        org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                        org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                        org.jivesoftware.smack.SmackException.NoResponseException,
                                                                        org.jivesoftware.smack.SmackException.NotLoggedInException,
                                                                        java.io.IOException,
                                                                        org.jivesoftware.smack.SmackException.FeatureNotSupportedException,
                                                                        org.bouncycastle.openpgp.PGPException,
                                                                        MissingOpenPgpKeyException
        Upload the encrypted secret key to a private PEP node.
        Parameters:
        selectKeyCallback - callback, which will receive the users choice of which keys will be backed up.
        Returns:
        secret key passphrase used to encrypt the backup.
        Throws:
        java.lang.InterruptedException - if the thread is interrupted.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if the private node is not a LeafNode.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        org.jivesoftware.smack.SmackException.NotLoggedInException - if we are not logged in.
        java.io.IOException - IO is dangerous.
        org.jivesoftware.smack.SmackException.FeatureNotSupportedException - if the server doesn't support the PubSub whitelist access model.
        org.bouncycastle.openpgp.PGPException - PGP is brittle
        MissingOpenPgpKeyException - in case we have no OpenPGP key pair to back up.
        See Also:
        XEP-0373 §5
      • backupSecretKeyToServer

        public void backupSecretKeyToServer​(SecretKeyBackupSelectionCallback selectKeyCallback,
                                            OpenPgpSecretKeyBackupPassphrase passphrase)
                                     throws java.lang.InterruptedException,
                                            org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                            org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                            org.jivesoftware.smack.SmackException.NotConnectedException,
                                            org.jivesoftware.smack.SmackException.NoResponseException,
                                            org.jivesoftware.smack.SmackException.NotLoggedInException,
                                            java.io.IOException,
                                            org.jivesoftware.smack.SmackException.FeatureNotSupportedException,
                                            org.bouncycastle.openpgp.PGPException,
                                            MissingOpenPgpKeyException
        Upload the encrypted secret key to a private PEP node. The backup is encrypted using the provided secret key passphrase.
        Parameters:
        selectKeyCallback - callback, which will receive the users choice of which keys will be backed up. @param selectKeyCallback
        passphrase - secret key passphrase
        Throws:
        java.lang.InterruptedException - if the thread is interrupted.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if the private node is not a LeafNode.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        org.jivesoftware.smack.SmackException.NotLoggedInException - if we are not logged in.
        java.io.IOException - IO is dangerous.
        org.jivesoftware.smack.SmackException.FeatureNotSupportedException - if the server doesn't support the PubSub whitelist access model.
        org.bouncycastle.openpgp.PGPException - PGP is brittle
        MissingOpenPgpKeyException - in case we have no OpenPGP key pair to back up.
        See Also:
        XEP-0373 §5
      • deleteSecretKeyServerBackup

        public void deleteSecretKeyServerBackup()
                                         throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                org.jivesoftware.smack.SmackException.NotConnectedException,
                                                java.lang.InterruptedException,
                                                org.jivesoftware.smack.SmackException.NoResponseException,
                                                org.jivesoftware.smack.SmackException.NotLoggedInException
        Delete the private LeafNode containing our secret key backup.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected.
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        org.jivesoftware.smack.SmackException.NotLoggedInException - if we are not logged in.
      • restoreSecretKeyServerBackup

        public org.pgpainless.key.OpenPgpV4Fingerprint restoreSecretKeyServerBackup​(AskForBackupCodeCallback codeCallback)
                                                                             throws java.lang.InterruptedException,
                                                                                    org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                                                                    org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                                                    org.jivesoftware.smack.SmackException.NotConnectedException,
                                                                                    org.jivesoftware.smack.SmackException.NoResponseException,
                                                                                    InvalidBackupCodeException,
                                                                                    org.jivesoftware.smack.SmackException.NotLoggedInException,
                                                                                    java.io.IOException,
                                                                                    MissingUserIdOnKeyException,
                                                                                    NoBackupFoundException,
                                                                                    org.bouncycastle.openpgp.PGPException
        Fetch a secret key backup from the server and try to restore a selected secret key from it.
        Parameters:
        codeCallback - callback for prompting the user to provide the secret backup code.
        Returns:
        fingerprint of the restored secret key
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if the private node is not a LeafNode.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        InvalidBackupCodeException - if the user-provided backup code is invalid.
        org.jivesoftware.smack.SmackException.NotLoggedInException - if we are not logged in
        java.io.IOException - IO is dangerous
        MissingUserIdOnKeyException - if the key that is to be imported is missing a user-id with our jid
        NoBackupFoundException - if no secret key backup has been found
        org.bouncycastle.openpgp.PGPException - in case the restored secret key is damaged.
      • decryptOpenPgpElement

        public OpenPgpMessage decryptOpenPgpElement​(OpenPgpElement element,
                                                    OpenPgpContact sender)
                                             throws org.jivesoftware.smack.SmackException.NotLoggedInException,
                                                    java.io.IOException,
                                                    org.bouncycastle.openpgp.PGPException
        Decrypt and or verify an OpenPgpElement and return the decrypted OpenPgpMessage.
        Parameters:
        element - OpenPgpElement containing the message.
        sender - OpenPgpContact who sent the message.
        Returns:
        decrypted and/or verified message
        Throws:
        org.jivesoftware.smack.SmackException.NotLoggedInException - in case we aren't logged in (we need to know our jid)
        java.io.IOException - IO error (reading keys, streams etc)
        org.bouncycastle.openpgp.PGPException - in case of an PGP error
      • registerSigncryptReceivedListener

        public void registerSigncryptReceivedListener​(SigncryptElementReceivedListener listener)
        Register a SigncryptElementReceivedListener on the OpenPgpManager. That listener will get informed whenever a SigncryptElement has been received and successfully decrypted. Note: This method is not intended for clients to listen for incoming SigncryptElements. Instead its purpose is to allow easy extension of XEP-0373 for custom OpenPGP profiles such as OpenPGP for XMPP: Instant Messaging.
        Parameters:
        listener - listener that gets registered