Search in sources :

Example 1 with OmemoFingerprint

use of org.jivesoftware.smackx.omemo.trust.OmemoFingerprint in project Smack by igniterealtime.

the class OmemoManagerSetupHelper method trustAllIdentities.

public static void trustAllIdentities(OmemoManager alice, OmemoManager bob) throws InterruptedException, SmackException.NotConnectedException, SmackException.NotLoggedInException, SmackException.NoResponseException, CannotEstablishOmemoSessionException, CorruptedOmemoKeyException, XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, IOException {
    Roster roster = Roster.getInstanceFor(alice.getConnection());
    if (alice.getOwnJid() != bob.getOwnJid() && (!roster.iAmSubscribedTo(bob.getOwnJid()) || !roster.isSubscribedToMyPresence(bob.getOwnJid()))) {
        throw new IllegalStateException("Before trusting identities of a user, we must be subscribed to one another.");
    }
    alice.requestDeviceListUpdateFor(bob.getOwnJid());
    HashMap<OmemoDevice, OmemoFingerprint> fingerprints = alice.getActiveFingerprints(bob.getOwnJid());
    for (OmemoDevice device : fingerprints.keySet()) {
        OmemoFingerprint fingerprint = fingerprints.get(device);
        alice.trustOmemoIdentity(device, fingerprint);
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) OmemoDevice(org.jivesoftware.smackx.omemo.internal.OmemoDevice) OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)

Example 2 with OmemoFingerprint

use of org.jivesoftware.smackx.omemo.trust.OmemoFingerprint in project Smack by igniterealtime.

the class OmemoService method decryptMessage.

/**
 * Decrypt an OMEMO message.
 *
 * @param managerGuard authenticated OmemoManager.
 * @param senderJid BareJid of the sender.
 * @param omemoElement omemoElement.
 * @return decrypted OmemoMessage object.
 *
 * @throws CorruptedOmemoKeyException if the identityKey of the sender is damaged.
 * @throws CryptoFailedException if decryption fails.
 * @throws NoRawSessionException if we have no session with the device and it sent a normal (non-preKey) message.
 * @throws IOException if an I/O error occurred.
 */
OmemoMessage.Received decryptMessage(OmemoManager.LoggedInOmemoManager managerGuard, BareJid senderJid, OmemoElement omemoElement) throws CorruptedOmemoKeyException, CryptoFailedException, NoRawSessionException, IOException {
    OmemoManager manager = managerGuard.get();
    int senderId = omemoElement.getHeader().getSid();
    OmemoDevice senderDevice = new OmemoDevice(senderJid, senderId);
    CipherAndAuthTag cipherAndAuthTag = getOmemoRatchet(manager).retrieveMessageKeyAndAuthTag(senderDevice, omemoElement);
    // Retrieve senders fingerprint.
    OmemoFingerprint senderFingerprint;
    try {
        senderFingerprint = getOmemoStoreBackend().getFingerprint(manager.getOwnDevice(), senderDevice);
    } catch (NoIdentityKeyException e) {
        throw new AssertionError("Cannot retrieve OmemoFingerprint of sender although decryption was successful: " + e);
    }
    // Reset the message counter.
    omemoStore.storeOmemoMessageCounter(manager.getOwnDevice(), senderDevice, 0);
    if (omemoElement.isMessageElement()) {
        // Use symmetric message key to decrypt message payload.
        String plaintext = OmemoRatchet.decryptMessageElement(omemoElement, cipherAndAuthTag);
        return new OmemoMessage.Received(omemoElement, cipherAndAuthTag.getKey(), cipherAndAuthTag.getIv(), plaintext, senderFingerprint, senderDevice, cipherAndAuthTag.wasPreKeyEncrypted());
    } else {
        // KeyTransportMessages don't require decryption of the payload.
        return new OmemoMessage.Received(omemoElement, cipherAndAuthTag.getKey(), cipherAndAuthTag.getIv(), null, senderFingerprint, senderDevice, cipherAndAuthTag.wasPreKeyEncrypted());
    }
}
Also used : OmemoDevice(org.jivesoftware.smackx.omemo.internal.OmemoDevice) CipherAndAuthTag(org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag) NoIdentityKeyException(org.jivesoftware.smackx.omemo.exceptions.NoIdentityKeyException) OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint) OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)

Example 3 with OmemoFingerprint

use of org.jivesoftware.smackx.omemo.trust.OmemoFingerprint in project Smack by igniterealtime.

the class OmemoKeyUtilTest method testPrettyFingerprint.

@Test
public void testPrettyFingerprint() {
    OmemoFingerprint fingerprint = new OmemoFingerprint("FFFFFFFFEEEEEEEEDDDDDDDDCCCCCCCCBBBBBBBBAAAAAAAA9999999988888888");
    String pretty = fingerprint.blocksOf8Chars();
    assertEquals(pretty, "FFFFFFFF EEEEEEEE DDDDDDDD CCCCCCCC BBBBBBBB AAAAAAAA 99999999 88888888");
}
Also used : OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint) Test(org.junit.Test)

Example 4 with OmemoFingerprint

use of org.jivesoftware.smackx.omemo.trust.OmemoFingerprint in project Smack by igniterealtime.

the class OmemoStoreTest method getFingerprint.

@Test
public void getFingerprint() throws IOException, CorruptedOmemoKeyException {
    assertNull("Method must return null for a non-existent fingerprint.", store.getFingerprint(alice));
    store.storeOmemoIdentityKeyPair(alice, store.generateOmemoIdentityKeyPair());
    OmemoFingerprint fingerprint = store.getFingerprint(alice);
    assertNotNull("fingerprint must not be null", fingerprint);
    assertEquals("Fingerprint must be of length 64", 64, fingerprint.length());
    // clean up
    store.removeOmemoIdentityKeyPair(alice);
}
Also used : OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint) Test(org.junit.Test)

Example 5 with OmemoFingerprint

use of org.jivesoftware.smackx.omemo.trust.OmemoFingerprint in project Smack by igniterealtime.

the class OmemoFingerprintTest method fingerprintTest.

@Test
public void fingerprintTest() {
    OmemoFingerprint first = new OmemoFingerprint("FINGER");
    OmemoFingerprint second = new OmemoFingerprint("TOE");
    assertNotSame(first, second);
    assertEquals(first, new OmemoFingerprint("FINGER"));
}
Also used : OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint) Test(org.junit.Test)

Aggregations

OmemoFingerprint (org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)8 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)4 Test (org.junit.Test)3 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)2 HashMap (java.util.HashMap)1 WeakHashMap (java.util.WeakHashMap)1 Message (org.jivesoftware.smack.packet.Message)1 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 Roster (org.jivesoftware.smack.roster.Roster)1 StoreHint (org.jivesoftware.smackx.hints.element.StoreHint)1 OmemoMessage (org.jivesoftware.smackx.omemo.OmemoMessage)1 OmemoKeyElement (org.jivesoftware.smackx.omemo.element.OmemoKeyElement)1 CannotEstablishOmemoSessionException (org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException)1 CorruptedOmemoKeyException (org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException)1 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)1 NoIdentityKeyException (org.jivesoftware.smackx.omemo.exceptions.NoIdentityKeyException)1 UntrustedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UntrustedOmemoIdentityException)1 CipherAndAuthTag (org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag)1 CiphertextTuple (org.jivesoftware.smackx.omemo.internal.CiphertextTuple)1 OmemoCachedDeviceList (org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList)1