Search in sources :

Example 1 with OutgoingPushMessage

use of org.whispersystems.signalservice.internal.push.OutgoingPushMessage 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 OutgoingPushMessage

use of org.whispersystems.signalservice.internal.push.OutgoingPushMessage in project Signal-Android by WhisperSystems.

the class SignalServiceMessageSender method getEncryptedMessages.

private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket socket, SignalServiceAddress recipient, Optional<UnidentifiedAccess> unidentifiedAccess, long timestamp, EnvelopeContent plaintext, boolean online) throws IOException, InvalidKeyException, UntrustedIdentityException {
    List<OutgoingPushMessage> messages = new LinkedList<>();
    List<Integer> subDevices = store.getSubDeviceSessions(recipient.getIdentifier());
    List<Integer> deviceIds = new ArrayList<>(subDevices.size() + 1);
    deviceIds.add(SignalServiceAddress.DEFAULT_DEVICE_ID);
    deviceIds.addAll(subDevices);
    if (recipient.matches(localAddress)) {
        deviceIds.remove(Integer.valueOf(localDeviceId));
    }
    for (int deviceId : deviceIds) {
        if (deviceId == SignalServiceAddress.DEFAULT_DEVICE_ID || store.containsSession(new SignalProtocolAddress(recipient.getIdentifier(), deviceId))) {
            messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, deviceId, plaintext));
        }
    }
    return new OutgoingPushMessageList(recipient.getIdentifier(), timestamp, messages, online);
}
Also used : OutgoingPushMessageList(org.whispersystems.signalservice.internal.push.OutgoingPushMessageList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) OutgoingPushMessage(org.whispersystems.signalservice.internal.push.OutgoingPushMessage)

Example 3 with OutgoingPushMessage

use of org.whispersystems.signalservice.internal.push.OutgoingPushMessage 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 4 with OutgoingPushMessage

use of org.whispersystems.signalservice.internal.push.OutgoingPushMessage in project Signal-Android by signalapp.

the class SignalServiceMessageSender method getEncryptedMessages.

private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket socket, SignalServiceAddress recipient, Optional<UnidentifiedAccess> unidentifiedAccess, long timestamp, EnvelopeContent plaintext, boolean online) throws IOException, InvalidKeyException, UntrustedIdentityException {
    List<OutgoingPushMessage> messages = new LinkedList<>();
    List<Integer> subDevices = store.getSubDeviceSessions(recipient.getIdentifier());
    List<Integer> deviceIds = new ArrayList<>(subDevices.size() + 1);
    deviceIds.add(SignalServiceAddress.DEFAULT_DEVICE_ID);
    deviceIds.addAll(subDevices);
    if (recipient.matches(localAddress)) {
        deviceIds.remove(Integer.valueOf(localDeviceId));
    }
    for (int deviceId : deviceIds) {
        if (deviceId == SignalServiceAddress.DEFAULT_DEVICE_ID || store.containsSession(new SignalProtocolAddress(recipient.getIdentifier(), deviceId))) {
            messages.add(getEncryptedMessage(socket, recipient, unidentifiedAccess, deviceId, plaintext));
        }
    }
    return new OutgoingPushMessageList(recipient.getIdentifier(), timestamp, messages, online);
}
Also used : OutgoingPushMessageList(org.whispersystems.signalservice.internal.push.OutgoingPushMessageList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ContentHint(org.whispersystems.signalservice.api.crypto.ContentHint) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) OutgoingPushMessage(org.whispersystems.signalservice.internal.push.OutgoingPushMessage)

Aggregations

OutgoingPushMessage (org.whispersystems.signalservice.internal.push.OutgoingPushMessage)4 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 SessionCipher (org.whispersystems.libsignal.SessionCipher)2 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)2 CiphertextMessage (org.whispersystems.libsignal.protocol.CiphertextMessage)2 ContentHint (org.whispersystems.signalservice.api.crypto.ContentHint)2 OutgoingPushMessageList (org.whispersystems.signalservice.internal.push.OutgoingPushMessageList)2 PushTransportDetails (org.whispersystems.signalservice.internal.push.PushTransportDetails)2 ByteString (com.google.protobuf.ByteString)1 SealedSessionCipher (org.signal.libsignal.metadata.SealedSessionCipher)1