final var senderPair = getSender(envelope, content);
final var sender = senderPair.first();
final var senderDeviceId = senderPair.second();
+ final var destination = getDestination(envelope);
if (content.getReceiptMessage().isPresent()) {
final var message = content.getReceiptMessage().get();
actions.addAll(handleSignalServiceDataMessage(message,
false,
sender,
- account.getSelfRecipientId(),
+ destination,
receiveConfig.ignoreAttachments()));
}
}
if (message.getRatchetKey().isPresent()) {
- if (account.getSessionStore().isCurrentRatchetKey(sender, senderDeviceId, message.getRatchetKey().get())) {
+ if (account.getAciSessionStore()
+ .isCurrentRatchetKey(sender, senderDeviceId, message.getRatchetKey().get())) {
if (logEntries.isEmpty()) {
logger.debug("Renewing the session with sender");
actions.add(new RenewSessionAction(sender));
} else {
logger.trace("Archiving the session with sender, a resend message has already been queued");
- context.getAccount().getSessionStore().archiveSessions(sender);
+ context.getAccount().getAciSessionStore().archiveSessions(sender);
}
}
return;
final var conversationPartnerAddress = isSync ? destination : source;
if (conversationPartnerAddress != null && message.isEndSession()) {
- account.getSessionStore().deleteAllSessions(conversationPartnerAddress);
+ account.getAciSessionStore().deleteAllSessions(conversationPartnerAddress);
}
if (message.isExpirationUpdate() || message.getBody().isPresent()) {
if (message.getGroupContext().isPresent()) {
content.getSenderDevice());
}
}
+
+ private RecipientId getDestination(SignalServiceEnvelope envelope) {
+ if (!envelope.hasDestinationUuid()) {
+ return account.getSelfRecipientId();
+ }
+ final var addressOptional = SignalServiceAddress.fromRaw(envelope.getDestinationUuid(), null);
+ if (addressOptional.isEmpty()) {
+ return account.getSelfRecipientId();
+ }
+ return context.getRecipientHelper().resolveRecipient(addressOptional.get());
+ }
}
private boolean registered = false;
- private SignalProtocolStore signalProtocolStore;
+ private SignalProtocolStore aciSignalProtocolStore;
+ private SignalProtocolStore pniSignalProtocolStore;
private PreKeyStore aciPreKeyStore;
private SignedPreKeyStore aciSignedPreKeyStore;
private PreKeyStore pniPreKeyStore;
private SignedPreKeyStore pniSignedPreKeyStore;
- private SessionStore sessionStore;
+ private SessionStore aciSessionStore;
+ private SessionStore pniSessionStore;
private IdentityKeyStore identityKeyStore;
private SignalIdentityKeyStore aciIdentityKeyStore;
+ private SignalIdentityKeyStore pniIdentityKeyStore;
private SenderKeyStore senderKeyStore;
private GroupStore groupStore;
private RecipientStore recipientStore;
profileKey);
signalAccount.getRecipientTrustedResolver()
.resolveSelfRecipientTrusted(signalAccount.getSelfRecipientAddress());
- signalAccount.getSessionStore().archiveAllSessions();
+ signalAccount.getAciSessionStore().archiveAllSessions();
+ signalAccount.getPniSessionStore().archiveAllSessions();
signalAccount.getSenderKeyStore().deleteAll();
signalAccount.clearAllPreKeys();
return signalAccount;
}
private void mergeRecipients(RecipientId recipientId, RecipientId toBeMergedRecipientId) {
- getSessionStore().mergeRecipients(recipientId, toBeMergedRecipientId);
+ getAciSessionStore().mergeRecipients(recipientId, toBeMergedRecipientId);
+ getPniSessionStore().mergeRecipients(recipientId, toBeMergedRecipientId);
getIdentityKeyStore().mergeRecipients(recipientId, toBeMergedRecipientId);
getMessageCache().mergeRecipients(recipientId, toBeMergedRecipientId);
getGroupStore().mergeRecipients(recipientId, toBeMergedRecipientId);
}
public void removeRecipient(final RecipientId recipientId) {
- getSessionStore().deleteAllSessions(recipientId);
+ getAciSessionStore().deleteAllSessions(recipientId);
+ getPniSessionStore().deleteAllSessions(recipientId);
getIdentityKeyStore().deleteIdentity(recipientId);
getMessageCache().deleteMessages(recipientId);
getSenderKeyStore().deleteAll(recipientId);
}
final var legacySessionsPath = getSessionsPath(dataPath, accountPath);
if (legacySessionsPath.exists()) {
- LegacySessionStore.migrate(legacySessionsPath, getRecipientResolver(), getSessionStore());
+ LegacySessionStore.migrate(legacySessionsPath, getRecipientResolver(), getAciSessionStore());
migratedLegacyConfig = true;
}
final var legacySignalProtocolStore = rootNode.hasNonNull("axolotlStore")
logger.debug("Migrating legacy session store.");
for (var session : legacySignalProtocolStore.getLegacySessionStore().getSessions()) {
try {
- getSessionStore().storeSession(new SignalProtocolAddress(session.address.getIdentifier(),
+ getAciSessionStore().storeSession(new SignalProtocolAddress(session.address.getIdentifier(),
session.deviceId), new SessionRecord(session.sessionRecord));
} catch (Exception e) {
logger.warn("Failed to migrate session, ignoring", e);
@Override
public SignalServiceAccountDataStore get(final ServiceId accountIdentifier) {
if (accountIdentifier.equals(aci)) {
- return getAciSignalServiceAccountDataStore();
+ return aci();
} else if (accountIdentifier.equals(pni)) {
- throw new AssertionError("PNI not to be used yet!");
+ return pni();
} else {
throw new IllegalArgumentException("No matching store found for " + accountIdentifier);
}
@Override
public SignalServiceAccountDataStore pni() {
- throw new AssertionError("PNI not to be used yet!");
+ return getPniSignalServiceAccountDataStore();
}
@Override
}
private SignalServiceAccountDataStore getAciSignalServiceAccountDataStore() {
- return getOrCreate(() -> signalProtocolStore,
- () -> signalProtocolStore = new SignalProtocolStore(getAciPreKeyStore(),
+ return getOrCreate(() -> aciSignalProtocolStore,
+ () -> aciSignalProtocolStore = new SignalProtocolStore(getAciPreKeyStore(),
getAciSignedPreKeyStore(),
- getSessionStore(),
+ getAciSessionStore(),
getAciIdentityKeyStore(),
getSenderKeyStore(),
this::isMultiDevice));
}
+ private SignalServiceAccountDataStore getPniSignalServiceAccountDataStore() {
+ return getOrCreate(() -> pniSignalProtocolStore,
+ () -> pniSignalProtocolStore = new SignalProtocolStore(getPniPreKeyStore(),
+ getPniSignedPreKeyStore(),
+ getPniSessionStore(),
+ getPniIdentityKeyStore(),
+ getSenderKeyStore(),
+ this::isMultiDevice));
+ }
+
private PreKeyStore getAciPreKeyStore() {
return getOrCreate(() -> aciPreKeyStore,
() -> aciPreKeyStore = new PreKeyStore(getAccountDatabase(), ServiceIdType.ACI));
() -> pniSignedPreKeyStore = new SignedPreKeyStore(getAccountDatabase(), ServiceIdType.PNI));
}
- public SessionStore getSessionStore() {
- return getOrCreate(() -> sessionStore,
- () -> sessionStore = new SessionStore(getAccountDatabase(),
+ public SessionStore getAciSessionStore() {
+ return getOrCreate(() -> aciSessionStore,
+ () -> aciSessionStore = new SessionStore(getAccountDatabase(),
ServiceIdType.ACI,
getRecipientResolver(),
getRecipientIdCreator()));
}
+ public SessionStore getPniSessionStore() {
+ return getOrCreate(() -> pniSessionStore,
+ () -> pniSessionStore = new SessionStore(getAccountDatabase(),
+ ServiceIdType.PNI,
+ getRecipientResolver(),
+ getRecipientIdCreator()));
+ }
+
public IdentityKeyStore getIdentityKeyStore() {
return getOrCreate(() -> identityKeyStore,
() -> identityKeyStore = new IdentityKeyStore(getIdentitiesPath(dataPath, accountPath),
getIdentityKeyStore()));
}
+ public SignalIdentityKeyStore getPniIdentityKeyStore() {
+ return getOrCreate(() -> pniIdentityKeyStore,
+ () -> pniIdentityKeyStore = new SignalIdentityKeyStore(getRecipientResolver(),
+ () -> pniIdentityKeyPair,
+ localRegistrationId,
+ getIdentityKeyStore()));
+ }
+
public GroupStore getGroupStore() {
return getOrCreate(() -> groupStore,
() -> groupStore = new GroupStore(getAccountDatabase(),
save();
clearAllPreKeys();
- getSessionStore().archiveAllSessions();
+ getAciSessionStore().archiveAllSessions();
+ getPniSessionStore().archiveAllSessions();
getSenderKeyStore().deleteAll();
final var recipientId = getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
final var publicKey = getAciIdentityKeyPair().getPublicKey();