Search in sources :

Example 1 with AsymmetricMasterSecret

use of org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret in project Signal-Android by WhisperSystems.

the class AttachmentDownloadJob method createAttachmentPointer.

@VisibleForTesting
SignalServiceAttachmentPointer createAttachmentPointer(MasterSecret masterSecret, Attachment attachment) throws InvalidPartException {
    if (TextUtils.isEmpty(attachment.getLocation())) {
        throw new InvalidPartException("empty content id");
    }
    if (TextUtils.isEmpty(attachment.getKey())) {
        throw new InvalidPartException("empty encrypted key");
    }
    try {
        AsymmetricMasterSecret asymmetricMasterSecret = MasterSecretUtil.getAsymmetricMasterSecret(context, masterSecret);
        long id = Long.parseLong(attachment.getLocation());
        byte[] key = MediaKey.getDecrypted(masterSecret, asymmetricMasterSecret, attachment.getKey());
        String relay = null;
        if (TextUtils.isEmpty(attachment.getRelay())) {
            relay = attachment.getRelay();
        }
        if (attachment.getDigest() != null) {
            Log.w(TAG, "Downloading attachment with digest: " + Hex.toString(attachment.getDigest()));
        } else {
            Log.w(TAG, "Downloading attachment with no digest...");
        }
        return new SignalServiceAttachmentPointer(id, null, key, relay, Optional.fromNullable(attachment.getDigest()));
    } catch (InvalidMessageException | IOException e) {
        Log.w(TAG, e);
        throw new InvalidPartException(e);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AsymmetricMasterSecret(org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) IOException(java.io.IOException) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 2 with AsymmetricMasterSecret

use of org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret in project Signal-Android by WhisperSystems.

the class MasterSecretDecryptJob method getAsymmetricDecryptedBody.

private String getAsymmetricDecryptedBody(MasterSecret masterSecret, String body) throws InvalidMessageException {
    try {
        AsymmetricMasterSecret asymmetricMasterSecret = MasterSecretUtil.getAsymmetricMasterSecret(context, masterSecret);
        AsymmetricMasterCipher asymmetricMasterCipher = new AsymmetricMasterCipher(asymmetricMasterSecret);
        if (TextUtils.isEmpty(body))
            return "";
        else
            return asymmetricMasterCipher.decryptBody(body);
    } catch (IOException e) {
        throw new InvalidMessageException(e);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AsymmetricMasterSecret(org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret) IOException(java.io.IOException) AsymmetricMasterCipher(org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher)

Aggregations

IOException (java.io.IOException)2 AsymmetricMasterSecret (org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 VisibleForTesting (android.support.annotation.VisibleForTesting)1 AsymmetricMasterCipher (org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher)1 SignalServiceAttachmentPointer (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer)1