Reduce direct use of recipient store

This commit is contained in:
AsamK 2022-05-23 13:18:33 +02:00
parent 995eaa6e7c
commit 3abb641c7c
13 changed files with 101 additions and 74 deletions

View file

@ -168,9 +168,9 @@ class ManagerImpl implements Manager {
logger.trace("Archiving old sessions for {}", recipientId); logger.trace("Archiving old sessions for {}", recipientId);
account.getSessionStore().archiveSessions(recipientId); account.getSessionStore().archiveSessions(recipientId);
account.getSenderKeyStore().deleteSharedWith(recipientId); account.getSenderKeyStore().deleteSharedWith(recipientId);
final var profile = account.getRecipientStore().getProfile(recipientId); final var profile = account.getProfileStore().getProfile(recipientId);
if (profile != null) { if (profile != null) {
account.getRecipientStore() account.getProfileStore()
.storeProfile(recipientId, .storeProfile(recipientId,
Profile.newBuilder(profile) Profile.newBuilder(profile)
.withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN) .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
@ -215,7 +215,8 @@ class ManagerImpl implements Manager {
final var aci = registeredUsers.get(number); final var aci = registeredUsers.get(number);
final var profile = aci == null final var profile = aci == null
? null ? null
: context.getProfileHelper().getRecipientProfile(account.getRecipientStore().resolveRecipient(aci)); : context.getProfileHelper()
.getRecipientProfile(account.getRecipientResolver().resolveRecipient(aci));
return new UserStatus(number.isEmpty() ? null : number, return new UserStatus(number.isEmpty() ? null : number,
aci == null ? null : aci.uuid(), aci == null ? null : aci.uuid(),
profile != null profile != null
@ -356,9 +357,7 @@ class ManagerImpl implements Manager {
return null; return null;
} }
return Group.from(groupInfo, return Group.from(groupInfo, account.getRecipientAddressResolver(), account.getSelfRecipientId());
account.getRecipientStore()::resolveRecipientAddress,
account.getSelfRecipientId());
} }
@Override @Override
@ -459,9 +458,7 @@ class ManagerImpl implements Manager {
} }
private SendMessageResult toSendMessageResult(final org.whispersystems.signalservice.api.messages.SendMessageResult result) { private SendMessageResult toSendMessageResult(final org.whispersystems.signalservice.api.messages.SendMessageResult result) {
return SendMessageResult.from(result, return SendMessageResult.from(result, account.getRecipientResolver(), account.getRecipientAddressResolver());
account.getRecipientStore(),
account.getRecipientStore()::resolveRecipientAddress);
} }
private SendMessageResults sendTypingMessage( private SendMessageResults sendTypingMessage(
@ -683,13 +680,13 @@ class ManagerImpl implements Manager {
@Override @Override
public void deleteRecipient(final RecipientIdentifier.Single recipient) { public void deleteRecipient(final RecipientIdentifier.Single recipient) {
account.removeRecipient(account.getRecipientStore().resolveRecipient(recipient.toPartialRecipientAddress())); account.removeRecipient(account.getRecipientResolver().resolveRecipient(recipient.toPartialRecipientAddress()));
} }
@Override @Override
public void deleteContact(final RecipientIdentifier.Single recipient) { public void deleteContact(final RecipientIdentifier.Single recipient) {
account.getContactStore() account.getContactStore()
.deleteContact(account.getRecipientStore().resolveRecipient(recipient.toPartialRecipientAddress())); .deleteContact(account.getRecipientResolver().resolveRecipient(recipient.toPartialRecipientAddress()));
} }
@Override @Override
@ -1018,7 +1015,8 @@ class ManagerImpl implements Manager {
return null; return null;
} }
final var address = account.getRecipientStore().resolveRecipientAddress(identityInfo.getRecipientId()); final var address = account.getRecipientAddressResolver()
.resolveRecipientAddress(identityInfo.getRecipientId());
final var scannableFingerprint = context.getIdentityHelper() final var scannableFingerprint = context.getIdentityHelper()
.computeSafetyNumberForScanning(identityInfo.getRecipientId(), identityInfo.getIdentityKey()); .computeSafetyNumberForScanning(identityInfo.getRecipientId(), identityInfo.getIdentityKey());
return new Identity(address, return new Identity(address,

View file

@ -86,7 +86,7 @@ public class AccountHelper {
account.setNumber(number); account.setNumber(number);
account.setAci(aci); account.setAci(aci);
account.setPni(pni); account.setPni(pni);
account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress()); account.getRecipientTrustedResolver().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
// TODO check and update remote storage // TODO check and update remote storage
context.getUnidentifiedAccessHelper().rotateSenderCertificates(); context.getUnidentifiedAccessHelper().rotateSenderCertificates();
dependencies.resetAfterAddressChange(); dependencies.resetAfterAddressChange();

View file

@ -153,7 +153,7 @@ public class GroupHelper {
downloadGroupAvatar(groupId, groupSecretParams, avatar); downloadGroupAvatar(groupId, groupSecretParams, avatar);
} }
} }
groupInfoV2.setGroup(group, account.getRecipientStore()); groupInfoV2.setGroup(group, account.getRecipientResolver());
account.getGroupStore().updateGroup(groupInfoV2); account.getGroupStore().updateGroup(groupInfoV2);
} }
@ -183,7 +183,7 @@ public class GroupHelper {
final var gv2 = gv2Pair.first(); final var gv2 = gv2Pair.first();
final var decryptedGroup = gv2Pair.second(); final var decryptedGroup = gv2Pair.second();
gv2.setGroup(decryptedGroup, account.getRecipientStore()); gv2.setGroup(decryptedGroup, account.getRecipientResolver());
if (avatarFile != null) { if (avatarFile != null) {
context.getAvatarStore() context.getAvatarStore()
.storeGroupAvatar(gv2.getGroupId(), .storeGroupAvatar(gv2.getGroupId(),
@ -398,7 +398,7 @@ public class GroupHelper {
downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar); downloadGroupAvatar(groupInfoV2.getGroupId(), groupSecretParams, avatar);
} }
} }
groupInfoV2.setGroup(decryptedGroup, account.getRecipientStore()); groupInfoV2.setGroup(decryptedGroup, account.getRecipientResolver());
account.getGroupStore().updateGroup(group); account.getGroupStore().updateGroup(group);
} }
} }
@ -441,7 +441,7 @@ public class GroupHelper {
private void storeProfileKeysFromMembers(final DecryptedGroup group) { private void storeProfileKeysFromMembers(final DecryptedGroup group) {
for (var member : group.getMembersList()) { for (var member : group.getMembersList()) {
final var serviceId = ServiceId.fromByteString(member.getUuid()); final var serviceId = ServiceId.fromByteString(member.getUuid());
final var recipientId = account.getRecipientStore().resolveRecipient(serviceId); final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
final var profileStore = account.getProfileStore(); final var profileStore = account.getProfileStore();
if (profileStore.getProfileKey(recipientId) != null) { if (profileStore.getProfileKey(recipientId) != null) {
// We already have a profile key, not updating it from a non-authoritative source // We already have a profile key, not updating it from a non-authoritative source
@ -461,7 +461,7 @@ public class GroupHelper {
if (profileKeyFromChange != null) { if (profileKeyFromChange != null) {
final var serviceId = profileKeyFromChange.first(); final var serviceId = profileKeyFromChange.first();
final var profileKey = profileKeyFromChange.second(); final var profileKey = profileKeyFromChange.second();
final var recipientId = account.getRecipientStore().resolveRecipient(serviceId); final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
account.getProfileStore().storeProfileKey(recipientId, profileKey); account.getProfileStore().storeProfileKey(recipientId, profileKey);
} }
} }
@ -487,7 +487,7 @@ public class GroupHelper {
.forEach(p -> { .forEach(p -> {
final var serviceId = p.first(); final var serviceId = p.first();
final var profileKey = p.second(); final var profileKey = p.second();
final var recipientId = account.getRecipientStore().resolveRecipient(serviceId); final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
newProfileKeys.put(recipientId, profileKey); newProfileKeys.put(recipientId, profileKey);
}); });
if (!page.getPagingData().hasMorePages()) { if (!page.getPagingData().hasMorePages()) {
@ -729,7 +729,7 @@ public class GroupHelper {
throw new LastGroupAdminException(groupInfoV2.getGroupId(), groupInfoV2.getTitle()); throw new LastGroupAdminException(groupInfoV2.getGroupId(), groupInfoV2.getTitle());
} }
final var groupGroupChangePair = context.getGroupV2Helper().leaveGroup(groupInfoV2, newAdmins); final var groupGroupChangePair = context.getGroupV2Helper().leaveGroup(groupInfoV2, newAdmins);
groupInfoV2.setGroup(groupGroupChangePair.first(), account.getRecipientStore()); groupInfoV2.setGroup(groupGroupChangePair.first(), account.getRecipientResolver());
account.getGroupStore().updateGroup(groupInfoV2); account.getGroupStore().updateGroup(groupInfoV2);
var messageBuilder = getGroupUpdateMessageBuilder(groupInfoV2, groupGroupChangePair.second().toByteArray()); var messageBuilder = getGroupUpdateMessageBuilder(groupInfoV2, groupGroupChangePair.second().toByteArray());
@ -773,7 +773,7 @@ public class GroupHelper {
) throws IOException { ) throws IOException {
final var selfRecipientId = account.getSelfRecipientId(); final var selfRecipientId = account.getSelfRecipientId();
final var members = group.getMembersIncludingPendingWithout(selfRecipientId); final var members = group.getMembersIncludingPendingWithout(selfRecipientId);
group.setGroup(newDecryptedGroup, account.getRecipientStore()); group.setGroup(newDecryptedGroup, account.getRecipientResolver());
members.addAll(group.getMembersIncludingPendingWithout(selfRecipientId)); members.addAll(group.getMembersIncludingPendingWithout(selfRecipientId));
account.getGroupStore().updateGroup(group); account.getGroupStore().updateGroup(group);
@ -792,8 +792,8 @@ public class GroupHelper {
return new SendGroupMessageResults(timestamp, return new SendGroupMessageResults(timestamp,
results.stream() results.stream()
.map(sendMessageResult -> SendMessageResult.from(sendMessageResult, .map(sendMessageResult -> SendMessageResult.from(sendMessageResult,
account.getRecipientStore(), account.getRecipientResolver(),
account.getRecipientStore()::resolveRecipientAddress)) account.getRecipientAddressResolver()))
.toList()); .toList());
} }
} }

View file

@ -89,8 +89,8 @@ public final class IncomingMessageHandler {
try { try {
content = dependencies.getCipher().decrypt(envelope); content = dependencies.getCipher().decrypt(envelope);
} catch (ProtocolUntrustedIdentityException e) { } catch (ProtocolUntrustedIdentityException e) {
final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender()); final var recipientId = account.getRecipientResolver().resolveRecipient(e.getSender());
final var exception = new UntrustedIdentityException(account.getRecipientStore() final var exception = new UntrustedIdentityException(account.getRecipientAddressResolver()
.resolveRecipientAddress(recipientId), e.getSenderDevice()); .resolveRecipientAddress(recipientId), e.getSenderDevice());
return new Pair<>(List.of(), exception); return new Pair<>(List.of(), exception);
} catch (Exception e) { } catch (Exception e) {
@ -112,7 +112,7 @@ public final class IncomingMessageHandler {
if (envelope.hasSourceUuid()) { if (envelope.hasSourceUuid()) {
// Store uuid if we don't have it already // Store uuid if we don't have it already
// address/uuid in envelope is sent by server // address/uuid in envelope is sent by server
account.getRecipientStore().resolveRecipientTrusted(envelope.getSourceAddress()); account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
} }
SignalServiceContent content = null; SignalServiceContent content = null;
Exception exception = null; Exception exception = null;
@ -120,14 +120,14 @@ public final class IncomingMessageHandler {
try { try {
content = dependencies.getCipher().decrypt(envelope); content = dependencies.getCipher().decrypt(envelope);
} catch (ProtocolUntrustedIdentityException e) { } catch (ProtocolUntrustedIdentityException e) {
final var recipientId = account.getRecipientStore().resolveRecipient(e.getSender()); final var recipientId = account.getRecipientResolver().resolveRecipient(e.getSender());
actions.add(new RetrieveProfileAction(recipientId)); actions.add(new RetrieveProfileAction(recipientId));
exception = new UntrustedIdentityException(account.getRecipientStore() exception = new UntrustedIdentityException(account.getRecipientAddressResolver()
.resolveRecipientAddress(recipientId), e.getSenderDevice()); .resolveRecipientAddress(recipientId), e.getSenderDevice());
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException | } catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolNoSessionException |
ProtocolInvalidMessageException e) { ProtocolInvalidMessageException e) {
logger.debug("Failed to decrypt incoming message", e); logger.debug("Failed to decrypt incoming message", e);
final var sender = account.getRecipientStore().resolveRecipient(e.getSender()); final var sender = account.getRecipientResolver().resolveRecipient(e.getSender());
if (context.getContactHelper().isContactBlocked(sender)) { if (context.getContactHelper().isContactBlocked(sender)) {
logger.debug("Received invalid message from blocked contact, ignoring."); logger.debug("Received invalid message from blocked contact, ignoring.");
} else { } else {
@ -169,7 +169,7 @@ public final class IncomingMessageHandler {
if (!envelope.hasSourceUuid() && content != null) { if (!envelope.hasSourceUuid() && content != null) {
// Store uuid if we don't have it already // Store uuid if we don't have it already
// address/uuid is validated by unidentified sender certificate // address/uuid is validated by unidentified sender certificate
account.getRecipientStore().resolveRecipientTrusted(content.getSender()); account.getRecipientTrustedResolver().resolveRecipientTrusted(content.getSender());
} }
if (envelope.isReceipt()) { if (envelope.isReceipt()) {
final var senderPair = getSender(envelope, content); final var senderPair = getSender(envelope, content);
@ -195,8 +195,8 @@ public final class IncomingMessageHandler {
} }
handler.handleMessage(MessageEnvelope.from(envelope, handler.handleMessage(MessageEnvelope.from(envelope,
content, content,
account.getRecipientStore(), account.getRecipientResolver(),
account.getRecipientStore()::resolveRecipientAddress, account.getRecipientAddressResolver(),
context.getAttachmentHelper()::getAttachmentFile, context.getAttachmentHelper()::getAttachmentFile,
exception), exception); exception), exception);
return actions; return actions;
@ -391,7 +391,7 @@ public final class IncomingMessageHandler {
if (syncMessage.getVerified().isPresent()) { if (syncMessage.getVerified().isPresent()) {
final var verifiedMessage = syncMessage.getVerified().get(); final var verifiedMessage = syncMessage.getVerified().get();
account.getIdentityKeyStore() account.getIdentityKeyStore()
.setIdentityTrustLevel(account.getRecipientStore() .setIdentityTrustLevel(account.getRecipientTrustedResolver()
.resolveRecipientTrusted(verifiedMessage.getDestination()), .resolveRecipientTrusted(verifiedMessage.getDestination()),
verifiedMessage.getIdentityKey(), verifiedMessage.getIdentityKey(),
TrustLevel.fromVerifiedState(verifiedMessage.getVerified())); TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));

View file

@ -289,7 +289,7 @@ public final class ProfileHelper {
var profile = account.getProfileStore().getProfile(recipientId); var profile = account.getProfileStore().getProfile(recipientId);
if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) { if (profile == null || !Objects.equals(avatarPath, profile.getAvatarUrlPath())) {
logger.trace("Downloading profile avatar for {}", recipientId); logger.trace("Downloading profile avatar for {}", recipientId);
downloadProfileAvatar(account.getRecipientStore().resolveRecipientAddress(recipientId), downloadProfileAvatar(account.getRecipientAddressResolver().resolveRecipientAddress(recipientId),
avatarPath, avatarPath,
profileKey); profileKey);
var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile); var builder = profile == null ? Profile.newBuilder() : Profile.newBuilder(profile);

View file

@ -141,7 +141,7 @@ public class ReceiveHelper {
isWaitingForMessage = true; isWaitingForMessage = true;
var result = signalWebSocket.readOrEmpty(timeout.toMillis(), envelope1 -> { var result = signalWebSocket.readOrEmpty(timeout.toMillis(), envelope1 -> {
isWaitingForMessage = false; isWaitingForMessage = false;
final var recipientId = envelope1.hasSourceUuid() ? account.getRecipientStore() final var recipientId = envelope1.hasSourceUuid() ? account.getRecipientResolver()
.resolveRecipient(envelope1.getSourceAddress()) : null; .resolveRecipient(envelope1.getSourceAddress()) : null;
logger.trace("Storing new message from {}", recipientId); logger.trace("Storing new message from {}", recipientId);
// store message on disk, before acknowledging receipt to the server // store message on disk, before acknowledging receipt to the server
@ -211,7 +211,7 @@ public class ReceiveHelper {
if (exception instanceof UntrustedIdentityException) { if (exception instanceof UntrustedIdentityException) {
logger.debug("Keeping message with untrusted identity in message cache"); logger.debug("Keeping message with untrusted identity in message cache");
final var address = ((UntrustedIdentityException) exception).getSender(); final var address = ((UntrustedIdentityException) exception).getSender();
final var recipientId = account.getRecipientStore().resolveRecipient(address); final var recipientId = account.getRecipientResolver().resolveRecipient(address);
if (!envelope.hasSourceUuid()) { if (!envelope.hasSourceUuid()) {
try { try {
cachedMessage[0] = account.getMessageCache().replaceSender(cachedMessage[0], recipientId); cachedMessage[0] = account.getMessageCache().replaceSender(cachedMessage[0], recipientId);
@ -260,7 +260,7 @@ public class ReceiveHelper {
} }
if (!envelope.hasSourceUuid()) { if (!envelope.hasSourceUuid()) {
final var identifier = ((UntrustedIdentityException) exception).getSender(); final var identifier = ((UntrustedIdentityException) exception).getSender();
final var recipientId = account.getRecipientStore().resolveRecipient(identifier); final var recipientId = account.getRecipientResolver().resolveRecipient(identifier);
try { try {
account.getMessageCache().replaceSender(cachedMessage, recipientId); account.getMessageCache().replaceSender(cachedMessage, recipientId);
} catch (IOException ioException) { } catch (IOException ioException) {

View file

@ -40,7 +40,7 @@ public class RecipientHelper {
} }
public SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId) { public SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId) {
final var address = account.getRecipientStore().resolveRecipientAddress(recipientId); final var address = account.getRecipientAddressResolver().resolveRecipientAddress(recipientId);
if (address.number().isEmpty() || address.uuid().isPresent()) { if (address.number().isEmpty() || address.uuid().isPresent()) {
return address.toSignalServiceAddress(); return address.toSignalServiceAddress();
} }
@ -60,13 +60,13 @@ public class RecipientHelper {
// Return SignalServiceAddress with unknown UUID // Return SignalServiceAddress with unknown UUID
return address.toSignalServiceAddress(); return address.toSignalServiceAddress();
} }
return account.getRecipientStore() return account.getRecipientAddressResolver()
.resolveRecipientAddress(account.getRecipientStore().resolveRecipient(aci)) .resolveRecipientAddress(account.getRecipientResolver().resolveRecipient(aci))
.toSignalServiceAddress(); .toSignalServiceAddress();
} }
public RecipientId resolveRecipient(final SignalServiceAddress address) { public RecipientId resolveRecipient(final SignalServiceAddress address) {
return account.getRecipientStore().resolveRecipient(address); return account.getRecipientResolver().resolveRecipient(address);
} }
public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException { public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws UnregisteredRecipientException {
@ -80,7 +80,7 @@ public class RecipientHelper {
public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException { public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) { if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) {
return account.getRecipientStore().resolveRecipient(ServiceId.from(uuidRecipient.uuid())); return account.getRecipientResolver().resolveRecipient(ServiceId.from(uuidRecipient.uuid()));
} else { } else {
final var number = ((RecipientIdentifier.Number) recipient).number(); final var number = ((RecipientIdentifier.Number) recipient).number();
return account.getRecipientStore().resolveRecipient(number, () -> { return account.getRecipientStore().resolveRecipient(number, () -> {
@ -100,7 +100,7 @@ public class RecipientHelper {
} }
final var number = address.getNumber().get(); final var number = address.getNumber().get();
final var uuid = getRegisteredUser(number); final var uuid = getRegisteredUser(number);
return account.getRecipientStore().resolveRecipientTrusted(new SignalServiceAddress(uuid, number)); return account.getRecipientTrustedResolver().resolveRecipientTrusted(new SignalServiceAddress(uuid, number));
} }
public Map<String, ACI> getRegisteredUsers(final Set<String> numbers) throws IOException { public Map<String, ACI> getRegisteredUsers(final Set<String> numbers) throws IOException {
@ -116,7 +116,7 @@ public class RecipientHelper {
} }
// Store numbers as recipients, so we have the number/uuid association // Store numbers as recipients, so we have the number/uuid association
registeredUsers.forEach((number, aci) -> account.getRecipientStore() registeredUsers.forEach((number, aci) -> account.getRecipientTrustedResolver()
.resolveRecipientTrusted(new SignalServiceAddress(aci, number))); .resolveRecipientTrusted(new SignalServiceAddress(aci, number)));
return registeredUsers; return registeredUsers;

View file

@ -656,12 +656,12 @@ public class SendHelper {
private void handleSendMessageResult(final SendMessageResult r) { private void handleSendMessageResult(final SendMessageResult r) {
if (r.isSuccess() && !r.getSuccess().isUnidentified()) { if (r.isSuccess() && !r.getSuccess().isUnidentified()) {
final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress()); final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
final var profile = account.getRecipientStore().getProfile(recipientId); final var profile = account.getProfileStore().getProfile(recipientId);
if (profile != null && ( if (profile != null && (
profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
|| profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED || profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED
)) { )) {
account.getRecipientStore() account.getProfileStore()
.storeProfile(recipientId, .storeProfile(recipientId,
Profile.newBuilder(profile) Profile.newBuilder(profile)
.withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN) .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
@ -670,12 +670,12 @@ public class SendHelper {
} }
if (r.isUnregisteredFailure()) { if (r.isUnregisteredFailure()) {
final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress()); final var recipientId = context.getRecipientHelper().resolveRecipient(r.getAddress());
final var profile = account.getRecipientStore().getProfile(recipientId); final var profile = account.getProfileStore().getProfile(recipientId);
if (profile != null && ( if (profile != null && (
profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.ENABLED
|| profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED || profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED
)) { )) {
account.getRecipientStore() account.getProfileStore()
.storeProfile(recipientId, .storeProfile(recipientId,
Profile.newBuilder(profile) Profile.newBuilder(profile)
.withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN) .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)

View file

@ -86,7 +86,7 @@ public class StorageHelper {
final var contactRecord = record.getContact().get(); final var contactRecord = record.getContact().get();
final var address = contactRecord.getAddress(); final var address = contactRecord.getAddress();
final var recipientId = account.getRecipientStore().resolveRecipient(address); final var recipientId = account.getRecipientResolver().resolveRecipient(address);
final var contact = account.getContactStore().getContact(recipientId); final var contact = account.getContactStore().getContact(recipientId);
final var blocked = contact != null && contact.isBlocked(); final var blocked = contact != null && contact.isBlocked();
final var profileShared = contact != null && contact.isProfileSharingEnabled(); final var profileShared = contact != null && contact.isProfileSharingEnabled();

View file

@ -257,7 +257,7 @@ public class SyncHelper {
if (c.getAddress().matches(account.getSelfAddress()) && c.getProfileKey().isPresent()) { if (c.getAddress().matches(account.getSelfAddress()) && c.getProfileKey().isPresent()) {
account.setProfileKey(c.getProfileKey().get()); account.setProfileKey(c.getProfileKey().get());
} }
final var recipientId = account.getRecipientStore().resolveRecipientTrusted(c.getAddress()); final var recipientId = account.getRecipientTrustedResolver().resolveRecipientTrusted(c.getAddress());
var contact = account.getContactStore().getContact(recipientId); var contact = account.getContactStore().getContact(recipientId);
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact); final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
if (c.getName().isPresent()) { if (c.getName().isPresent()) {
@ -272,7 +272,7 @@ public class SyncHelper {
if (c.getVerified().isPresent()) { if (c.getVerified().isPresent()) {
final var verifiedMessage = c.getVerified().get(); final var verifiedMessage = c.getVerified().get();
account.getIdentityKeyStore() account.getIdentityKeyStore()
.setIdentityTrustLevel(account.getRecipientStore() .setIdentityTrustLevel(account.getRecipientTrustedResolver()
.resolveRecipientTrusted(verifiedMessage.getDestination()), .resolveRecipientTrusted(verifiedMessage.getDestination()),
verifiedMessage.getIdentityKey(), verifiedMessage.getIdentityKey(),
TrustLevel.fromVerifiedState(verifiedMessage.getVerified())); TrustLevel.fromVerifiedState(verifiedMessage.getVerified()));

View file

@ -7,6 +7,7 @@ import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.TrustLevel; import org.asamk.signal.manager.api.TrustLevel;
import org.asamk.signal.manager.config.ServiceEnvironment; import org.asamk.signal.manager.config.ServiceEnvironment;
import org.asamk.signal.manager.groups.GroupId; import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.helper.RecipientAddressResolver;
import org.asamk.signal.manager.storage.configuration.ConfigurationStore; import org.asamk.signal.manager.storage.configuration.ConfigurationStore;
import org.asamk.signal.manager.storage.contacts.ContactsStore; import org.asamk.signal.manager.storage.contacts.ContactsStore;
import org.asamk.signal.manager.storage.contacts.LegacyJsonContactsStore; import org.asamk.signal.manager.storage.contacts.LegacyJsonContactsStore;
@ -27,7 +28,9 @@ import org.asamk.signal.manager.storage.recipients.LegacyRecipientStore;
import org.asamk.signal.manager.storage.recipients.Profile; import org.asamk.signal.manager.storage.recipients.Profile;
import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.manager.storage.recipients.RecipientResolver;
import org.asamk.signal.manager.storage.recipients.RecipientStore; import org.asamk.signal.manager.storage.recipients.RecipientStore;
import org.asamk.signal.manager.storage.recipients.RecipientTrustedResolver;
import org.asamk.signal.manager.storage.sendLog.MessageSendLogStore; import org.asamk.signal.manager.storage.sendLog.MessageSendLogStore;
import org.asamk.signal.manager.storage.senderKeys.SenderKeyStore; import org.asamk.signal.manager.storage.senderKeys.SenderKeyStore;
import org.asamk.signal.manager.storage.sessions.SessionStore; import org.asamk.signal.manager.storage.sessions.SessionStore;
@ -201,7 +204,7 @@ public class SignalAccount implements Closeable {
signalAccount.localRegistrationId = registrationId; signalAccount.localRegistrationId = registrationId;
signalAccount.trustNewIdentity = trustNewIdentity; signalAccount.trustNewIdentity = trustNewIdentity;
signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath), signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
signalAccount.getRecipientStore(), signalAccount.getRecipientResolver(),
signalAccount::saveGroupStore); signalAccount::saveGroupStore);
signalAccount.stickerStore = new StickerStore(signalAccount::saveStickerStore); signalAccount.stickerStore = new StickerStore(signalAccount::saveStickerStore);
signalAccount.configurationStore = new ConfigurationStore(signalAccount::saveConfigurationStore); signalAccount.configurationStore = new ConfigurationStore(signalAccount::saveConfigurationStore);
@ -260,7 +263,8 @@ public class SignalAccount implements Closeable {
aciIdentityKey, aciIdentityKey,
pniIdentityKey, pniIdentityKey,
profileKey); profileKey);
signalAccount.getRecipientStore().resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress()); signalAccount.getRecipientTrustedResolver()
.resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
signalAccount.getSessionStore().archiveAllSessions(); signalAccount.getSessionStore().archiveAllSessions();
signalAccount.getSenderKeyStore().deleteAll(); signalAccount.getSenderKeyStore().deleteAll();
signalAccount.clearAllPreKeys(); signalAccount.clearAllPreKeys();
@ -321,12 +325,13 @@ public class SignalAccount implements Closeable {
signalAccount.localRegistrationId = registrationId; signalAccount.localRegistrationId = registrationId;
signalAccount.trustNewIdentity = trustNewIdentity; signalAccount.trustNewIdentity = trustNewIdentity;
signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath), signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
signalAccount.getRecipientStore(), signalAccount.getRecipientResolver(),
signalAccount::saveGroupStore); signalAccount::saveGroupStore);
signalAccount.stickerStore = new StickerStore(signalAccount::saveStickerStore); signalAccount.stickerStore = new StickerStore(signalAccount::saveStickerStore);
signalAccount.configurationStore = new ConfigurationStore(signalAccount::saveConfigurationStore); signalAccount.configurationStore = new ConfigurationStore(signalAccount::saveConfigurationStore);
signalAccount.getRecipientStore().resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress()); signalAccount.getRecipientTrustedResolver()
.resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
signalAccount.previousStorageVersion = CURRENT_STORAGE_VERSION; signalAccount.previousStorageVersion = CURRENT_STORAGE_VERSION;
signalAccount.migrateLegacyConfigs(); signalAccount.migrateLegacyConfigs();
signalAccount.clearAllPreKeys(); signalAccount.clearAllPreKeys();
@ -608,11 +613,11 @@ public class SignalAccount implements Closeable {
groupStoreStorage = jsonProcessor.convertValue(rootNode.get("groupStore"), GroupStore.Storage.class); groupStoreStorage = jsonProcessor.convertValue(rootNode.get("groupStore"), GroupStore.Storage.class);
groupStore = GroupStore.fromStorage(groupStoreStorage, groupStore = GroupStore.fromStorage(groupStoreStorage,
getGroupCachePath(dataPath, accountPath), getGroupCachePath(dataPath, accountPath),
getRecipientStore(), getRecipientResolver(),
this::saveGroupStore); this::saveGroupStore);
} else { } else {
groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath), groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
getRecipientStore(), getRecipientResolver(),
this::saveGroupStore); this::saveGroupStore);
} }
@ -650,7 +655,7 @@ public class SignalAccount implements Closeable {
if (legacyRecipientStore != null) { if (legacyRecipientStore != null) {
getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses()); getRecipientStore().resolveRecipientsTrusted(legacyRecipientStore.getAddresses());
} }
getRecipientStore().resolveSelfRecipientTrusted(getSelfRecipientAddress()); getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
migrated = true; migrated = true;
} }
@ -710,7 +715,7 @@ public class SignalAccount implements Closeable {
final var contactStore = jsonProcessor.convertValue(contactStoreNode, LegacyJsonContactsStore.class); final var contactStore = jsonProcessor.convertValue(contactStoreNode, LegacyJsonContactsStore.class);
for (var contact : contactStore.getContacts()) { for (var contact : contactStore.getContacts()) {
final var recipientId = getRecipientStore().resolveRecipientTrusted(contact.getAddress()); final var recipientId = getRecipientStore().resolveRecipientTrusted(contact.getAddress());
getRecipientStore().storeContact(recipientId, getContactStore().storeContact(recipientId,
new Contact(contact.name, new Contact(contact.name,
contact.color, contact.color,
contact.messageExpirationTime, contact.messageExpirationTime,
@ -738,9 +743,9 @@ public class SignalAccount implements Closeable {
var profileStoreNode = rootNode.get("profileStore"); var profileStoreNode = rootNode.get("profileStore");
final var legacyProfileStore = jsonProcessor.convertValue(profileStoreNode, LegacyProfileStore.class); final var legacyProfileStore = jsonProcessor.convertValue(profileStoreNode, LegacyProfileStore.class);
for (var profileEntry : legacyProfileStore.getProfileEntries()) { for (var profileEntry : legacyProfileStore.getProfileEntries()) {
var recipientId = getRecipientStore().resolveRecipient(profileEntry.getAddress()); var recipientId = getRecipientResolver().resolveRecipient(profileEntry.getAddress());
getRecipientStore().storeProfileKeyCredential(recipientId, profileEntry.getProfileKeyCredential()); getProfileStore().storeProfileKeyCredential(recipientId, profileEntry.getProfileKeyCredential());
getRecipientStore().storeProfileKey(recipientId, profileEntry.getProfileKey()); getProfileStore().storeProfileKey(recipientId, profileEntry.getProfileKey());
final var profile = profileEntry.getProfile(); final var profile = profileEntry.getProfile();
if (profile != null) { if (profile != null) {
final var capabilities = new HashSet<Profile.Capability>(); final var capabilities = new HashSet<Profile.Capability>();
@ -765,7 +770,7 @@ public class SignalAccount implements Closeable {
? Profile.UnidentifiedAccessMode.ENABLED ? Profile.UnidentifiedAccessMode.ENABLED
: Profile.UnidentifiedAccessMode.DISABLED, : Profile.UnidentifiedAccessMode.DISABLED,
capabilities); capabilities);
getRecipientStore().storeProfile(recipientId, newProfile); getProfileStore().storeProfile(recipientId, newProfile);
} }
} }
} }
@ -784,10 +789,10 @@ public class SignalAccount implements Closeable {
} }
try { try {
if (UuidUtil.isUuid(thread.id) || thread.id.startsWith("+")) { if (UuidUtil.isUuid(thread.id) || thread.id.startsWith("+")) {
final var recipientId = getRecipientStore().resolveRecipient(thread.id); final var recipientId = getRecipientResolver().resolveRecipient(thread.id);
var contact = getRecipientStore().getContact(recipientId); var contact = getContactStore().getContact(recipientId);
if (contact != null) { if (contact != null) {
getRecipientStore().storeContact(recipientId, getContactStore().storeContact(recipientId,
Contact.newBuilder(contact) Contact.newBuilder(contact)
.withMessageExpirationTime(thread.messageExpirationTime) .withMessageExpirationTime(thread.messageExpirationTime)
.build()); .build());
@ -1028,13 +1033,13 @@ public class SignalAccount implements Closeable {
public SessionStore getSessionStore() { public SessionStore getSessionStore() {
return getOrCreate(() -> sessionStore, return getOrCreate(() -> sessionStore,
() -> sessionStore = new SessionStore(getSessionsPath(dataPath, accountPath), getRecipientStore())); () -> sessionStore = new SessionStore(getSessionsPath(dataPath, accountPath), getRecipientResolver()));
} }
public IdentityKeyStore getIdentityKeyStore() { public IdentityKeyStore getIdentityKeyStore() {
return getOrCreate(() -> identityKeyStore, return getOrCreate(() -> identityKeyStore,
() -> identityKeyStore = new IdentityKeyStore(getIdentitiesPath(dataPath, accountPath), () -> identityKeyStore = new IdentityKeyStore(getIdentitiesPath(dataPath, accountPath),
getRecipientStore(), getRecipientResolver(),
aciIdentityKeyPair, aciIdentityKeyPair,
localRegistrationId, localRegistrationId,
trustNewIdentity)); trustNewIdentity));
@ -1048,6 +1053,18 @@ public class SignalAccount implements Closeable {
return getRecipientStore(); return getRecipientStore();
} }
public RecipientResolver getRecipientResolver() {
return getRecipientStore();
}
public RecipientTrustedResolver getRecipientTrustedResolver() {
return getRecipientStore();
}
public RecipientAddressResolver getRecipientAddressResolver() {
return getRecipientStore()::resolveRecipientAddress;
}
public RecipientStore getRecipientStore() { public RecipientStore getRecipientStore() {
return getOrCreate(() -> recipientStore, return getOrCreate(() -> recipientStore,
() -> recipientStore = RecipientStore.load(getRecipientsStoreFile(dataPath, accountPath), () -> recipientStore = RecipientStore.load(getRecipientsStoreFile(dataPath, accountPath),
@ -1067,8 +1084,8 @@ public class SignalAccount implements Closeable {
return getOrCreate(() -> senderKeyStore, return getOrCreate(() -> senderKeyStore,
() -> senderKeyStore = new SenderKeyStore(getSharedSenderKeysFile(dataPath, accountPath), () -> senderKeyStore = new SenderKeyStore(getSharedSenderKeysFile(dataPath, accountPath),
getSenderKeysPath(dataPath, accountPath), getSenderKeysPath(dataPath, accountPath),
getRecipientStore()::resolveRecipientAddress, getRecipientAddressResolver(),
getRecipientStore())); getRecipientResolver()));
} }
public ConfigurationStore getConfigurationStore() { public ConfigurationStore getConfigurationStore() {
@ -1092,7 +1109,7 @@ public class SignalAccount implements Closeable {
public MessageSendLogStore getMessageSendLogStore() { public MessageSendLogStore getMessageSendLogStore() {
return getOrCreate(() -> messageSendLogStore, return getOrCreate(() -> messageSendLogStore,
() -> messageSendLogStore = new MessageSendLogStore(getRecipientStore(), getAccountDatabase())); () -> messageSendLogStore = new MessageSendLogStore(getRecipientResolver(), getAccountDatabase()));
} }
public CredentialsProvider getCredentialsProvider() { public CredentialsProvider getCredentialsProvider() {
@ -1169,7 +1186,7 @@ public class SignalAccount implements Closeable {
} }
public RecipientId getSelfRecipientId() { public RecipientId getSelfRecipientId() {
return getRecipientStore().resolveRecipient(getSelfRecipientAddress()); return getRecipientResolver().resolveRecipient(getSelfRecipientAddress());
} }
public byte[] getEncryptedDeviceName() { public byte[] getEncryptedDeviceName() {
@ -1337,7 +1354,7 @@ public class SignalAccount implements Closeable {
clearAllPreKeys(); clearAllPreKeys();
getSessionStore().archiveAllSessions(); getSessionStore().archiveAllSessions();
getSenderKeyStore().deleteAll(); getSenderKeyStore().deleteAll();
final var recipientId = getRecipientStore().resolveSelfRecipientTrusted(getSelfRecipientAddress()); final var recipientId = getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
final var publicKey = getAciIdentityKeyPair().getPublicKey(); final var publicKey = getAciIdentityKeyPair().getPublicKey();
getIdentityKeyStore().saveIdentity(recipientId, publicKey, new Date()); getIdentityKeyStore().saveIdentity(recipientId, publicKey, new Date());
getIdentityKeyStore().setIdentityTrustLevel(recipientId, publicKey, TrustLevel.TRUSTED_VERIFIED); getIdentityKeyStore().setIdentityTrustLevel(recipientId, publicKey, TrustLevel.TRUSTED_VERIFIED);

View file

@ -37,7 +37,7 @@ import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class RecipientStore implements RecipientResolver, ContactsStore, ProfileStore { public class RecipientStore implements RecipientResolver, RecipientTrustedResolver, ContactsStore, ProfileStore {
private final static Logger logger = LoggerFactory.getLogger(RecipientStore.class); private final static Logger logger = LoggerFactory.getLogger(RecipientStore.class);
@ -224,6 +224,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
return resolveRecipient(new RecipientAddress(address), false, false); return resolveRecipient(new RecipientAddress(address), false, false);
} }
@Override
public RecipientId resolveSelfRecipientTrusted(RecipientAddress address) { public RecipientId resolveSelfRecipientTrusted(RecipientAddress address) {
return resolveRecipient(address, true, true); return resolveRecipient(address, true, true);
} }
@ -232,6 +233,7 @@ public class RecipientStore implements RecipientResolver, ContactsStore, Profile
return resolveRecipient(address, true, false); return resolveRecipient(address, true, false);
} }
@Override
public RecipientId resolveRecipientTrusted(SignalServiceAddress address) { public RecipientId resolveRecipientTrusted(SignalServiceAddress address) {
return resolveRecipient(new RecipientAddress(address), true, false); return resolveRecipient(new RecipientAddress(address), true, false);
} }

View file

@ -0,0 +1,10 @@
package org.asamk.signal.manager.storage.recipients;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
public interface RecipientTrustedResolver {
RecipientId resolveSelfRecipientTrusted(RecipientAddress address);
RecipientId resolveRecipientTrusted(SignalServiceAddress address);
}