Adapt log levels

This commit is contained in:
AsamK 2021-12-30 13:30:05 +01:00
parent 592491ab4e
commit a738fb725b
2 changed files with 55 additions and 49 deletions

View file

@ -44,16 +44,68 @@ public class UnidentifiedAccessHelper {
this.profileProvider = profileProvider; this.profileProvider = profileProvider;
} }
public List<Optional<UnidentifiedAccessPair>> getAccessFor(List<RecipientId> recipients) {
return recipients.stream().map(this::getAccessFor).toList();
}
public Optional<UnidentifiedAccessPair> getAccessFor(RecipientId recipient) {
return getAccessFor(recipient, false);
}
public Optional<UnidentifiedAccessPair> getAccessFor(RecipientId recipientId, boolean noRefresh) {
var recipientUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipientId, noRefresh);
if (recipientUnidentifiedAccessKey == null) {
logger.trace("Unidentified access not available for {}", recipientId);
return Optional.absent();
}
var selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(noRefresh);
if (selfUnidentifiedAccessKey == null) {
logger.trace("Unidentified access not available for self");
return Optional.absent();
}
var senderCertificate = getSenderCertificateFor(recipientId);
if (senderCertificate == null) {
logger.trace("Unidentified access not available due to missing sender certificate");
return Optional.absent();
}
try {
return Optional.of(new UnidentifiedAccessPair(new UnidentifiedAccess(recipientUnidentifiedAccessKey,
senderCertificate), new UnidentifiedAccess(selfUnidentifiedAccessKey, senderCertificate)));
} catch (InvalidCertificateException e) {
return Optional.absent();
}
}
public Optional<UnidentifiedAccessPair> getAccessForSync() {
var selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(false);
var selfUnidentifiedAccessCertificate = getSenderCertificate();
if (selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
return Optional.absent();
}
try {
return Optional.of(new UnidentifiedAccessPair(new UnidentifiedAccess(selfUnidentifiedAccessKey,
selfUnidentifiedAccessCertificate),
new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)));
} catch (InvalidCertificateException e) {
return Optional.absent();
}
}
private byte[] getSenderCertificateFor(final RecipientId recipientId) { private byte[] getSenderCertificateFor(final RecipientId recipientId) {
final var sharingMode = account.getConfigurationStore().getPhoneNumberSharingMode(); final var sharingMode = account.getConfigurationStore().getPhoneNumberSharingMode();
if (sharingMode == PhoneNumberSharingMode.EVERYBODY || ( if (sharingMode == PhoneNumberSharingMode.EVERYBODY || (
sharingMode == PhoneNumberSharingMode.CONTACTS sharingMode == PhoneNumberSharingMode.CONTACTS
&& account.getContactStore().getContact(recipientId) != null && account.getContactStore().getContact(recipientId) != null
)) { )) {
logger.debug("Using normal sender certificate for message to {}", recipientId); logger.trace("Using normal sender certificate for message to {}", recipientId);
return getSenderCertificate(); return getSenderCertificate();
} else { } else {
logger.debug("Using phone number privacy sender certificate for message to {}", recipientId); logger.trace("Using phone number privacy sender certificate for message to {}", recipientId);
return getSenderCertificateForPhoneNumberPrivacy(); return getSenderCertificateForPhoneNumberPrivacy();
} }
} }
@ -130,52 +182,6 @@ public class UnidentifiedAccessHelper {
} }
} }
public Optional<UnidentifiedAccessPair> getAccessForSync() {
var selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(false);
var selfUnidentifiedAccessCertificate = getSenderCertificate();
if (selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
return Optional.absent();
}
try {
return Optional.of(new UnidentifiedAccessPair(new UnidentifiedAccess(selfUnidentifiedAccessKey,
selfUnidentifiedAccessCertificate),
new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)));
} catch (InvalidCertificateException e) {
return Optional.absent();
}
}
public List<Optional<UnidentifiedAccessPair>> getAccessFor(List<RecipientId> recipients) {
return recipients.stream().map(this::getAccessFor).toList();
}
public Optional<UnidentifiedAccessPair> getAccessFor(RecipientId recipient) {
return getAccessFor(recipient, false);
}
public Optional<UnidentifiedAccessPair> getAccessFor(RecipientId recipient, boolean noRefresh) {
var recipientUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient, noRefresh);
if (recipientUnidentifiedAccessKey == null) {
return Optional.absent();
}
var selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey(noRefresh);
var selfUnidentifiedAccessCertificate = getSenderCertificateFor(recipient);
if (selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
return Optional.absent();
}
try {
return Optional.of(new UnidentifiedAccessPair(new UnidentifiedAccess(recipientUnidentifiedAccessKey,
selfUnidentifiedAccessCertificate),
new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)));
} catch (InvalidCertificateException e) {
return Optional.absent();
}
}
private static byte[] createUnrestrictedUnidentifiedAccess() { private static byte[] createUnrestrictedUnidentifiedAccess() {
return UNRESTRICTED_KEY; return UNRESTRICTED_KEY;
} }

View file

@ -114,7 +114,7 @@ public class IdentityKeyStore implements org.whispersystems.libsignal.state.Iden
return false; return false;
} }
if (identityInfo.getTrustLevel() == trustLevel) { if (identityInfo.getTrustLevel() == trustLevel) {
logger.debug("Not updating trust level for recipient {}, trust level already matches", recipientId); logger.trace("Not updating trust level for recipient {}, trust level already matches", recipientId);
return false; return false;
} }