public final class OmemoManager extends Manager
Modifier and Type | Method and Description |
---|---|
void |
addOmemoMessageListener(OmemoMessageListener listener) |
void |
addOmemoMucMessageListener(OmemoMucMessageListener listener) |
void |
buildSessionsWith(BareJid contact)
Build OMEMO sessions with devices of contact.
|
boolean |
contactSupportsOmemo(BareJid contact)
Returns true, if the contact has any active devices published in a deviceList.
|
OmemoVAxolotlElement |
createKeyTransportElement(byte[] aesKey,
byte[] iv,
OmemoDevice... to)
Create a new KeyTransportElement.
|
ClearTextMessage |
decrypt(BareJid sender,
Message omemoMessage)
Decrypt an OMEMO message.
|
List<ClearTextMessage> |
decryptMamQueryResult(MamManager.MamQuery mamQuery)
Return a list of all OMEMO messages that were found in the MAM query result, that could be successfully decrypted.
|
void |
distrustOmemoIdentity(OmemoDevice device,
OmemoFingerprint fingerprint)
Distrust the fingerprint/OmemoDevice tuple.
|
Message |
encrypt(ArrayList<BareJid> recipients,
String message)
OMEMO encrypt a cleartext message for multiple recipients.
|
Message |
encrypt(BareJid to,
String message)
OMEMO encrypt a cleartext message for a single recipient.
|
Message |
encrypt(MultiUserChat muc,
String message)
Encrypt a message for all recipients in the MultiUserChat.
|
Message |
encryptForExistingSessions(CannotEstablishOmemoSessionException exception,
String message)
Encrypt a message for all users we could build a session with successfully in a previous attempt.
|
HashMap<OmemoDevice,OmemoFingerprint> |
getActiveFingerprints(BareJid contact)
Return all fingerprints of active devices of a contact.
|
int |
getDeviceId()
Return the deviceId of this OmemoManager.
|
OmemoFingerprint |
getFingerprint(OmemoDevice device) |
static OmemoManager |
getInstanceFor(XMPPConnection connection)
Get an instance of the OmemoManager for the given connection.
|
static OmemoManager |
getInstanceFor(XMPPConnection connection,
Integer deviceId)
Get an instance of the OmemoManager for the given connection and deviceId.
|
OmemoFingerprint |
getOurFingerprint()
Return the fingerprint of our identity key.
|
OmemoDevice |
getOwnDevice()
Return the OmemoDevice of the user.
|
BareJid |
getOwnJid()
Return the BareJid of the user.
|
void |
initialize()
Initializes the OmemoManager.
|
boolean |
isDecidedOmemoIdentity(OmemoDevice device,
OmemoFingerprint fingerprint)
Returns true, if the fingerprint/OmemoDevice tuple is decided by the user.
|
boolean |
isTrustedOmemoIdentity(OmemoDevice device,
OmemoFingerprint fingerprint)
Returns true, if the fingerprint/OmemoDevice tuple is trusted, otherwise false.
|
boolean |
multiUserChatSupportsOmemo(EntityBareJid multiUserChat)
Returns true, if the MUC with the EntityBareJid multiUserChat is non-anonymous and members only (prerequisite
for OMEMO encryption in MUC).
|
void |
purgeDevices()
Clear all other devices except this one from our device list and republish the list.
|
static int |
randomDeviceId() |
void |
regenerate()
Generate fresh identity keys and bundle and publish it to the server.
|
void |
removeOmemoMessageListener(OmemoMessageListener listener) |
void |
removeOmemoMucMessageListener(OmemoMucMessageListener listener) |
void |
requestDeviceListUpdateFor(BareJid contact)
Request a deviceList update from contact contact.
|
void |
rotateSignedPreKey()
Rotate the signedPreKey published in our OmemoBundle.
|
void |
sendRatchetUpdateMessage(OmemoDevice recipient)
Send a ratchet update message.
|
static boolean |
serverSupportsOmemo(XMPPConnection connection,
DomainBareJid server)
Returns true, if the Server supports PEP.
|
void |
shutdown()
Remove all active stanza listeners of this manager from the connection.
|
static boolean |
stanzaContainsOmemoElement(Stanza stanza)
Return true, if the given Stanza contains an OMEMO element 'encrypted'.
|
void |
trustOmemoIdentity(OmemoDevice device,
OmemoFingerprint fingerprint)
Trust that a fingerprint belongs to an OmemoDevice.
|
connection, getAuthenticatedConnectionOrThrow, schedule
public static OmemoManager getInstanceFor(XMPPConnection connection, Integer deviceId)
connection
- ConnectiondeviceId
- deviceId of the Manager. If the deviceId is null, a random id will be generated.public static OmemoManager getInstanceFor(XMPPConnection connection)
connection
- connectionpublic void initialize() throws CorruptedOmemoKeyException, InterruptedException, SmackException.NoResponseException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NotLoggedInException, PubSubException.NotALeafNodeException
CorruptedOmemoKeyException
InterruptedException
SmackException.NoResponseException
SmackException.NotConnectedException
XMPPException.XMPPErrorException
SmackException.NotLoggedInException
PubSubException.NotALeafNodeException
public Message encrypt(BareJid to, String message) throws CryptoFailedException, UndecidedOmemoIdentityException, NoSuchAlgorithmException, InterruptedException, CannotEstablishOmemoSessionException, SmackException.NotConnectedException, SmackException.NoResponseException
to
- recipients barejidmessage
- text to encryptCryptoFailedException
- when something crypto related failsUndecidedOmemoIdentityException
- When there are undecided devicesNoSuchAlgorithmException
InterruptedException
CannotEstablishOmemoSessionException
- when we could not create session withs all of the recipients devices.SmackException.NotConnectedException
SmackException.NoResponseException
public Message encrypt(ArrayList<BareJid> recipients, String message) throws CryptoFailedException, UndecidedOmemoIdentityException, NoSuchAlgorithmException, InterruptedException, CannotEstablishOmemoSessionException, SmackException.NotConnectedException, SmackException.NoResponseException
recipients
- recipients barejidsmessage
- text to encryptCryptoFailedException
- When something crypto related failsUndecidedOmemoIdentityException
- When there are undecided devices.NoSuchAlgorithmException
InterruptedException
CannotEstablishOmemoSessionException
- When there is one recipient, for whom we failed to create a session
with every one of their devices.SmackException.NotConnectedException
SmackException.NoResponseException
public Message encrypt(MultiUserChat muc, String message) throws UndecidedOmemoIdentityException, NoSuchAlgorithmException, CryptoFailedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, NoOmemoSupportException, CannotEstablishOmemoSessionException
muc
- multiUserChatmessage
- message to sendUndecidedOmemoIdentityException
- when there are undecided devices.NoSuchAlgorithmException
CryptoFailedException
XMPPException.XMPPErrorException
SmackException.NotConnectedException
InterruptedException
SmackException.NoResponseException
NoOmemoSupportException
- When the muc doesn't support OMEMO.CannotEstablishOmemoSessionException
- when there is a user for whom we could not create a session
with any of their devices.public Message encryptForExistingSessions(CannotEstablishOmemoSessionException exception, String message) throws CryptoFailedException, UndecidedOmemoIdentityException
exception
- CannotEstablishSessionException from a previous encrypt(user(s), message) call.message
- message we want to send.CryptoFailedException
UndecidedOmemoIdentityException
- when there are undecided identities.public ClearTextMessage decrypt(BareJid sender, Message omemoMessage) throws InterruptedException, SmackException.NoResponseException, SmackException.NotConnectedException, CryptoFailedException, XMPPException.XMPPErrorException, CorruptedOmemoKeyException, NoRawSessionException
sender
- sender of the messageomemoMessage
- messageInterruptedException
- ExceptionSmackException.NoResponseException
- ExceptionSmackException.NotConnectedException
- ExceptionCryptoFailedException
- When decryption failsXMPPException.XMPPErrorException
- ExceptionCorruptedOmemoKeyException
- When the used keys are invalidNoRawSessionException
- When there is no double ratchet session found for this messagepublic List<ClearTextMessage> decryptMamQueryResult(MamManager.MamQuery mamQuery) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException
mamQuery
- The MAM queryInterruptedException
- ExceptionXMPPException.XMPPErrorException
- ExceptionSmackException.NotConnectedException
- ExceptionSmackException.NoResponseException
- Exceptionpublic void trustOmemoIdentity(OmemoDevice device, OmemoFingerprint fingerprint)
device
- devicefingerprint
- fingerprintpublic void distrustOmemoIdentity(OmemoDevice device, OmemoFingerprint fingerprint)
device
- devicefingerprint
- fingerprintpublic boolean isTrustedOmemoIdentity(OmemoDevice device, OmemoFingerprint fingerprint)
device
- devicefingerprint
- fingerprintpublic boolean isDecidedOmemoIdentity(OmemoDevice device, OmemoFingerprint fingerprint)
device
- devicefingerprint
- fingerprintpublic void purgeDevices() throws SmackException, InterruptedException, XMPPException.XMPPErrorException, CorruptedOmemoKeyException
InterruptedException
SmackException
XMPPException.XMPPErrorException
CorruptedOmemoKeyException
public void regenerate() throws SmackException, InterruptedException, XMPPException.XMPPErrorException, CorruptedOmemoKeyException
SmackException
InterruptedException
XMPPException.XMPPErrorException
CorruptedOmemoKeyException
public void sendRatchetUpdateMessage(OmemoDevice recipient) throws CorruptedOmemoKeyException, UndecidedOmemoIdentityException, CryptoFailedException, CannotEstablishOmemoSessionException
recipient
- recipientUndecidedOmemoIdentityException
- When the trust of session with the recipient is not decided yetCorruptedOmemoKeyException
- When the used identityKeys are corruptedCryptoFailedException
- When something fails with the cryptoCannotEstablishOmemoSessionException
- When we can't establish a session with the recipientpublic OmemoVAxolotlElement createKeyTransportElement(byte[] aesKey, byte[] iv, OmemoDevice... to) throws UndecidedOmemoIdentityException, CorruptedOmemoKeyException, CryptoFailedException, CannotEstablishOmemoSessionException
aesKey
- AES key to transportiv
- Initialization vectorto
- list of recipient devicesUndecidedOmemoIdentityException
- When the trust of session with the recipient is not decided yetCorruptedOmemoKeyException
- When the used identityKeys are corruptedCryptoFailedException
- When something fails with the cryptoCannotEstablishOmemoSessionException
- When we can't establish a session with the recipientpublic boolean contactSupportsOmemo(BareJid contact) throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
contact
- contactSmackException.NotConnectedException
InterruptedException
SmackException.NoResponseException
public boolean multiUserChatSupportsOmemo(EntityBareJid multiUserChat) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
multiUserChat
- EntityBareJid of the MUCXMPPException.XMPPErrorException
- ifSmackException.NotConnectedException
- somethingInterruptedException
- goesSmackException.NoResponseException
- wrongpublic static boolean serverSupportsOmemo(XMPPConnection connection, DomainBareJid server) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
connection
- XMPPConnectionserver
- domainBareJid of the server to testXMPPException.XMPPErrorException
SmackException.NotConnectedException
InterruptedException
SmackException.NoResponseException
public OmemoFingerprint getOurFingerprint()
public OmemoFingerprint getFingerprint(OmemoDevice device) throws CannotEstablishOmemoSessionException
public HashMap<OmemoDevice,OmemoFingerprint> getActiveFingerprints(BareJid contact)
contact
- contactpublic void addOmemoMessageListener(OmemoMessageListener listener)
public void removeOmemoMessageListener(OmemoMessageListener listener)
public void addOmemoMucMessageListener(OmemoMucMessageListener listener)
public void removeOmemoMucMessageListener(OmemoMucMessageListener listener)
public void buildSessionsWith(BareJid contact) throws InterruptedException, CannotEstablishOmemoSessionException, SmackException.NotConnectedException, SmackException.NoResponseException
contact
- contact we want to build session with.InterruptedException
CannotEstablishOmemoSessionException
SmackException.NotConnectedException
SmackException.NoResponseException
public void requestDeviceListUpdateFor(BareJid contact) throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
contact
- contact we want to obtain the deviceList from.SmackException.NotConnectedException
InterruptedException
SmackException.NoResponseException
public void rotateSignedPreKey() throws CorruptedOmemoKeyException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, PubSubException.NotALeafNodeException
CorruptedOmemoKeyException
- When the IdentityKeyPair is damaged.InterruptedException
- XMPP errorXMPPException.XMPPErrorException
- XMPP errorSmackException.NotConnectedException
- XMPP errorSmackException.NoResponseException
- XMPP errorPubSubException.NotALeafNodeException
- if the bundle node on the server is a CollectionNodepublic static boolean stanzaContainsOmemoElement(Stanza stanza)
stanza
- stanzapublic static int randomDeviceId()
public int getDeviceId()
public OmemoDevice getOwnDevice()
public void shutdown()