Ungate some PNP receive-side behavior.

This commit is contained in:
Greyson Parrelli
2023-08-10 11:08:28 -04:00
committed by Alex Hart
parent 327cd93e3c
commit ca3187d0b8
6 changed files with 18 additions and 42 deletions

View File

@@ -88,7 +88,17 @@ object MessageDecryptor {
val selfAci: ACI = SignalStore.account().requireAci()
val selfPni: PNI = SignalStore.account().requirePni()
val destination: ServiceId = envelope.getDestination(selfAci, selfPni)
val destination: ServiceId? = ServiceId.parseOrNull(envelope.destinationServiceId)
if (destination == null) {
Log.w(TAG, "${logPrefix(envelope)} Missing destination address! Invalid message, ignoring.")
return Result.Ignore(envelope, serverDeliveredTimestamp, emptyList())
}
if (destination != selfAci && destination != selfPni) {
Log.w(TAG, "${logPrefix(envelope)} Destination address does not match our ACI or PNI! Invalid message, ignoring.")
return Result.Ignore(envelope, serverDeliveredTimestamp, emptyList())
}
if (destination == selfPni && envelope.hasSourceServiceId()) {
Log.i(TAG, "${logPrefix(envelope)} Received a message at our PNI. Marking as needing a PNI signature.")
@@ -158,7 +168,7 @@ object MessageDecryptor {
)
}
if (FeatureFlags.phoneNumberPrivacy() && cipherResult.content.hasPniSignatureMessage()) {
if (cipherResult.content.hasPniSignatureMessage()) {
if (cipherResult.metadata.sourceServiceId is ACI) {
handlePniSignatureMessage(
envelope,
@@ -411,23 +421,6 @@ object MessageDecryptor {
}
}
private fun Envelope.getDestination(selfAci: ServiceId, selfPni: ServiceId): ServiceId {
return if (!FeatureFlags.phoneNumberPrivacy()) {
selfAci
} else if (this.hasDestinationServiceId()) {
val serviceId = ServiceId.parseOrThrow(this.destinationServiceId)
if (serviceId == selfAci || serviceId == selfPni) {
serviceId
} else {
Log.w(TAG, "Destination of $serviceId does not match our ACI ($selfAci) or PNI ($selfPni)! Defaulting to ACI.")
selfAci
}
} else {
Log.w(TAG, "No destinationUuid set! Defaulting to ACI.")
selfAci
}
}
private fun Int.toCiphertextMessageType(): Int {
return when (this) {
Envelope.Type.CIPHERTEXT_VALUE -> CiphertextMessage.WHISPER_TYPE