public final class OpenPgpManager
extends org.jivesoftware.smack.Manager
OpenPgpManager for your XMPPConnection using
getInstanceFor(XMPPConnection).
OpenPgpManager openPgpManager = OpenPgpManager.getInstanceFor(connection);
You also need an OpenPgpProvider, as well as an OpenPgpStore.
The provider must be registered using setOpenPgpProvider(OpenPgpProvider).
OpenPgpStore store = new FileBasedOpenPgpStore(storePath);
OpenPgpProvider provider = new PainlessOpenPgpProvider(connection, store);
openPgpManager.setOpenPgpProvider(provider);
It is also advised to register a custom SecretKeyRingProtector using
OpenPgpStore.setKeyRingProtector(SecretKeyRingProtector) in order to be able to handle password protected
secret keys.OpenPgpStore by doing
hasSecretKeysAvailable().announceSupportAndPublish().generateAndImportKeyPair(BareJid),
or try to restore a secret key backup from your private PubSub node by doing
restoreSecretKeyServerBackup(AskForBackupCodeCallback).announceSupportAndPublish() afterwards.
OpenPgpContacts in the context of OpenPGP for XMPP. You can get those by using
getOpenPgpContact(EntityBareJid). The main function of OpenPgpContacts is to bundle information
about the OpenPGP capabilities of a contact in one spot. The pendant to the OpenPgpContact is the
OpenPgpSelf, which encapsulates your own OpenPGP identity. Both classes can be used to acquire information
about the OpenPGP keys of a user.
OpenPgpElement, which contains an OpenPGP encrypted content element.
The content can be either a SignElement, CryptElement or SigncryptElement, depending on the use-case.
Those content elements contain the actual payload. If an OpenPgpElement is decrypted, it will be returned in
form of an OpenPgpMessage, which represents the decrypted message + metadata.| Modifier and Type | Method and Description |
|---|---|
void |
announceSupportAndPublish()
Generate a fresh OpenPGP key pair, given we don't have one already.
|
void |
backupSecretKeyToServer(DisplayBackupCodeCallback displayCodeCallback,
SecretKeyBackupSelectionCallback selectKeyCallback)
Upload the encrypted secret key to a private PEP node.
|
OpenPgpMessage |
decryptOpenPgpElement(OpenPgpElement element,
OpenPgpContact sender)
Decrypt and or verify an
OpenPgpElement and return the decrypted OpenPgpMessage. |
void |
deleteSecretKeyServerBackup()
Delete the private
LeafNode containing our secret key backup. |
org.pgpainless.key.OpenPgpV4Fingerprint |
generateAndImportKeyPair(org.jxmpp.jid.BareJid ourJid)
Generate a fresh OpenPGP key pair and import it.
|
static OpenPgpManager |
getInstanceFor(org.jivesoftware.smack.XMPPConnection connection)
Get the instance of the
OpenPgpManager which belongs to the connection. |
org.jxmpp.jid.BareJid |
getJidOrThrow()
Return our own
BareJid. |
OpenPgpContact |
getOpenPgpContact(org.jxmpp.jid.EntityBareJid jid)
Return an OpenPGP capable contact.
|
OpenPgpProvider |
getOpenPgpProvider() |
OpenPgpSelf |
getOpenPgpSelf()
Get our OpenPGP self.
|
org.pgpainless.key.OpenPgpV4Fingerprint |
getOurFingerprint()
Return the upper-case hex encoded OpenPGP v4 fingerprint of our key pair.
|
boolean |
hasSecretKeysAvailable()
Return true, if we have a secret key available, otherwise false.
|
void |
registerSigncryptReceivedListener(SigncryptElementReceivedListener listener)
Register a
SigncryptElementReceivedListener on the OpenPgpManager. |
org.pgpainless.key.OpenPgpV4Fingerprint |
restoreSecretKeyServerBackup(AskForBackupCodeCallback codeCallback)
Fetch a secret key backup from the server and try to restore a selected secret key from it.
|
static boolean |
serverSupportsSecretKeyBackups(org.jivesoftware.smack.XMPPConnection connection)
Determine, if we can sync secret keys using private PEP nodes as described in the XEP.
|
void |
setOpenPgpProvider(OpenPgpProvider provider)
Set the
OpenPgpProvider which will be used to process incoming OpenPGP elements,
as well as to execute cryptographic operations. |
void |
stopMetadataListener()
Remove the metadata listener.
|
public static OpenPgpManager getInstanceFor(org.jivesoftware.smack.XMPPConnection connection)
OpenPgpManager which belongs to the connection.connection - xmpp connection.public org.jxmpp.jid.BareJid getJidOrThrow()
throws org.jivesoftware.smack.SmackException.NotLoggedInException
BareJid.SmackException.NotLoggedInException - in case our connection is not logged in, which means our BareJid is unknown.public void setOpenPgpProvider(OpenPgpProvider provider)
OpenPgpProvider which will be used to process incoming OpenPGP elements,
as well as to execute cryptographic operations.provider - OpenPgpProvider.public OpenPgpProvider getOpenPgpProvider()
public OpenPgpSelf getOpenPgpSelf() throws org.jivesoftware.smack.SmackException.NotLoggedInException
SmackException.NotLoggedInException - if we are not logged inpublic 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
PepListener which listens for updates to Public Key Metadata Nodes.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.PubSubException.NotALeafNodeException - if one of the PubSub nodes is not a LeafNode.XMPPException.XMPPErrorException - in case of an XMPP protocol error.SmackException.NotConnectedException - if we are not connected.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.SmackException.NotLoggedInException - if we are not logged in.org.bouncycastle.openpgp.PGPException - if something goes wrong during key loading/generatingpublic 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
ourJid - our BareJid.OpenPgpV4Fingerprint of the generated key.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.public org.pgpainless.key.OpenPgpV4Fingerprint getOurFingerprint()
throws org.jivesoftware.smack.SmackException.NotLoggedInException,
java.io.IOException,
org.bouncycastle.openpgp.PGPException
SmackException.NotLoggedInException - in case we are not logged in.java.io.IOException - IO is dangerous.org.bouncycastle.openpgp.PGPException - PGP is brittle.public OpenPgpContact getOpenPgpContact(org.jxmpp.jid.EntityBareJid jid)
jid - BareJid of the contact.OpenPgpContact.public boolean hasSecretKeysAvailable()
throws org.jivesoftware.smack.SmackException.NotLoggedInException,
org.bouncycastle.openpgp.PGPException,
java.io.IOException
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.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
connection - XMPP connectionXMPPException.XMPPErrorException - in case of an XMPP protocol error.SmackException.NotConnectedException - if we are not connected.java.lang.InterruptedException - if the thread is interrupted.SmackException.NoResponseException - if the server doesn't respond.public void stopMetadataListener()
public void backupSecretKeyToServer(DisplayBackupCodeCallback displayCodeCallback, 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
displayCodeCallback - callback, which will receive the backup password used to encrypt the secret key.selectKeyCallback - callback, which will receive the users choice of which keys will be backed up.java.lang.InterruptedException - if the thread is interrupted.PubSubException.NotALeafNodeException - if the private node is not a LeafNode.XMPPException.XMPPErrorException - in case of an XMPP protocol error.SmackException.NotConnectedException - if we are not connected.SmackException.NoResponseException - if the server doesn't respond.SmackException.NotLoggedInException - if we are not logged in.java.io.IOException - IO is dangerous.SmackException.FeatureNotSupportedException - if the server doesn't support the PubSub whitelist access model.org.bouncycastle.openpgp.PGPException - PGP is brittleMissingOpenPgpKeyException - in case we have no OpenPGP key pair to back up.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
LeafNode containing our secret key backup.XMPPException.XMPPErrorException - in case of an XMPP protocol error.SmackException.NotConnectedException - if we are not connected.java.lang.InterruptedException - if the thread gets interrupted.SmackException.NoResponseException - if the server doesn't respond.SmackException.NotLoggedInException - if we are not logged in.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
codeCallback - callback for prompting the user to provide the secret backup code.java.lang.InterruptedException - if the thread gets interrupted.PubSubException.NotALeafNodeException - if the private node is not a LeafNode.XMPPException.XMPPErrorException - in case of an XMPP protocol error.SmackException.NotConnectedException - if we are not connected.SmackException.NoResponseException - if the server doesn't respond.InvalidBackupCodeException - if the user-provided backup code is invalid.SmackException.NotLoggedInException - if we are not logged injava.io.IOException - IO is dangerousMissingUserIdOnKeyException - if the key that is to be imported is missing a user-id with our jidNoBackupFoundException - if no secret key backup has been foundorg.bouncycastle.openpgp.PGPException - in case the restored secret key is damaged.public OpenPgpMessage decryptOpenPgpElement(OpenPgpElement element, OpenPgpContact sender) throws org.jivesoftware.smack.SmackException.NotLoggedInException, java.io.IOException, org.bouncycastle.openpgp.PGPException
OpenPgpElement and return the decrypted OpenPgpMessage.element - OpenPgpElement containing the message.sender - OpenPgpContact who sent the message.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 errorpublic void registerSigncryptReceivedListener(SigncryptElementReceivedListener listener)
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.listener - listener that gets registered