public final class OXInstantMessagingManager extends Manager
OpenPgpManager
, then
do the following steps:
OXInstantMessagingManager
instance.
OXInstantMessagingManager instantManager = OXInstantMessagingManager.getInstanceFor(connection);
instantManager.addOxMessageListener(
new OxMessageListener() {
void newIncomingOxMessage(OpenPgpContact contact,
Message originalMessage,
SigncryptElement decryptedPayload) {
Message.Body body = decryptedPayload.<Message.Body>getExtension(Message.Body.ELEMENT, Message.Body.NAMESPACE);
...
}
});
instantManager.announceSupportForOxInstantMessaging();
instantManager.sendOxMessage(openPgpManager.getOpenPgpContact(contactsJid), "Hello World");
Note, that you have to decide, whether to trust the contacts keys prior to sending a message, otherwise undecided
keys are not included in the encryption process. You can trust keys by calling
OpenPgpContact.trust(OpenPgpV4Fingerprint)
. Same goes for your own keys! In order to determine, whether
there are undecided keys, call OpenPgpContact.hasUndecidedKeys()
. The trust state of a single key can be
determined using OpenPgpContact.getTrust(OpenPgpV4Fingerprint)
.
Note: This implementation does not yet have support for sending/receiving messages to/from MUCs.Modifier and Type | Field and Description |
---|---|
static String |
NAMESPACE_0 |
Modifier and Type | Method and Description |
---|---|
org.pgpainless.decryption_verification.OpenPgpMetadata |
addOxMessage(Message message,
OpenPgpContact contact,
List<ExtensionElement> payload)
Add an OX-IM message element to a message.
|
org.pgpainless.decryption_verification.OpenPgpMetadata |
addOxMessage(Message message,
Set<OpenPgpContact> contacts,
List<ExtensionElement> payload)
Add an OX-IM message element to a message.
|
boolean |
addOxMessageListener(OxMessageListener listener)
Add an
OxMessageListener . |
void |
announceSupportForOxInstantMessaging()
Add the OX:IM namespace as a feature to our disco features.
|
boolean |
contactSupportsOxInstantMessaging(BareJid jid)
Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.
|
boolean |
contactSupportsOxInstantMessaging(OpenPgpContact contact)
Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.
|
OpenPgpMessage |
decryptAndVerify(OpenPgpElement element,
OpenPgpContact sender)
Manually decrypt and verify an
OpenPgpElement . |
static OXInstantMessagingManager |
getInstanceFor(XMPPConnection connection)
Return an instance of the
OXInstantMessagingManager that belongs to the given connection . |
boolean |
removeOxMessageListener(OxMessageListener listener)
Remove an
OxMessageListener . |
org.pgpainless.decryption_verification.OpenPgpMetadata |
sendOxMessage(OpenPgpContact contact,
CharSequence body)
Send an OX message to a
OpenPgpContact . |
OpenPgpElementAndMetadata |
signAndEncrypt(Set<OpenPgpContact> contacts,
List<ExtensionElement> payload)
|
connection, getAuthenticatedConnectionOrThrow, schedule
public static final String NAMESPACE_0
public static OXInstantMessagingManager getInstanceFor(XMPPConnection connection)
OXInstantMessagingManager
that belongs to the given connection
.connection
- XMPP connectionpublic void announceSupportForOxInstantMessaging()
public boolean contactSupportsOxInstantMessaging(BareJid jid) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
jid
- BareJid
of the contact in question.XMPPException.XMPPErrorException
- in case of an XMPP protocol errorSmackException.NotConnectedException
- if we are not connectedInterruptedException
- if the thread gets interruptedSmackException.NoResponseException
- if the server doesn't respondpublic boolean contactSupportsOxInstantMessaging(OpenPgpContact contact) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
contact
- OpenPgpContact
in question.XMPPException.XMPPErrorException
- in case of an XMPP protocol errorSmackException.NotConnectedException
- if we are not connectedInterruptedException
- if the thread is interruptedSmackException.NoResponseException
- if the server doesn't respondpublic boolean addOxMessageListener(OxMessageListener listener)
OxMessageListener
. The listener gets notified about incoming OpenPgpMessage
s which
contained an OX-IM message.listener
- listenerpublic boolean removeOxMessageListener(OxMessageListener listener)
OxMessageListener
. The listener will no longer be notified about OX-IM messages.listener
- listenerpublic org.pgpainless.decryption_verification.OpenPgpMetadata sendOxMessage(OpenPgpContact contact, CharSequence body) throws InterruptedException, IOException, SmackException.NotConnectedException, SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException
OpenPgpContact
. The message will be encrypted to all active keys of the contact,
as well as all of our active keys. The message is also signed with our key.contact
- contact capable of OpenPGP for XMPP: Instant Messaging.body
- message body.OpenPgpMetadata
about the messages encryption + signatures.InterruptedException
- if the thread is interruptedIOException
- IO is dangerousSmackException.NotConnectedException
- if we are not connectedSmackException.NotLoggedInException
- if we are not logged inorg.bouncycastle.openpgp.PGPException
- PGP is brittlepublic org.pgpainless.decryption_verification.OpenPgpMetadata addOxMessage(Message message, OpenPgpContact contact, List<ExtensionElement> payload) throws SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException, IOException
message
- messagecontact
- recipient of the messagepayload
- payload which will be encrypted and signedOpenPgpMetadata
about the messages encryption + metadata.SmackException.NotLoggedInException
- in case we are not logged inorg.bouncycastle.openpgp.PGPException
- in case something goes wrong during encryptionIOException
- IO is dangerous (we need to read keys)public org.pgpainless.decryption_verification.OpenPgpMetadata addOxMessage(Message message, Set<OpenPgpContact> contacts, List<ExtensionElement> payload) throws SmackException.NotLoggedInException, IOException, org.bouncycastle.openpgp.PGPException
message
- messagecontacts
- recipients of the messagepayload
- payload which will be encrypted and signedSmackException.NotLoggedInException
- in case we are not logged inorg.bouncycastle.openpgp.PGPException
- in case something goes wrong during encryptionIOException
- IO is dangerous (we need to read keys)public OpenPgpElementAndMetadata signAndEncrypt(Set<OpenPgpContact> contacts, List<ExtensionElement> payload) throws SmackException.NotLoggedInException, IOException, org.bouncycastle.openpgp.PGPException
contacts
- recipients of the messagepayload
- payload which will be encrypted and signedOpenPgpElement
, along with OpenPgpMetadata
about the
encryption + signatures.SmackException.NotLoggedInException
- in case we are not logged inIOException
- IO is dangerous (we need to read keys)org.bouncycastle.openpgp.PGPException
- in case encryption goes wrongpublic OpenPgpMessage decryptAndVerify(OpenPgpElement element, OpenPgpContact sender) throws SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException, IOException, org.xmlpull.v1.XmlPullParserException
OpenPgpElement
.element
- encrypted, signed OpenPgpElement
.sender
- sender of the message.SmackException.NotLoggedInException
- In case we are not logged in (we need our jid to access our keys)org.bouncycastle.openpgp.PGPException
- in case of an PGP errorIOException
- in case of an IO error (reading keys, streams etc)org.xmlpull.v1.XmlPullParserException
- in case that the content of the OpenPgpElement
is not a valid
OpenPgpContentElement
or broken XML.IllegalArgumentException
- if the elements content is not a SigncryptElement
. This happens, if the
element likely is not an OX message.