use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.
the class SenderKeySharedDatabase method delete.
/**
* Clear the shared statuses for all provided addresses.
*/
public void delete(@NonNull DistributionId distributionId, @NonNull Collection<SignalProtocolAddress> addresses) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
String query = DISTRIBUTION_ID + " = ? AND " + ADDRESS + " = ? AND " + DEVICE + " = ?";
db.beginTransaction();
try {
for (SignalProtocolAddress address : addresses) {
db.delete(TABLE_NAME, query, SqlUtil.buildArgs(distributionId, address.getName(), address.getDeviceId()));
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method handleSenderKeyRetryReceipt.
private void handleSenderKeyRetryReceipt(@NonNull Recipient requester, @Nullable MessageLogEntry messageLogEntry, @NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage) {
long sentTimestamp = decryptionErrorMessage.getTimestamp();
MessageRecord relatedMessage = findRetryReceiptRelatedMessage(context, messageLogEntry, sentTimestamp);
if (relatedMessage == null) {
warn(content.getTimestamp(), "[RetryReceipt-SK] The related message could not be found! There shouldn't be any sender key resends where we can't find the related message. Skipping.");
return;
}
Recipient threadRecipient = SignalDatabase.threads().getRecipientForThreadId(relatedMessage.getThreadId());
if (threadRecipient == null) {
warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a thread recipient! Skipping.");
return;
}
if (!threadRecipient.isPushV2Group()) {
warn(content.getTimestamp(), "[RetryReceipt-SK] Thread recipient is not a v2 group! Skipping.");
return;
}
GroupId.V2 groupId = threadRecipient.requireGroupId().requireV2();
DistributionId distributionId = SignalDatabase.groups().getOrCreateDistributionId(groupId);
SignalProtocolAddress requesterAddress = new SignalProtocolAddress(requester.requireServiceId().toString(), content.getSenderDevice());
SignalDatabase.senderKeyShared().delete(distributionId, Collections.singleton(requesterAddress));
if (messageLogEntry != null) {
warn(content.getTimestamp(), "[RetryReceipt-SK] Found MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ". Scheduling a resend.");
ApplicationDependencies.getJobManager().add(new ResendMessageJob(messageLogEntry.getRecipientId(), messageLogEntry.getDateSent(), messageLogEntry.getContent(), messageLogEntry.getContentHint(), groupId, distributionId));
} else {
warn(content.getTimestamp(), "[RetryReceipt-SK] Unable to find MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ".");
Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroup(groupId);
if (!groupRecord.isPresent()) {
warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a record for the group!");
return;
}
if (!groupRecord.get().getMembers().contains(requester.getId())) {
warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is not in the group, so we cannot send them a SenderKeyDistributionMessage.");
return;
}
warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is in the group, so we'll send them a SenderKeyDistributionMessage.");
ApplicationDependencies.getJobManager().add(new SenderKeyDistributionSendJob(requester.getId(), groupRecord.get().getId().requireV2()));
}
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method ratchetKeyMatches.
public static boolean ratchetKeyMatches(@NonNull Recipient recipient, int deviceId, @NonNull ECPublicKey ratchetKey) {
SignalProtocolAddress address = recipient.resolve().requireServiceId().toProtocolAddress(deviceId);
SessionRecord session = ApplicationDependencies.getProtocolStore().aci().loadSession(address);
return session.currentRatchetKeyMatches(ratchetKey);
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.
the class IdentityUtil method saveIdentity.
public static void saveIdentity(String user, IdentityKey identityKey) {
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
SessionStore sessionStore = ApplicationDependencies.getProtocolStore().aci();
SignalProtocolAddress address = new SignalProtocolAddress(user, SignalServiceAddress.DEFAULT_DEVICE_ID);
if (ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(address, identityKey)) {
if (sessionStore.containsSession(address)) {
SessionRecord sessionRecord = sessionStore.loadSession(address);
sessionRecord.archiveCurrentState();
sessionStore.storeSession(address, sessionRecord);
}
}
}
}
use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.
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