Search in sources :

Example 1 with CiphertextMessage

use of org.whispersystems.libsignal.protocol.CiphertextMessage in project libsignal-service-java by signalapp.

the class SignalServiceCipher method encrypt.

public OutgoingPushMessage encrypt(SignalProtocolAddress destination, byte[] unpaddedMessage, boolean silent) throws UntrustedIdentityException {
    SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, destination);
    PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
    CiphertextMessage message = sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage));
    int remoteRegistrationId = sessionCipher.getRemoteRegistrationId();
    String body = Base64.encodeBytes(message.serialize());
    int type;
    switch(message.getType()) {
        case CiphertextMessage.PREKEY_TYPE:
            type = Type.PREKEY_BUNDLE_VALUE;
            break;
        case CiphertextMessage.WHISPER_TYPE:
            type = Type.CIPHERTEXT_VALUE;
            break;
        default:
            throw new AssertionError("Bad type: " + message.getType());
    }
    return new OutgoingPushMessage(type, destination.getDeviceId(), remoteRegistrationId, body, silent);
}
Also used : CiphertextMessage(org.whispersystems.libsignal.protocol.CiphertextMessage) PushTransportDetails(org.whispersystems.signalservice.internal.push.PushTransportDetails) SessionCipher(org.whispersystems.libsignal.SessionCipher) OutgoingPushMessage(org.whispersystems.signalservice.internal.push.OutgoingPushMessage)

Example 2 with CiphertextMessage

use of org.whispersystems.libsignal.protocol.CiphertextMessage in project Signal-Android by WhisperSystems.

the class SignalServiceCipher method encryptForGroup.

public byte[] encryptForGroup(DistributionId distributionId, List<SignalProtocolAddress> destinations, SenderCertificate senderCertificate, byte[] unpaddedMessage, ContentHint contentHint, byte[] groupId) throws NoSessionException, UntrustedIdentityException, InvalidKeyException, InvalidRegistrationIdException {
    PushTransportDetails transport = new PushTransportDetails();
    SignalProtocolAddress localProtocolAddress = new SignalProtocolAddress(localAddress.getIdentifier(), localDeviceId);
    SignalGroupCipher groupCipher = new SignalGroupCipher(sessionLock, new GroupCipher(signalProtocolStore, localProtocolAddress));
    SignalSealedSessionCipher sessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orNull(), localDeviceId));
    CiphertextMessage message = groupCipher.encrypt(distributionId.asUuid(), transport.getPaddedMessageBody(unpaddedMessage));
    UnidentifiedSenderMessageContent messageContent = new UnidentifiedSenderMessageContent(message, senderCertificate, contentHint.getType(), Optional.of(groupId));
    return sessionCipher.multiRecipientEncrypt(destinations, messageContent);
}
Also used : SealedSessionCipher(org.signal.libsignal.metadata.SealedSessionCipher) CiphertextMessage(org.whispersystems.libsignal.protocol.CiphertextMessage) PushTransportDetails(org.whispersystems.signalservice.internal.push.PushTransportDetails) GroupCipher(org.whispersystems.libsignal.groups.GroupCipher) UnidentifiedSenderMessageContent(org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 3 with CiphertextMessage

use of org.whispersystems.libsignal.protocol.CiphertextMessage 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 4 with CiphertextMessage

use of org.whispersystems.libsignal.protocol.CiphertextMessage in project libsignal-service-java by signalapp.

the class SignalServiceCipher method encrypt.

public OutgoingPushMessage encrypt(SignalProtocolAddress destination, Optional<UnidentifiedAccess> unidentifiedAccess, byte[] unpaddedMessage) throws UntrustedIdentityException, InvalidKeyException {
    if (unidentifiedAccess.isPresent()) {
        SealedSessionCipher sessionCipher = new SealedSessionCipher(signalProtocolStore, localAddress.getUuid().orNull(), localAddress.getNumber().orNull(), 1);
        PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion(destination));
        byte[] ciphertext = sessionCipher.encrypt(destination, unidentifiedAccess.get().getUnidentifiedCertificate(), transportDetails.getPaddedMessageBody(unpaddedMessage));
        String body = Base64.encodeBytes(ciphertext);
        int remoteRegistrationId = sessionCipher.getRemoteRegistrationId(destination);
        return new OutgoingPushMessage(Type.UNIDENTIFIED_SENDER_VALUE, destination.getDeviceId(), remoteRegistrationId, body);
    } else {
        SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, destination);
        PushTransportDetails transportDetails = new PushTransportDetails(sessionCipher.getSessionVersion());
        CiphertextMessage message = sessionCipher.encrypt(transportDetails.getPaddedMessageBody(unpaddedMessage));
        int remoteRegistrationId = sessionCipher.getRemoteRegistrationId();
        String body = Base64.encodeBytes(message.serialize());
        int type;
        switch(message.getType()) {
            case CiphertextMessage.PREKEY_TYPE:
                type = Type.PREKEY_BUNDLE_VALUE;
                break;
            case CiphertextMessage.WHISPER_TYPE:
                type = Type.CIPHERTEXT_VALUE;
                break;
            default:
                throw new AssertionError("Bad type: " + message.getType());
        }
        return new OutgoingPushMessage(type, destination.getDeviceId(), remoteRegistrationId, body);
    }
}
Also used : SealedSessionCipher(org.signal.libsignal.metadata.SealedSessionCipher) CiphertextMessage(org.whispersystems.libsignal.protocol.CiphertextMessage) PushTransportDetails(org.whispersystems.signalservice.internal.push.PushTransportDetails) ByteString(com.google.protobuf.ByteString) SessionCipher(org.whispersystems.libsignal.SessionCipher) SealedSessionCipher(org.signal.libsignal.metadata.SealedSessionCipher) OutgoingPushMessage(org.whispersystems.signalservice.internal.push.OutgoingPushMessage)

Example 5 with CiphertextMessage

use of org.whispersystems.libsignal.protocol.CiphertextMessage in project Signal-Android by signalapp.

the class SignalServiceCipher method encryptForGroup.

public byte[] encryptForGroup(DistributionId distributionId, List<SignalProtocolAddress> destinations, SenderCertificate senderCertificate, byte[] unpaddedMessage, ContentHint contentHint, byte[] groupId) throws NoSessionException, UntrustedIdentityException, InvalidKeyException, InvalidRegistrationIdException {
    PushTransportDetails transport = new PushTransportDetails();
    SignalProtocolAddress localProtocolAddress = new SignalProtocolAddress(localAddress.getIdentifier(), localDeviceId);
    SignalGroupCipher groupCipher = new SignalGroupCipher(sessionLock, new GroupCipher(signalProtocolStore, localProtocolAddress));
    SignalSealedSessionCipher sessionCipher = new SignalSealedSessionCipher(sessionLock, new SealedSessionCipher(signalProtocolStore, localAddress.getServiceId().uuid(), localAddress.getNumber().orNull(), localDeviceId));
    CiphertextMessage message = groupCipher.encrypt(distributionId.asUuid(), transport.getPaddedMessageBody(unpaddedMessage));
    UnidentifiedSenderMessageContent messageContent = new UnidentifiedSenderMessageContent(message, senderCertificate, contentHint.getType(), Optional.of(groupId));
    return sessionCipher.multiRecipientEncrypt(destinations, messageContent);
}
Also used : SealedSessionCipher(org.signal.libsignal.metadata.SealedSessionCipher) CiphertextMessage(org.whispersystems.libsignal.protocol.CiphertextMessage) PushTransportDetails(org.whispersystems.signalservice.internal.push.PushTransportDetails) GroupCipher(org.whispersystems.libsignal.groups.GroupCipher) UnidentifiedSenderMessageContent(org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Aggregations

CiphertextMessage (org.whispersystems.libsignal.protocol.CiphertextMessage)5 PushTransportDetails (org.whispersystems.signalservice.internal.push.PushTransportDetails)4 SealedSessionCipher (org.signal.libsignal.metadata.SealedSessionCipher)3 UnidentifiedSenderMessageContent (org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent)2 SessionCipher (org.whispersystems.libsignal.SessionCipher)2 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)2 GroupCipher (org.whispersystems.libsignal.groups.GroupCipher)2 OutgoingPushMessage (org.whispersystems.signalservice.internal.push.OutgoingPushMessage)2 ByteString (com.google.protobuf.ByteString)1 CiphertextTuple (org.jivesoftware.smackx.omemo.internal.CiphertextTuple)1 UntrustedIdentityException (org.whispersystems.libsignal.UntrustedIdentityException)1