Fix handling of some PNI initial contact flows.

This commit is contained in:
Greyson Parrelli
2023-08-29 15:57:56 -04:00
parent 75b81a0fd2
commit 099c94c215
5 changed files with 12 additions and 13 deletions

View File

@@ -70,7 +70,7 @@ public class SignalBaseIdentityKeyStore {
public @NonNull SaveResult saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
IdentityStoreRecord identityRecord = cache.get(address.getName());
RecipientId recipientId = RecipientId.fromSidOrE164(address.getName());
RecipientId recipientId = RecipientId.from(ServiceId.fromLibSignal(address.getServiceId()));
if (identityRecord == null) {
Log.i(TAG, "Saving new identity for " + address);

View File

@@ -457,7 +457,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
if (result.operations.isNotEmpty() || result.requiredInsert) {
val pniString = if (pni == null) "null" else if (aci == null && e164 == null) pni.toString() else "<pni>"
val e164String = if (e164 == null) "null" else if (aci == null && pni == null) e164 else "<e164>"
val e164String = if (e164 == null) "null" else if (aci == null) e164 else "<e164>"
Log.i(TAG, "[getAndPossiblyMerge] ($aci, $pniString, $e164String) BreadCrumbs: ${result.breadCrumbs}, Operations: ${result.operations}, RequiredInsert: ${result.requiredInsert}, FinalId: ${result.finalId}")
}

View File

@@ -172,6 +172,7 @@ object MessageDecryptor {
if (cipherResult.metadata.sourceServiceId is ACI) {
handlePniSignatureMessage(
envelope,
bufferedProtocolStore,
cipherResult.metadata.sourceServiceId as ACI,
cipherResult.metadata.sourceE164,
cipherResult.metadata.sourceDeviceId,
@@ -325,7 +326,7 @@ object MessageDecryptor {
SignalGroupSessionBuilder(ReentrantSessionLock.INSTANCE, GroupSessionBuilder(senderKeyStore)).process(sender, message)
}
private fun handlePniSignatureMessage(envelope: Envelope, aci: ACI, e164: String?, deviceId: Int, pniSignatureMessage: PniSignatureMessage) {
private fun handlePniSignatureMessage(envelope: Envelope, protocolStore: BufferedProtocolStore, aci: ACI, e164: String?, deviceId: Int, pniSignatureMessage: PniSignatureMessage) {
Log.i(TAG, "${logPrefix(envelope, aci)} Processing PniSignatureMessage")
val pni: PNI = PNI.parseOrThrow(pniSignatureMessage.pni.toByteArray())
@@ -335,11 +336,10 @@ object MessageDecryptor {
return
}
val identityStore = ApplicationDependencies.getProtocolStore().aci().identities()
val aciAddress = SignalProtocolAddress(aci.toString(), deviceId)
val pniAddress = SignalProtocolAddress(pni.toString(), deviceId)
val aciIdentity = identityStore.getIdentity(aciAddress)
val pniIdentity = identityStore.getIdentity(pniAddress)
val aciIdentity = protocolStore.getAciStore().getIdentity(aciAddress)
val pniIdentity = protocolStore.getAciStore().getIdentity(pniAddress)
if (aciIdentity == null) {
Log.w(TAG, "${logPrefix(envelope, aci)}[validatePniSignature] No identity found for ACI address $aciAddress")

View File

@@ -58,8 +58,6 @@ import org.whispersystems.signalservice.api.util.OptionalUtil;
import org.whispersystems.signalservice.api.util.Preconditions;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -75,7 +73,6 @@ import java.util.stream.Collectors;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import static org.thoughtcrime.securesms.database.RecipientTable.InsightsBannerTier;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class Recipient {
@@ -343,8 +340,9 @@ public class Recipient {
RecipientTable db = SignalDatabase.recipients();
RecipientId id = null;
if (UuidUtil.isUuid(identifier)) {
ServiceId serviceId = ServiceId.parseOrThrow(identifier);
ServiceId serviceId = ServiceId.parseOrNull(identifier);
if (serviceId != null) {
id = db.getOrInsertFromServiceId(serviceId);
} else if (GroupId.isEncodedGroup(identifier)) {
id = db.getOrInsertFromGroupId(GroupId.parseOrThrow(identifier));

View File

@@ -87,8 +87,9 @@ public class RecipientId implements Parcelable, Comparable<RecipientId>, Databas
*/
@AnyThread
public static @NonNull RecipientId fromSidOrE164(@NonNull String identifier) {
if (UuidUtil.isUuid(identifier)) {
return from(ServiceId.parseOrThrow(identifier));
ServiceId serviceId = ServiceId.parseOrNull(identifier);
if (serviceId != null) {
return from(serviceId);
} else {
return from(null, identifier);
}