mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Fix PNI prefixing in provisioning message.
This commit is contained in:
committed by
Alex Hart
parent
f56a65d30d
commit
1cc7b46555
@@ -47,7 +47,7 @@ public class PniMigrationJob extends MigrationJob {
|
||||
return;
|
||||
}
|
||||
|
||||
PNI pni = PNI.parseOrNull(ApplicationDependencies.getSignalServiceAccountManager().getWhoAmI().getPni());
|
||||
PNI pni = PNI.parseUnPrefixedOrNull(ApplicationDependencies.getSignalServiceAccountManager().getWhoAmI().getPni());
|
||||
|
||||
if (pni == null) {
|
||||
throw new IOException("Invalid PNI!");
|
||||
|
||||
@@ -134,7 +134,6 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
||||
Log.w(TAG, "Found a ContactRecord without a UUID -- marking as invalid.");
|
||||
return true;
|
||||
} else if (remote.getAci().equals(selfAci) ||
|
||||
remote.getAci().equals(selfPni) ||
|
||||
(selfPni != null && selfPni.equals(remote.getPni().orElse(null))) ||
|
||||
(selfE164 != null && remote.getNumber().isPresent() && remote.getNumber().get().equals(selfE164)))
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ class ContactRecordProcessorTest {
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setPni(PNI_B.toString())
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
setE164(E164_B)
|
||||
}
|
||||
|
||||
@@ -117,22 +117,6 @@ class ContactRecordProcessorTest {
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isInvalid, pni matches self as serviceId, true`() {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(PNI_A.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
|
||||
// THEN
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isInvalid, pni matches self as pni, true`() {
|
||||
// GIVEN
|
||||
@@ -140,7 +124,7 @@ class ContactRecordProcessorTest {
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setPni(PNI_A.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -262,13 +246,13 @@ class ContactRecordProcessorTest {
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_B.toString())
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -290,13 +274,13 @@ class ContactRecordProcessorTest {
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_A.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -318,13 +302,13 @@ class ContactRecordProcessorTest {
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_B.toString())
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -346,13 +330,13 @@ class ContactRecordProcessorTest {
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_B.toString())
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
|
||||
@@ -668,7 +668,7 @@ public class SignalServiceAccountManager {
|
||||
.setPniIdentityKeyPublic(ByteString.copyFrom(pniIdentityKeyPair.getPublicKey().serialize()))
|
||||
.setPniIdentityKeyPrivate(ByteString.copyFrom(pniIdentityKeyPair.getPrivateKey().serialize()))
|
||||
.setAci(aci.toString())
|
||||
.setPni(pni.toString())
|
||||
.setPni(pni.toStringWithoutPrefix())
|
||||
.setNumber(e164)
|
||||
.setProfileKey(ByteString.copyFrom(profileKey.serialize()))
|
||||
.setProvisioningCode(code)
|
||||
|
||||
@@ -182,5 +182,8 @@ sealed class ServiceId(val libSignalServiceId: LibSignalServiceId) {
|
||||
}
|
||||
|
||||
override fun toString(): String = super.toString()
|
||||
|
||||
/** String version without the PNI: prefix. This is only for specific proto fields. For application storage, prefer [toString]. */
|
||||
fun toStringWithoutPrefix(): String = rawUuid.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
this.proto = proto;
|
||||
this.hasUnknownFields = ProtoUtil.hasUnknownFields(proto);
|
||||
this.aci = ACI.parseOrUnknown(proto.getAci());
|
||||
this.pni = OptionalUtil.absentIfEmpty(proto.getPni()).map(PNI::parseOrNull);
|
||||
this.pni = OptionalUtil.absentIfEmpty(proto.getPni()).map(PNI::parseUnPrefixedOrNull);
|
||||
this.e164 = OptionalUtil.absentIfEmpty(proto.getE164());
|
||||
this.profileGivenName = OptionalUtil.absentIfEmpty(proto.getGivenName());
|
||||
this.profileFamilyName = OptionalUtil.absentIfEmpty(proto.getFamilyName());
|
||||
@@ -300,7 +300,7 @@ public final class SignalContactRecord implements SignalRecord {
|
||||
}
|
||||
|
||||
public Builder setPni(PNI pni) {
|
||||
builder.setPni(pni == null ? "" : pni.toString());
|
||||
builder.setPni(pni == null ? "" : pni.toStringWithoutPrefix());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user