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);
}
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;
}
}
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;
}
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));
}
}
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());
}
}
Aggregations