public final class OXInstantMessagingManager
extends org.jivesoftware.smack.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 java.lang.String |
NAMESPACE_0 |
| Modifier and Type | Method and Description |
|---|---|
org.pgpainless.decryption_verification.OpenPgpMetadata |
addOxMessage(org.jivesoftware.smack.packet.MessageBuilder messageBuilder,
OpenPgpContact contact,
java.util.List<org.jivesoftware.smack.packet.ExtensionElement> payload)
Add an OX-IM message element to a message.
|
org.pgpainless.decryption_verification.OpenPgpMetadata |
addOxMessage(org.jivesoftware.smack.packet.MessageBuilder messageBuilder,
java.util.Set<OpenPgpContact> recipients,
java.util.List<org.jivesoftware.smack.packet.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(org.jxmpp.jid.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(org.jivesoftware.smack.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,
java.lang.CharSequence body)
Send an OX message to a
OpenPgpContact. |
OpenPgpElementAndMetadata |
signAndEncrypt(java.util.Set<OpenPgpContact> contacts,
java.util.List<org.jivesoftware.smack.packet.ExtensionElement> payload)
|
public static final java.lang.String NAMESPACE_0
public static OXInstantMessagingManager getInstanceFor(org.jivesoftware.smack.XMPPConnection connection)
OXInstantMessagingManager that belongs to the given connection.connection - XMPP connectionpublic void announceSupportForOxInstantMessaging()
public boolean contactSupportsOxInstantMessaging(org.jxmpp.jid.BareJid jid)
throws org.jivesoftware.smack.XMPPException.XMPPErrorException,
org.jivesoftware.smack.SmackException.NotConnectedException,
java.lang.InterruptedException,
org.jivesoftware.smack.SmackException.NoResponseException
jid - BareJid of the contact in question.XMPPException.XMPPErrorException - in case of an XMPP protocol errorSmackException.NotConnectedException - if we are not connectedjava.lang.InterruptedException - if the thread gets interruptedSmackException.NoResponseException - if the server doesn't respondpublic boolean contactSupportsOxInstantMessaging(OpenPgpContact contact) throws org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, java.lang.InterruptedException, org.jivesoftware.smack.SmackException.NoResponseException
contact - OpenPgpContact in question.XMPPException.XMPPErrorException - in case of an XMPP protocol errorSmackException.NotConnectedException - if we are not connectedjava.lang.InterruptedException - if the thread is interruptedSmackException.NoResponseException - if the server doesn't respondpublic boolean addOxMessageListener(OxMessageListener listener)
OxMessageListener. The listener gets notified about incoming OpenPgpMessages 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, java.lang.CharSequence body) throws java.lang.InterruptedException, java.io.IOException, org.jivesoftware.smack.SmackException.NotConnectedException, org.jivesoftware.smack.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.java.lang.InterruptedException - if the thread is interruptedjava.io.IOException - 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(org.jivesoftware.smack.packet.MessageBuilder messageBuilder,
OpenPgpContact contact,
java.util.List<org.jivesoftware.smack.packet.ExtensionElement> payload)
throws org.jivesoftware.smack.SmackException.NotLoggedInException,
org.bouncycastle.openpgp.PGPException,
java.io.IOException
messageBuilder - a message builder.contact - 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 encryptionjava.io.IOException - IO is dangerous (we need to read keys)public org.pgpainless.decryption_verification.OpenPgpMetadata addOxMessage(org.jivesoftware.smack.packet.MessageBuilder messageBuilder,
java.util.Set<OpenPgpContact> recipients,
java.util.List<org.jivesoftware.smack.packet.ExtensionElement> payload)
throws org.jivesoftware.smack.SmackException.NotLoggedInException,
java.io.IOException,
org.bouncycastle.openpgp.PGPException
messageBuilder - messagerecipients - 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 encryptionjava.io.IOException - IO is dangerous (we need to read keys)public OpenPgpElementAndMetadata signAndEncrypt(java.util.Set<OpenPgpContact> contacts, java.util.List<org.jivesoftware.smack.packet.ExtensionElement> payload) throws org.jivesoftware.smack.SmackException.NotLoggedInException, java.io.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 injava.io.IOException - IO is dangerous (we need to read keys)org.bouncycastle.openpgp.PGPException - in case encryption goes wrongpublic OpenPgpMessage decryptAndVerify(OpenPgpElement element, OpenPgpContact sender) throws org.jivesoftware.smack.SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException, java.io.IOException, org.jivesoftware.smack.xml.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 errorjava.io.IOException - in case of an IO error (reading keys, streams etc)org.jivesoftware.smack.xml.XmlPullParserException - in case that the content of the OpenPgpElement is not a valid
OpenPgpContentElement or broken XML.java.lang.IllegalArgumentException - if the elements content is not a SigncryptElement. This happens, if the
element likely is not an OX message.