Package org.jivesoftware.smackx.ox_im
Class OXInstantMessagingManager
- java.lang.Object
-
- org.jivesoftware.smack.Manager
-
- org.jivesoftware.smackx.ox_im.OXInstantMessagingManager
-
public final class OXInstantMessagingManager extends org.jivesoftware.smack.Manager
Entry point of Smacks API for XEP-0374: OpenPGP for XMPP: Instant Messaging.Setup
In order to set up OX Instant Messaging, please first follow the setup routines of theOpenPgpManager
, then do the following steps:Acquire an
OXInstantMessagingManager
instance.OXInstantMessagingManager instantManager = OXInstantMessagingManager.getInstanceFor(connection);
Listen for OX messages
In order to listen for incoming OX:IM messages, you have to register a listener.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); ... } });
Finally, announce support for OX:IM
In order to let your contacts know, that you support message encrypting using the OpenPGP for XMPP: Instant Messaging profile, you have to announce support for OX:IM.instantManager.announceSupportForOxInstantMessaging();
Sending messages
In order to send an OX:IM message, just doinstantManager.sendOxMessage(openPgpManager.getOpenPgpContact(contactsJid), "Hello World");
OpenPgpContact.trust(OpenPgpV4Fingerprint)
. Same goes for your own keys! In order to determine, whether there are undecided keys, callOpenPgpContact.hasUndecidedKeys()
. The trust state of a single key can be determined usingOpenPgpContact.getTrust(OpenPgpV4Fingerprint)
. Note: This implementation does not yet have support for sending/receiving messages to/from MUCs.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NAMESPACE_0
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.boolean
addOxMessageListener(OxMessageListener listener)
Add anOxMessageListener
.void
announceSupportForOxInstantMessaging()
Add the OX:IM namespace as a feature to our disco features.boolean
contactSupportsOxInstantMessaging(OpenPgpContact contact)
Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.boolean
contactSupportsOxInstantMessaging(org.jxmpp.jid.BareJid jid)
Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.OpenPgpMessage
decryptAndVerify(OpenPgpElement element, OpenPgpContact sender)
Manually decrypt and verify anOpenPgpElement
.static OXInstantMessagingManager
getInstanceFor(org.jivesoftware.smack.XMPPConnection connection)
Return an instance of theOXInstantMessagingManager
that belongs to the givenconnection
.boolean
removeOxMessageListener(OxMessageListener listener)
Remove anOxMessageListener
.org.pgpainless.decryption_verification.OpenPgpMetadata
sendOxMessage(OpenPgpContact contact, java.lang.CharSequence body)
Send an OX message to aOpenPgpContact
.OpenPgpElementAndMetadata
signAndEncrypt(java.util.Set<OpenPgpContact> contacts, java.util.List<org.jivesoftware.smack.packet.ExtensionElement> payload)
-
-
-
Field Detail
-
NAMESPACE_0
public static final java.lang.String NAMESPACE_0
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstanceFor
public static OXInstantMessagingManager getInstanceFor(org.jivesoftware.smack.XMPPConnection connection)
Return an instance of theOXInstantMessagingManager
that belongs to the givenconnection
.- Parameters:
connection
- XMPP connection- Returns:
- manager instance
-
announceSupportForOxInstantMessaging
public void announceSupportForOxInstantMessaging()
Add the OX:IM namespace as a feature to our disco features.
-
contactSupportsOxInstantMessaging
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
Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.- Parameters:
jid
-BareJid
of the contact in question.- Returns:
- true if contact announces support, otherwise false.
- Throws:
org.jivesoftware.smack.XMPPException.XMPPErrorException
- in case of an XMPP protocol errororg.jivesoftware.smack.SmackException.NotConnectedException
- if we are not connectedjava.lang.InterruptedException
- if the thread gets interruptedorg.jivesoftware.smack.SmackException.NoResponseException
- if the server doesn't respond
-
contactSupportsOxInstantMessaging
public boolean contactSupportsOxInstantMessaging(OpenPgpContact contact) throws org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, java.lang.InterruptedException, org.jivesoftware.smack.SmackException.NoResponseException
Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.- Parameters:
contact
-OpenPgpContact
in question.- Returns:
- true if contact announces support, otherwise false.
- Throws:
org.jivesoftware.smack.XMPPException.XMPPErrorException
- in case of an XMPP protocol errororg.jivesoftware.smack.SmackException.NotConnectedException
- if we are not connectedjava.lang.InterruptedException
- if the thread is interruptedorg.jivesoftware.smack.SmackException.NoResponseException
- if the server doesn't respond
-
addOxMessageListener
public boolean addOxMessageListener(OxMessageListener listener)
Add anOxMessageListener
. The listener gets notified about incomingOpenPgpMessage
s which contained an OX-IM message.- Parameters:
listener
- listener- Returns:
- true if the listener gets added, otherwise false.
-
removeOxMessageListener
public boolean removeOxMessageListener(OxMessageListener listener)
Remove anOxMessageListener
. The listener will no longer be notified about OX-IM messages.- Parameters:
listener
- listener- Returns:
- true, if the listener gets removed, otherwise false
-
sendOxMessage
public 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
Send an OX message to aOpenPgpContact
. 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.- Parameters:
contact
- contact capable of OpenPGP for XMPP: Instant Messaging.body
- message body.- Returns:
OpenPgpMetadata
about the messages encryption + signatures.- Throws:
java.lang.InterruptedException
- if the thread is interruptedjava.io.IOException
- IO is dangerousorg.jivesoftware.smack.SmackException.NotConnectedException
- if we are not connectedorg.jivesoftware.smack.SmackException.NotLoggedInException
- if we are not logged inorg.bouncycastle.openpgp.PGPException
- PGP is brittle
-
addOxMessage
public 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
Add an OX-IM message element to a message.- Parameters:
messageBuilder
- a message builder.contact
- recipient of the messagepayload
- payload which will be encrypted and signed- Returns:
OpenPgpMetadata
about the messages encryption + metadata.- Throws:
org.jivesoftware.smack.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)
-
addOxMessage
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
Add an OX-IM message element to a message.- Parameters:
messageBuilder
- messagerecipients
- recipients of the messagepayload
- payload which will be encrypted and signed- Returns:
- metadata about the messages encryption + signatures.
- Throws:
org.jivesoftware.smack.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)
-
signAndEncrypt
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
- Parameters:
contacts
- recipients of the messagepayload
- payload which will be encrypted and signed- Returns:
- encrypted and signed
OpenPgpElement
, along withOpenPgpMetadata
about the encryption + signatures. - Throws:
org.jivesoftware.smack.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 wrong
-
decryptAndVerify
public OpenPgpMessage decryptAndVerify(OpenPgpElement element, OpenPgpContact sender) throws org.jivesoftware.smack.SmackException.NotLoggedInException, org.bouncycastle.openpgp.PGPException, java.io.IOException, org.jivesoftware.smack.xml.XmlPullParserException
Manually decrypt and verify anOpenPgpElement
.- Parameters:
element
- encrypted, signedOpenPgpElement
.sender
- sender of the message.- Returns:
- decrypted, verified message
- Throws:
org.jivesoftware.smack.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 theOpenPgpElement
is not a validOpenPgpContentElement
or broken XML.java.lang.IllegalArgumentException
- if the elements content is not aSigncryptElement
. This happens, if the element likely is not an OX message.
-
-