public final class OpenPgpManager extends 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.
OpenPgpContact
s in the context of OpenPGP for XMPP. You can get those by using
getOpenPgpContact(EntityBareJid)
. The main function of OpenPgpContact
s 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.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 contact) |
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(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(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.
|
connection, getAuthenticatedConnectionOrThrow, schedule
public static OpenPgpManager getInstanceFor(XMPPConnection connection)
OpenPgpManager
which belongs to the connection
.connection
- xmpp connection.public org.jxmpp.jid.BareJid getJidOrThrow() throws 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 SmackException.NotLoggedInException
SmackException.NotLoggedInException
- if we are not logged inpublic void announceSupportAndPublish() throws NoSuchAlgorithmException, NoSuchProviderException, InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException, InvalidAlgorithmParameterException, SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException
PEPListener
which listens for updates to Public Key Metadata Nodes.NoSuchAlgorithmException
- if we are missing an algorithm to generate a fresh key pair.NoSuchProviderException
- if we are missing a suitable Provider
.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.IOException
- IO is dangerous.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 NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, org.bouncycastle.openpgp.PGPException, IOException
ourJid
- our BareJid
.OpenPgpV4Fingerprint
of the generated key.NoSuchAlgorithmException
- if the JVM doesn't support one of the used algorithms.InvalidAlgorithmParameterException
- if the used algorithm parameters are invalid.NoSuchProviderException
- if we are missing a cryptographic provider.org.bouncycastle.openpgp.PGPException
- PGP is brittle.IOException
- IO is dangerous.public org.pgpainless.key.OpenPgpV4Fingerprint getOurFingerprint() throws SmackException.NotLoggedInException, IOException, org.bouncycastle.openpgp.PGPException
SmackException.NotLoggedInException
- in case we are not logged in.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 SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException, 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.IOException
- IO is dangerous.public static boolean serverSupportsSecretKeyBackups(XMPPConnection connection) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
connection
- XMPP connectionXMPPException.XMPPErrorException
- in case of an XMPP protocol error.SmackException.NotConnectedException
- if we are not connected.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 InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, SmackException.NotLoggedInException, IOException, 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.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.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 XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, SmackException.NotLoggedInException
LeafNode
containing our secret key backup.XMPPException.XMPPErrorException
- in case of an XMPP protocol error.SmackException.NotConnectedException
- if we are not connected.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 InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, InvalidBackupCodeException, SmackException.NotLoggedInException, IOException, MissingUserIdOnKeyException, NoBackupFoundException, org.bouncycastle.openpgp.PGPException
codeCallback
- callback for prompting the user to provide the secret backup code.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 inIOException
- 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 contact) throws SmackException.NotLoggedInException, IOException, org.bouncycastle.openpgp.PGPException
SmackException.NotLoggedInException
IOException
org.bouncycastle.openpgp.PGPException
public 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 SigncryptElement
s.
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