use of org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus in project Signal-Android by signalapp.
the class TextSecureIdentityKeyStore method saveIdentity.
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
synchronized (LOCK) {
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
Address signalAddress = Address.fromExternal(context, address.getName());
Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(signalAddress);
if (!identityRecord.isPresent()) {
Log.w(TAG, "Saving new identity...");
identityDatabase.saveIdentity(signalAddress, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
return false;
}
if (!identityRecord.get().getIdentityKey().equals(identityKey)) {
Log.w(TAG, "Replacing existing identity...");
VerifiedStatus verifiedStatus;
if (identityRecord.get().getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.get().getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
verifiedStatus = VerifiedStatus.UNVERIFIED;
} else {
verifiedStatus = VerifiedStatus.DEFAULT;
}
identityDatabase.saveIdentity(signalAddress, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
IdentityUtil.markIdentityUpdate(context, Recipient.from(context, signalAddress, true));
SessionUtil.archiveSiblingSessions(context, address);
return true;
}
if (isNonBlockingApprovalRequired(identityRecord.get())) {
Log.w(TAG, "Setting approval status...");
identityDatabase.setApproval(signalAddress, nonBlockingApproval);
return false;
}
return false;
}
}
use of org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus in project Signal-Android by WhisperSystems.
the class SignalBaseIdentityKeyStore method saveIdentity.
@NonNull
public SaveResult saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
synchronized (LOCK) {
IdentityStoreRecord identityRecord = cache.get(address.getName());
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
if (identityRecord == null) {
Log.i(TAG, "Saving new identity...");
cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
return SaveResult.NEW;
}
if (!identityRecord.getIdentityKey().equals(identityKey)) {
Log.i(TAG, "Replacing existing identity... Existing: " + identityRecord.getIdentityKey().hashCode() + " New: " + identityKey.hashCode());
VerifiedStatus verifiedStatus;
if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
verifiedStatus = VerifiedStatus.UNVERIFIED;
} else {
verifiedStatus = VerifiedStatus.DEFAULT;
}
cache.save(address.getName(), recipientId, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
IdentityUtil.markIdentityUpdate(context, recipientId);
ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(address);
SignalDatabase.senderKeyShared().deleteAllFor(recipientId);
return SaveResult.UPDATE;
}
if (isNonBlockingApprovalRequired(identityRecord)) {
Log.i(TAG, "Setting approval status...");
cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
}
return SaveResult.NO_CHANGE;
}
}
use of org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus in project Signal-Android by signalapp.
the class SignalBaseIdentityKeyStore method saveIdentity.
@NonNull
public SaveResult saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
synchronized (LOCK) {
IdentityStoreRecord identityRecord = cache.get(address.getName());
RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
if (identityRecord == null) {
Log.i(TAG, "Saving new identity...");
cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
return SaveResult.NEW;
}
if (!identityRecord.getIdentityKey().equals(identityKey)) {
Log.i(TAG, "Replacing existing identity... Existing: " + identityRecord.getIdentityKey().hashCode() + " New: " + identityKey.hashCode());
VerifiedStatus verifiedStatus;
if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
verifiedStatus = VerifiedStatus.UNVERIFIED;
} else {
verifiedStatus = VerifiedStatus.DEFAULT;
}
cache.save(address.getName(), recipientId, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
IdentityUtil.markIdentityUpdate(context, recipientId);
ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(address);
SignalDatabase.senderKeyShared().deleteAllFor(recipientId);
return SaveResult.UPDATE;
}
if (isNonBlockingApprovalRequired(identityRecord)) {
Log.i(TAG, "Setting approval status...");
cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
}
return SaveResult.NO_CHANGE;
}
}
Aggregations