Search in sources :

Example 1 with CiphertextTuple

use of org.jivesoftware.smackx.omemo.internal.CiphertextTuple in project Smack by igniterealtime.

the class SignalOmemoRatchet method doubleRatchetEncrypt.

@Override
public CiphertextTuple doubleRatchetEncrypt(OmemoDevice recipient, byte[] messageKey) {
    CiphertextMessage ciphertextMessage;
    try {
        ciphertextMessage = getCipher(recipient).encrypt(messageKey);
    } catch (UntrustedIdentityException e) {
        throw new AssertionError("Signals trust management MUST be disabled.");
    }
    int type = ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE ? OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE : OmemoElement.TYPE_OMEMO_MESSAGE;
    return new CiphertextTuple(ciphertextMessage.serialize(), type);
}
Also used : UntrustedIdentityException(org.whispersystems.libsignal.UntrustedIdentityException) CiphertextMessage(org.whispersystems.libsignal.protocol.CiphertextMessage) CiphertextTuple(org.jivesoftware.smackx.omemo.internal.CiphertextTuple)

Example 2 with CiphertextTuple

use of org.jivesoftware.smackx.omemo.internal.CiphertextTuple in project Smack by igniterealtime.

the class OmemoMessageBuilder method addRecipient.

/**
 * Add a new recipient device to the message.
 *
 * @param contactsDevice device of the recipient
 *
 * @throws NoIdentityKeyException if we have no identityKey of that device. Can be fixed by fetching and
 *                                processing the devices bundle.
 * @throws CorruptedOmemoKeyException if the identityKey of that device is corrupted.
 * @throws UndecidedOmemoIdentityException if the user hasn't yet decided whether to trust that device or not.
 * @throws UntrustedOmemoIdentityException if the user has decided not to trust that device.
 * @throws IOException if an I/O error occurred.
 */
public void addRecipient(OmemoDevice contactsDevice) throws NoIdentityKeyException, CorruptedOmemoKeyException, UndecidedOmemoIdentityException, UntrustedOmemoIdentityException, IOException {
    OmemoFingerprint fingerprint;
    fingerprint = OmemoService.getInstance().getOmemoStoreBackend().getFingerprint(userDevice, contactsDevice);
    switch(trustCallback.getTrust(contactsDevice, fingerprint)) {
        case undecided:
            throw new UndecidedOmemoIdentityException(contactsDevice);
        case trusted:
            CiphertextTuple encryptedKey = ratchet.doubleRatchetEncrypt(contactsDevice, messageKey);
            keys.add(new OmemoKeyElement(encryptedKey.getCiphertext(), contactsDevice.getDeviceId(), encryptedKey.isPreKeyMessage()));
            break;
        case untrusted:
            throw new UntrustedOmemoIdentityException(contactsDevice, fingerprint);
    }
}
Also used : UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) OmemoKeyElement(org.jivesoftware.smackx.omemo.element.OmemoKeyElement) OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint) UntrustedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UntrustedOmemoIdentityException) CiphertextTuple(org.jivesoftware.smackx.omemo.internal.CiphertextTuple)

Example 3 with CiphertextTuple

use of org.jivesoftware.smackx.omemo.internal.CiphertextTuple in project Smack by igniterealtime.

the class WrapperObjectsTest method ciphertextTupleTest.

@Test
public void ciphertextTupleTest() {
    byte[] c = OmemoMessageBuilder.generateIv();
    CiphertextTuple c1 = new CiphertextTuple(c, OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE);
    assertTrue(c1.isPreKeyMessage());
    assertArrayEquals(c, c1.getCiphertext());
    assertEquals(OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE, c1.getMessageType());
    CiphertextTuple c2 = new CiphertextTuple(c, OmemoElement.TYPE_OMEMO_MESSAGE);
    assertFalse(c2.isPreKeyMessage());
    assertEquals(OmemoElement.TYPE_OMEMO_MESSAGE, c2.getMessageType());
}
Also used : CiphertextTuple(org.jivesoftware.smackx.omemo.internal.CiphertextTuple) Test(org.junit.Test)

Aggregations

CiphertextTuple (org.jivesoftware.smackx.omemo.internal.CiphertextTuple)3 OmemoKeyElement (org.jivesoftware.smackx.omemo.element.OmemoKeyElement)1 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)1 UntrustedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UntrustedOmemoIdentityException)1 OmemoFingerprint (org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)1 Test (org.junit.Test)1 UntrustedIdentityException (org.whispersystems.libsignal.UntrustedIdentityException)1 CiphertextMessage (org.whispersystems.libsignal.protocol.CiphertextMessage)1