Class OpenPgpPubSubUtil


  • public class OpenPgpPubSubUtil
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PEP_NODE_PUBLIC_KEYS
      Name of the OX metadata node.
      static java.lang.String PEP_NODE_PUBLIC_KEYS_NOTIFY
      Feature to be announced using the ServiceDiscoveryManager to subscribe to the OX metadata node.
      static java.lang.String PEP_NODE_SECRET_KEY
      Name of the OX secret key node.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void changeAccessModelIfNecessary​(org.jivesoftware.smackx.pubsub.LeafNode node, org.jivesoftware.smackx.pubsub.AccessModel accessModel)
      Query the access model of node.
      static boolean deletePubkeysListNode​(org.jivesoftware.smackx.pep.PepManager pepManager)
      Delete our metadata node.
      static boolean deletePublicKeyNode​(org.jivesoftware.smackx.pep.PepManager pepManager, org.pgpainless.key.OpenPgpV4Fingerprint fingerprint)
      Delete the public key node of the key with fingerprint fingerprint.
      static boolean deleteSecretKeyNode​(org.jivesoftware.smackx.pep.PepManager pepManager)
      Delete the private backup node.
      static void depositSecretKey​(org.jivesoftware.smack.XMPPConnection connection, SecretkeyElement element)
      Publishes a SecretkeyElement to the secret key node.
      static PubkeyElement fetchPubkey​(org.jivesoftware.smack.XMPPConnection connection, org.jxmpp.jid.BareJid contact, org.pgpainless.key.OpenPgpV4Fingerprint v4_fingerprint)
      Fetch the OpenPGP public key of a contact, identified by its OpenPGP v4_fingerprint.
      static PublicKeysListElement fetchPubkeysList​(org.jivesoftware.smack.XMPPConnection connection)
      Consult the public key metadata node and fetch a list of all of our published OpenPGP public keys.
      static PublicKeysListElement fetchPubkeysList​(org.jivesoftware.smack.XMPPConnection connection, org.jxmpp.jid.BareJid contact)
      Consult the public key metadata node of contact to fetch the list of their published OpenPGP public keys.
      static SecretkeyElement fetchSecretKey​(org.jivesoftware.smackx.pep.PepManager pepManager)
      Fetch the latest SecretkeyElement from the private backup node.
      static org.jivesoftware.smackx.pubsub.LeafNode getOpenLeafNode​(org.jivesoftware.smackx.pubsub.PubSubManager pubSubManager, java.lang.String nodeName)
      Use reflection magic to get a LeafNode without doing a disco#info query.
      static java.lang.String PEP_NODE_PUBLIC_KEY​(org.pgpainless.key.OpenPgpV4Fingerprint id)
      Name of the OX public key node, which contains the key with id id.
      static void publishPublicKey​(org.jivesoftware.smackx.pep.PepManager pepManager, PubkeyElement pubkeyElement, org.pgpainless.key.OpenPgpV4Fingerprint fingerprint)
      Publish the users OpenPGP public key to the public key node if necessary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PEP_NODE_SECRET_KEY

        public static final java.lang.String PEP_NODE_SECRET_KEY
        Name of the OX secret key node.
        See Also:
        Constant Field Values
      • PEP_NODE_PUBLIC_KEYS_NOTIFY

        public static final java.lang.String PEP_NODE_PUBLIC_KEYS_NOTIFY
        Feature to be announced using the ServiceDiscoveryManager to subscribe to the OX metadata node.
        See Also:
        XEP-0373 §4.4, Constant Field Values
    • Constructor Detail

      • OpenPgpPubSubUtil

        public OpenPgpPubSubUtil()
    • Method Detail

      • PEP_NODE_PUBLIC_KEY

        public static java.lang.String PEP_NODE_PUBLIC_KEY​(org.pgpainless.key.OpenPgpV4Fingerprint id)
        Name of the OX public key node, which contains the key with id id.
        Parameters:
        id - upper case hex encoded OpenPGP v4 fingerprint of the key.
        Returns:
        PEP node name.
      • changeAccessModelIfNecessary

        public static void changeAccessModelIfNecessary​(org.jivesoftware.smackx.pubsub.LeafNode node,
                                                        org.jivesoftware.smackx.pubsub.AccessModel accessModel)
                                                 throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                        org.jivesoftware.smack.SmackException.NotConnectedException,
                                                        java.lang.InterruptedException,
                                                        org.jivesoftware.smack.SmackException.NoResponseException
        Query the access model of node. If it is different from accessModel, change the access model of the node to accessModel.
        Parameters:
        node - LeafNode whose PubSub access model we want to change
        accessModel - new access model.
        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-0060 §4.5 - Node Access Models
      • publishPublicKey

        public static void publishPublicKey​(org.jivesoftware.smackx.pep.PepManager pepManager,
                                            PubkeyElement pubkeyElement,
                                            org.pgpainless.key.OpenPgpV4Fingerprint fingerprint)
                                     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
        Publish the users OpenPGP public key to the public key node if necessary. Also announce the key to other users by updating the metadata node.
        Parameters:
        pepManager - The PEP manager.
        pubkeyElement - PubkeyElement containing the public key
        fingerprint - fingerprint of the public key
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if either the metadata node or the public key 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.
        See Also:
        XEP-0373 §4.1
      • fetchPubkeysList

        public static PublicKeysListElement fetchPubkeysList​(org.jivesoftware.smack.XMPPConnection connection)
                                                      throws java.lang.InterruptedException,
                                                             org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                             org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException,
                                                             org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                                             org.jivesoftware.smack.SmackException.NotConnectedException,
                                                             org.jivesoftware.smack.SmackException.NoResponseException
        Consult the public key metadata node and fetch a list of all of our published OpenPGP public keys.
        Parameters:
        connection - XMPP connection
        Returns:
        content of our metadata node.
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol exception.
        org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException - in case the queried entity is not a PubSub node
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - in case the queried node is not a LeafNode
        org.jivesoftware.smack.SmackException.NotConnectedException - in case we are not connected
        org.jivesoftware.smack.SmackException.NoResponseException - in case the server doesn't respond
        See Also:
        XEP-0373 §4.3: Discovering Public Keys of a User
      • fetchPubkeysList

        public static PublicKeysListElement fetchPubkeysList​(org.jivesoftware.smack.XMPPConnection connection,
                                                             org.jxmpp.jid.BareJid contact)
                                                      throws java.lang.InterruptedException,
                                                             org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                             org.jivesoftware.smack.SmackException.NoResponseException,
                                                             org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                                             org.jivesoftware.smack.SmackException.NotConnectedException,
                                                             org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException
        Consult the public key metadata node of contact to fetch the list of their published OpenPGP public keys.
        Parameters:
        connection - XMPP connection
        contact - BareJid of the user we want to fetch the list from.
        Returns:
        content of contact's metadata node.
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol exception.
        org.jivesoftware.smack.SmackException.NoResponseException - in case the server doesn't respond
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - in case the queried node is not a LeafNode
        org.jivesoftware.smack.SmackException.NotConnectedException - in case we are not connected
        org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException - in case the queried entity is not a PubSub node
        See Also:
        XEP-0373 §4.3: Discovering Public Keys of a User
      • deletePubkeysListNode

        public static boolean deletePubkeysListNode​(org.jivesoftware.smackx.pep.PepManager pepManager)
                                             throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                    org.jivesoftware.smack.SmackException.NotConnectedException,
                                                    java.lang.InterruptedException,
                                                    org.jivesoftware.smack.SmackException.NoResponseException
        Delete our metadata node.
        Parameters:
        pepManager - The PEP manager.
        Returns:
        true if the node existed and was deleted, false if the node did not exist.
        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.
      • deletePublicKeyNode

        public static boolean deletePublicKeyNode​(org.jivesoftware.smackx.pep.PepManager pepManager,
                                                  org.pgpainless.key.OpenPgpV4Fingerprint fingerprint)
                                           throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                  org.jivesoftware.smack.SmackException.NotConnectedException,
                                                  java.lang.InterruptedException,
                                                  org.jivesoftware.smack.SmackException.NoResponseException
        Delete the public key node of the key with fingerprint fingerprint.
        Parameters:
        pepManager - The PEP manager.
        fingerprint - fingerprint of the key we want to delete
        Returns:
        true if the node existed and was deleted, false if the node did not exist.
        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.
      • fetchPubkey

        public static PubkeyElement fetchPubkey​(org.jivesoftware.smack.XMPPConnection connection,
                                                org.jxmpp.jid.BareJid contact,
                                                org.pgpainless.key.OpenPgpV4Fingerprint v4_fingerprint)
                                         throws java.lang.InterruptedException,
                                                org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException,
                                                org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException,
                                                org.jivesoftware.smack.SmackException.NotConnectedException,
                                                org.jivesoftware.smack.SmackException.NoResponseException
        Fetch the OpenPGP public key of a contact, identified by its OpenPGP v4_fingerprint.
        Parameters:
        connection - XMPP connection
        contact - BareJid of the contact we want to fetch a key from.
        v4_fingerprint - upper case, hex encoded v4 fingerprint of the contacts key.
        Returns:
        PubkeyElement containing the requested public key.
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted.A
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an XMPP protocol error.
        org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException - in case the targeted entity is not a PubSub node.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - in case the fetched node is not a LeafNode.
        org.jivesoftware.smack.SmackException.NotConnectedException - in case we are not connected.
        org.jivesoftware.smack.SmackException.NoResponseException - if the server doesn't respond.
        See Also:
        XEP-0373 §4.3
      • depositSecretKey

        public static void depositSecretKey​(org.jivesoftware.smack.XMPPConnection connection,
                                            SecretkeyElement element)
                                     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.FeatureNotSupportedException
        Publishes a SecretkeyElement to the secret key node. The node will be configured to use the whitelist access model to prevent access from subscribers.
        Parameters:
        connection - XMPPConnection of the user
        element - a SecretkeyElement containing the encrypted secret key of the user
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted.
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if something is wrong with the PubSub node
        org.jivesoftware.smack.XMPPException.XMPPErrorException - in case of an protocol related error
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected
        org.jivesoftware.smack.SmackException.NoResponseException - /watch?v=0peBq89ZTrc
        org.jivesoftware.smack.SmackException.FeatureNotSupportedException - if the Server doesn't support the whitelist access model
        See Also:
        XEP-0373 §5. Synchronizing the Secret Key with a Private PEP Node
      • fetchSecretKey

        public static SecretkeyElement fetchSecretKey​(org.jivesoftware.smackx.pep.PepManager pepManager)
                                               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
        Fetch the latest SecretkeyElement from the private backup node.
        Parameters:
        pepManager - the PEP manager.
        Returns:
        the secret key node or null, if it doesn't exist.
        Throws:
        java.lang.InterruptedException - if the thread gets interrupted
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - if there is an issue with the PubSub node
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there is an XMPP protocol related issue
        org.jivesoftware.smack.SmackException.NotConnectedException - if we are not connected
        org.jivesoftware.smack.SmackException.NoResponseException - /watch?v=7U0FzQzJzyI
        See Also:
        XEP-0373 §5. Synchronizing the Secret Key with a Private PEP Node
      • deleteSecretKeyNode

        public static boolean deleteSecretKeyNode​(org.jivesoftware.smackx.pep.PepManager pepManager)
                                           throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
                                                  org.jivesoftware.smack.SmackException.NotConnectedException,
                                                  java.lang.InterruptedException,
                                                  org.jivesoftware.smack.SmackException.NoResponseException
        Delete the private backup node.
        Parameters:
        pepManager - the PEP manager.
        Returns:
        true if the node existed and was deleted, false if the node did not exist.
        Throws:
        org.jivesoftware.smack.XMPPException.XMPPErrorException - if there is an XMPP protocol related issue
        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 sends no response
      • getOpenLeafNode

        public static org.jivesoftware.smackx.pubsub.LeafNode getOpenLeafNode​(org.jivesoftware.smackx.pubsub.PubSubManager pubSubManager,
                                                                              java.lang.String nodeName)
                                                                       throws org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException
        Use reflection magic to get a LeafNode without doing a disco#info query. This method is useful for fetching nodes that are configured with the access model 'open', since some servers that announce support for that access model do not allow disco#info queries from contacts which are not subscribed to the node owner. Therefore this method fetches the node directly and puts it into the PubSubManagers node map. Note: Due to the alck of a disco#info query, it might happen, that the node doesn't exist on the server, even though we add it to the node map.
        Parameters:
        pubSubManager - pubsub manager
        nodeName - name of the node
        Returns:
        leafNode TODO javadoc me please
        Throws:
        org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException - in case we already have the node cached, but it is not a LeafNode.
        See Also:
        Ejabberd bug tracker about the issue, Topic on the standards mailing list