use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.
the class SafetyNumberChangeRepository method trustOrVerifyChangedRecipientsAndResendInternal.
@WorkerThread
private TrustAndVerifyResult trustOrVerifyChangedRecipientsAndResendInternal(@NonNull List<ChangedRecipient> changedRecipients, @NonNull MessageRecord messageRecord) {
if (changedRecipients.isEmpty()) {
Log.d(TAG, "No changed recipients to process, will still process message record");
}
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
for (ChangedRecipient changedRecipient : changedRecipients) {
SignalProtocolAddress mismatchAddress = changedRecipient.getRecipient().requireServiceId().toProtocolAddress(SignalServiceAddress.DEFAULT_DEVICE_ID);
Log.d(TAG, "Saving identity for: " + changedRecipient.getRecipient().getId() + " " + changedRecipient.getIdentityRecord().getIdentityKey().hashCode());
SignalIdentityKeyStore.SaveResult result = ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(mismatchAddress, changedRecipient.getIdentityRecord().getIdentityKey(), true);
Log.d(TAG, "Saving identity result: " + result);
if (result == SignalIdentityKeyStore.SaveResult.NO_CHANGE) {
Log.i(TAG, "Archiving sessions explicitly as they appear to be out of sync.");
ApplicationDependencies.getProtocolStore().aci().sessions().archiveSession(changedRecipient.getRecipient().getId(), SignalServiceAddress.DEFAULT_DEVICE_ID);
ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(mismatchAddress);
SignalDatabase.senderKeyShared().deleteAllFor(changedRecipient.getRecipient().getId());
}
}
}
if (messageRecord.isOutgoing()) {
processOutgoingMessageRecord(changedRecipients, messageRecord);
}
return TrustAndVerifyResult.trustVerifyAndResend(changedRecipients, messageRecord);
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.
the class SenderKeySharedDatabase method getSharedWith.
/**
* Get the set of recipientIds that know about the distributionId in question.
*/
@NonNull
public Set<SignalProtocolAddress> getSharedWith(@NonNull DistributionId distributionId) {
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
String query = DISTRIBUTION_ID + " = ?";
String[] args = SqlUtil.buildArgs(distributionId);
Set<SignalProtocolAddress> addresses = new HashSet<>();
try (Cursor cursor = db.query(TABLE_NAME, new String[] { ADDRESS, DEVICE }, query, args, null, null, null)) {
while (cursor.moveToNext()) {
String address = CursorUtil.requireString(cursor, ADDRESS);
int device = CursorUtil.requireInt(cursor, DEVICE);
addresses.add(new SignalProtocolAddress(address, device));
}
}
return addresses;
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.
the class SenderKeySharedDatabase method deleteAllFor.
/**
* Clear the shared status for all distributionIds for a set of addresses.
*/
public void deleteAllFor(@NonNull Collection<SignalProtocolAddress> addresses) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
String query = ADDRESS + " = ? AND " + DEVICE + " = ?";
db.beginTransaction();
try {
for (SignalProtocolAddress address : addresses) {
db.delete(TABLE_NAME, query, SqlUtil.buildArgs(address.getName(), address.getDeviceId()));
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
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, Optional<UnidentifiedAccess> unidentifiedAccess, int deviceId, byte[] plaintext) throws IOException, InvalidKeyException, UntrustedIdentityException {
SignalProtocolAddress signalProtocolAddress = new SignalProtocolAddress(recipient.getIdentifier(), deviceId);
SignalServiceCipher cipher = new SignalServiceCipher(localAddress, store, null);
if (!store.containsSession(signalProtocolAddress)) {
try {
List<PreKeyBundle> preKeys = socket.getPreKeys(recipient, unidentifiedAccess, deviceId);
for (PreKeyBundle preKey : preKeys) {
try {
SignalProtocolAddress preKeyAddress = new SignalProtocolAddress(recipient.getIdentifier(), preKey.getDeviceId());
SessionBuilder sessionBuilder = new SessionBuilder(store, preKeyAddress);
sessionBuilder.process(preKey);
} catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
throw new UntrustedIdentityException("Untrusted identity key!", recipient.getIdentifier(), preKey.getIdentityKey());
}
}
if (eventListener.isPresent()) {
eventListener.get().onSecurityEvent(recipient);
}
} catch (InvalidKeyException e) {
throw new IOException(e);
}
}
try {
return cipher.encrypt(signalProtocolAddress, unidentifiedAccess, plaintext);
} catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
throw new UntrustedIdentityException("Untrusted on send", recipient.getIdentifier(), e.getUntrustedIdentity());
}
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.
the class TextSecureSessionStore method archiveAllSessions.
public void archiveAllSessions() {
synchronized (LOCK) {
List<SessionDatabase.SessionRow> sessions = SignalDatabase.sessions().getAll(accountId);
for (SessionDatabase.SessionRow row : sessions) {
row.getRecord().archiveCurrentState();
storeSession(new SignalProtocolAddress(row.getAddress(), row.getDeviceId()), row.getRecord());
}
}
}
Aggregations