Search in sources :

Example 1 with SignalServiceContentProto

use of org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto in project Signal-Android by WhisperSystems.

the class SignalServiceCipher method decrypt.

/**
 * Decrypt a received {@link SignalServiceEnvelope}
 *
 * @param envelope The received SignalServiceEnvelope
 *
 * @return a decrypted SignalServiceContent
 */
public SignalServiceContent decrypt(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, InvalidMetadataVersionException, ProtocolInvalidKeyIdException, ProtocolLegacyMessageException, ProtocolUntrustedIdentityException, ProtocolNoSessionException, ProtocolInvalidVersionException, ProtocolInvalidMessageException, ProtocolInvalidKeyException, ProtocolDuplicateMessageException, SelfSendException, UnsupportedDataMessageException, InvalidMessageStructureException {
    try {
        if (envelope.hasLegacyMessage()) {
            Plaintext plaintext = decrypt(envelope, envelope.getLegacyMessage());
            SignalServiceProtos.DataMessage dataMessage = SignalServiceProtos.DataMessage.parseFrom(plaintext.getData());
            SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder().setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress)).setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata)).setLegacyDataMessage(dataMessage).build();
            return SignalServiceContent.createFromProto(contentProto);
        } else if (envelope.hasContent()) {
            Plaintext plaintext = decrypt(envelope, envelope.getContent());
            SignalServiceProtos.Content content = SignalServiceProtos.Content.parseFrom(plaintext.getData());
            SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder().setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress)).setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata)).setContent(content).build();
            return SignalServiceContent.createFromProto(contentProto);
        }
        return null;
    } catch (InvalidProtocolBufferException e) {
        throw new InvalidMetadataMessageException(e);
    }
}
Also used : SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) UnidentifiedSenderMessageContent(org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SignalServiceContentProto(org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto) InvalidMetadataMessageException(org.signal.libsignal.metadata.InvalidMetadataMessageException)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 InvalidMetadataMessageException (org.signal.libsignal.metadata.InvalidMetadataMessageException)1 UnidentifiedSenderMessageContent (org.signal.libsignal.metadata.protocol.UnidentifiedSenderMessageContent)1 PlaintextContent (org.whispersystems.libsignal.protocol.PlaintextContent)1 SignalServiceContent (org.whispersystems.signalservice.api.messages.SignalServiceContent)1 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)1 SignalServiceContentProto (org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto)1