public static SignalAccount load(
File dataPath, String account, boolean waitForLock, final TrustNewIdentity trustNewIdentity
) throws IOException {
+ logger.trace("Opening account file");
final var fileName = getFileName(dataPath, account);
final var pair = openFileChannel(fileName, waitForLock);
try {
var signalAccount = new SignalAccount(pair.first(), pair.second());
+ logger.trace("Loading account file");
signalAccount.load(dataPath, trustNewIdentity);
+ logger.trace("Migrating legacy parts of account file");
signalAccount.migrateLegacyConfigs();
if (!account.equals(signalAccount.getAccount())) {
final var identityInfo = loadIdentityLocked(recipientId);
if (identityInfo != null && identityInfo.getIdentityKey().equals(identityKey)) {
// Identity already exists, not updating the trust level
+ logger.trace("Not storing new identity for recipient {}, identity already stored", recipientId);
return false;
}
isRetryingDecryption = retryingDecryption;
}
- public boolean setIdentityTrustLevel(
- RecipientId recipientId, IdentityKey identityKey, TrustLevel trustLevel
- ) {
+ public boolean setIdentityTrustLevel(RecipientId recipientId, IdentityKey identityKey, TrustLevel trustLevel) {
synchronized (cachedIdentities) {
final var identityInfo = loadIdentityLocked(recipientId);
- if (identityInfo == null
- || !identityInfo.getIdentityKey().equals(identityKey)
- || identityInfo.getTrustLevel() == trustLevel) {
- // Identity not found or trust not changed, not updating the trust level
+ if (identityInfo == null) {
+ logger.debug("Not updating trust level for recipient {}, identity not found", recipientId);
+ return false;
+ }
+ if (!identityInfo.getIdentityKey().equals(identityKey)) {
+ logger.debug("Not updating trust level for recipient {}, different identity found", recipientId);
+ return false;
+ }
+ if (identityInfo.getTrustLevel() == trustLevel) {
+ logger.debug("Not updating trust level for recipient {}, trust level already matches", recipientId);
return false;
}
+ logger.debug("Updating trust level for recipient {} with trust {}", recipientId, trustLevel);
final var newIdentityInfo = new IdentityInfo(recipientId,
identityKey,
trustLevel,
// TODO implement possibility for different handling of incoming/outgoing trust decisions
var identityInfo = loadIdentityLocked(recipientId);
if (identityInfo == null) {
- // Identity not found
+ logger.debug("Initial identity found for {}, saving.", recipientId);
saveIdentity(address, identityKey);
- return trustNewIdentity == TrustNewIdentity.ON_FIRST_USE;
- }
-
- if (!identityInfo.getIdentityKey().equals(identityKey)) {
+ identityInfo = loadIdentityLocked(recipientId);
+ } else if (!identityInfo.getIdentityKey().equals(identityKey)) {
// Identity found, but different
if (direction == Direction.SENDING) {
+ logger.debug("Changed identity found for {}, saving.", recipientId);
saveIdentity(address, identityKey);
identityInfo = loadIdentityLocked(recipientId);
+ } else {
+ logger.trace("Trusting identity for {} for {}: {}", recipientId, direction, false);
+ return false;
}
}
- return identityInfo.isTrusted();
+ final var isTrusted = identityInfo != null && identityInfo.isTrusted();
+ logger.trace("Trusting identity for {} for {}: {}", recipientId, direction, isTrusted);
+ return isTrusted;
}
}
}
private void storeIdentityLocked(final RecipientId recipientId, final IdentityInfo identityInfo) {
+ logger.trace("Storing identity info for {}, trust: {}, added: {}",
+ recipientId,
+ identityInfo.getTrustLevel(),
+ identityInfo.getDateAdded());
cachedIdentities.put(recipientId, identityInfo);
var storage = new IdentityStorage(Base64.getEncoder().encodeToString(identityInfo.getIdentityKey().serialize()),