Search in sources :

Example 36 with SignalProtocolAddress

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

the class SignalServiceMessageSender method buildGroupTargetInfo.

private GroupTargetInfo buildGroupTargetInfo(List<SignalServiceAddress> recipients) {
    List<String> addressNames = recipients.stream().map(SignalServiceAddress::getIdentifier).collect(Collectors.toList());
    Set<SignalProtocolAddress> destinations = store.getAllAddressesWithActiveSessions(addressNames);
    Map<String, List<Integer>> devicesByAddressName = new HashMap<>();
    destinations.addAll(recipients.stream().map(a -> new SignalProtocolAddress(a.getIdentifier(), SignalServiceAddress.DEFAULT_DEVICE_ID)).collect(Collectors.toList()));
    for (SignalProtocolAddress destination : destinations) {
        List<Integer> devices = devicesByAddressName.containsKey(destination.getName()) ? devicesByAddressName.get(destination.getName()) : new LinkedList<>();
        devices.add(destination.getDeviceId());
        devicesByAddressName.put(destination.getName(), devices);
    }
    Map<SignalServiceAddress, List<Integer>> recipientDevices = new HashMap<>();
    for (SignalServiceAddress recipient : recipients) {
        if (devicesByAddressName.containsKey(recipient.getIdentifier())) {
            recipientDevices.put(recipient, devicesByAddressName.get(recipient.getIdentifier()));
        }
    }
    return new GroupTargetInfo(new ArrayList<>(destinations), recipientDevices);
}
Also used : HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) OutgoingPushMessageList(org.whispersystems.signalservice.internal.push.OutgoingPushMessageList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 37 with SignalProtocolAddress

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

the class TextSecureSessionStore method getAddressName.

@Nullable
private SignalProtocolAddress getAddressName(File sessionFile) {
    try {
        String[] parts = sessionFile.getName().split("[.]");
        Recipient recipient = RecipientFactory.getRecipientForId(context, Integer.valueOf(parts[0]), true);
        int deviceId;
        if (parts.length > 1)
            deviceId = Integer.parseInt(parts[1]);
        else
            deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
        return new SignalProtocolAddress(recipient.getNumber(), deviceId);
    } catch (NumberFormatException e) {
        Log.w(TAG, e);
        return null;
    }
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Nullable(android.support.annotation.Nullable)

Example 38 with SignalProtocolAddress

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

the class IdentityUtil method getRemoteIdentityKey.

@UiThread
public static ListenableFuture<Optional<IdentityKey>> getRemoteIdentityKey(final Context context, final MasterSecret masterSecret, final Recipient recipient) {
    final SettableFuture<Optional<IdentityKey>> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Optional<IdentityKey>>() {

        @Override
        protected Optional<IdentityKey> doInBackground(Recipient... recipient) {
            SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
            SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(recipient[0].getNumber(), SignalServiceAddress.DEFAULT_DEVICE_ID);
            SessionRecord record = sessionStore.loadSession(axolotlAddress);
            if (record == null) {
                return Optional.absent();
            }
            return Optional.fromNullable(record.getSessionState().getRemoteIdentityKey());
        }

        @Override
        protected void onPostExecute(Optional<IdentityKey> result) {
            future.set(result);
        }
    }.execute(recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) IdentityKey(org.whispersystems.libsignal.IdentityKey) Optional(org.whispersystems.libsignal.util.guava.Optional) Recipient(org.thoughtcrime.securesms.recipients.Recipient) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord) UiThread(android.support.annotation.UiThread)

Example 39 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project toshi-android-client by toshiapp.

the class SignalSessionStore method deleteAllSessions.

@Override
public void deleteAllSessions(final String name) {
    List<Integer> devices = getSubDeviceSessions(name);
    deleteSession(new SignalProtocolAddress(name, DEFAULT_DEVICE_ID));
    for (int device : devices) {
        deleteSession(new SignalProtocolAddress(name, device));
    }
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 40 with SignalProtocolAddress

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

the class SignalServiceMessageSender method getEncryptedMessage.

private OutgoingPushMessage getEncryptedMessage(PushServiceSocket socket, SignalServiceAddress recipient, int deviceId, byte[] plaintext, boolean silent) throws IOException, UntrustedIdentityException {
    SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(recipient.getNumber(), deviceId);
    SignalServiceCipher cipher = new SignalServiceCipher(localAddress, store);
    if (!store.containsSession(signalProtocolAddress)) {
        try {
            List<PreKeyBundle> preKeys = socket.getPreKeys(recipient, deviceId);
            for (PreKeyBundle preKey : preKeys) {
                try {
                    SignalProtocolAddress preKeyAddress = new SignalProtocolAddress(recipient.getNumber(), preKey.getDeviceId());
                    SessionBuilder sessionBuilder = new SessionBuilder(store, preKeyAddress);
                    sessionBuilder.process(preKey);
                } catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
                    throw new UntrustedIdentityException("Untrusted identity key!", recipient.getNumber(), preKey.getIdentityKey());
                }
            }
            if (eventListener.isPresent()) {
                eventListener.get().onSecurityEvent(recipient);
            }
        } catch (InvalidKeyException e) {
            throw new IOException(e);
        }
    }
    try {
        return cipher.encrypt(signalProtocolAddress, plaintext, silent);
    } catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
        throw new UntrustedIdentityException("Untrusted on send", recipient.getNumber(), e.getUntrustedIdentity());
    }
}
Also used : PreKeyBundle(org.whispersystems.libsignal.state.PreKeyBundle) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) SignalServiceCipher(org.whispersystems.signalservice.api.crypto.SignalServiceCipher) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Aggregations

SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)77 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)14 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)11 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)11 ArrayList (java.util.ArrayList)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 IOException (java.io.IOException)9 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)9 Optional (org.whispersystems.libsignal.util.guava.Optional)9 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 ContentHint (org.whispersystems.signalservice.api.crypto.ContentHint)8 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)8 NonNull (androidx.annotation.NonNull)6 LinkedList (java.util.LinkedList)6 Collectors (java.util.stream.Collectors)6 SenderKeyDistributionMessage (org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage)6 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)6