Skip to content

Commit b170ec9

Browse files
committed
1 parent 11bf454 commit b170ec9

File tree

1 file changed

+81
-23
lines changed

1 file changed

+81
-23
lines changed

libsignal-protocol-dotnet-tests/fingerprint/NumericFingerprintGeneratorTest.cs

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,67 @@ namespace org.whispersystems.libsignal.fingerprint
2525
[TestClass]
2626
public class NumericFingerprintGeneratorTest
2727
{
28-
private const int VERSION = 1;
2928
private static readonly byte[] ALICE_IDENTITY = { 0x05, 0x06, 0x86, 0x3b, 0xc6, 0x6d, 0x02, 0xb4, 0x0d, 0x27, 0xb8, 0xd4, 0x9c, 0xa7, 0xc0, 0x9e, 0x92, 0x39, 0x23, 0x6f, 0x9d, 0x7d, 0x25, 0xd6, 0xfc, 0xca, 0x5c, 0xe1, 0x3c, 0x70, 0x64, 0xd8, 0x68 };
3029
private static readonly byte[] BOB_IDENTITY = { 0x05, 0xf7, 0x81, 0xb6, 0xfb, 0x32, 0xfe, 0xd9, 0xba, 0x1c, 0xf2, 0xde, 0x97, 0x8d, 0x4d, 0x5d, 0xa2, 0x8d, 0xc3, 0x40, 0x46, 0xae, 0x81, 0x44, 0x02, 0xb5, 0xc0, 0xdb, 0xd9, 0x6f, 0xda, 0x90, 0x7b };
31-
private static readonly string DISPLAYABLE_FINGERPRINT = "300354477692869396892869876765458257569162576843440918079131";
32-
private static readonly byte[] ALICE_SCANNABLE_FINGERPRINT = new byte[] { 0x08, 0x01, 0x12, 0x22, 0x0a, 0x20, 0x1e, 0x30, 0x1a, 0x03, 0x53, 0xdc, 0xe3, 0xdb, 0xe7, 0x68, 0x4c, 0xb8, 0x33, 0x6e, 0x85, 0x13, 0x6c, 0xdc, 0x0e, 0xe9, 0x62, 0x19, 0x49, 0x4a, 0xda, 0x30, 0x5d, 0x62, 0xa7, 0xbd, 0x61, 0xdf, 0x1a, 0x22, 0x0a, 0x20, 0xd6, 0x2c, 0xbf, 0x73, 0xa1, 0x15, 0x92, 0x01, 0x5b, 0x6b, 0x9f, 0x16, 0x82, 0xac, 0x30, 0x6f, 0xea, 0x3a, 0xaf, 0x38, 0x85, 0xb8, 0x4d, 0x12, 0xbc, 0xa6, 0x31, 0xe9, 0xd4, 0xfb, 0x3a, 0x4d };
33-
private static readonly byte[] BOB_SCANNABLE_FINGERPRINT = new byte[] { 0x08, 0x01, 0x12, 0x22, 0x0a, 0x20, 0xd6, 0x2c, 0xbf, 0x73, 0xa1, 0x15, 0x92, 0x01, 0x5b, 0x6b, 0x9f, 0x16, 0x82, 0xac, 0x30, 0x6f, 0xea, 0x3a, 0xaf, 0x38, 0x85, 0xb8, 0x4d, 0x12, 0xbc, 0xa6, 0x31, 0xe9, 0xd4, 0xfb, 0x3a, 0x4d, 0x1a, 0x22, 0x0a, 0x20, 0x1e, 0x30, 0x1a, 0x03, 0x53, 0xdc, 0xe3, 0xdb, 0xe7, 0x68, 0x4c, 0xb8, 0x33, 0x6e, 0x85, 0x13, 0x6c, 0xdc, 0x0e, 0xe9, 0x62, 0x19, 0x49, 0x4a, 0xda, 0x30, 0x5d, 0x62, 0xa7, 0xbd, 0x61, 0xdf };
30+
31+
private const int VERSION_1 = 1;
32+
private const string DISPLAYABLE_FINGERPRINT_V1 = "300354477692869396892869876765458257569162576843440918079131";
33+
private static readonly byte[] ALICE_SCANNABLE_FINGERPRINT_V1 = new byte[] { 0x08, 0x01, 0x12, 0x22, 0x0a, 0x20, 0x1e, 0x30, 0x1a, 0x03, 0x53, 0xdc, 0xe3, 0xdb, 0xe7, 0x68, 0x4c, 0xb8, 0x33, 0x6e, 0x85, 0x13, 0x6c, 0xdc, 0x0e, 0xe9, 0x62, 0x19, 0x49, 0x4a, 0xda, 0x30, 0x5d, 0x62, 0xa7, 0xbd, 0x61, 0xdf, 0x1a, 0x22, 0x0a, 0x20, 0xd6, 0x2c, 0xbf, 0x73, 0xa1, 0x15, 0x92, 0x01, 0x5b, 0x6b, 0x9f, 0x16, 0x82, 0xac, 0x30, 0x6f, 0xea, 0x3a, 0xaf, 0x38, 0x85, 0xb8, 0x4d, 0x12, 0xbc, 0xa6, 0x31, 0xe9, 0xd4, 0xfb, 0x3a, 0x4d };
34+
private static readonly byte[] BOB_SCANNABLE_FINGERPRINT_V1 = new byte[] { 0x08, 0x01, 0x12, 0x22, 0x0a, 0x20, 0xd6, 0x2c, 0xbf, 0x73, 0xa1, 0x15, 0x92, 0x01, 0x5b, 0x6b, 0x9f, 0x16, 0x82, 0xac, 0x30, 0x6f, 0xea, 0x3a, 0xaf, 0x38, 0x85, 0xb8, 0x4d, 0x12, 0xbc, 0xa6, 0x31, 0xe9, 0xd4, 0xfb, 0x3a, 0x4d, 0x1a, 0x22, 0x0a, 0x20, 0x1e, 0x30, 0x1a, 0x03, 0x53, 0xdc, 0xe3, 0xdb, 0xe7, 0x68, 0x4c, 0xb8, 0x33, 0x6e, 0x85, 0x13, 0x6c, 0xdc, 0x0e, 0xe9, 0x62, 0x19, 0x49, 0x4a, 0xda, 0x30, 0x5d, 0x62, 0xa7, 0xbd, 0x61, 0xdf };
35+
36+
private const int VERSION_2 = 2;
37+
private const string DISPLAYABLE_FINGERPRINT_V2 = DISPLAYABLE_FINGERPRINT_V1;
38+
private static readonly byte[] ALICE_SCANNABLE_FINGERPRINT_V2 = new byte[] { 0x08, 0x02, 0x12, 0x22, 0x0a, 0x20, 0x1e, 0x30, 0x1a, 0x03, 0x53, 0xdc, 0xe3, 0xdb, 0xe7, 0x68, 0x4c, 0xb8, 0x33, 0x6e, 0x85, 0x13, 0x6c, 0xdc, 0x0e, 0xe9, 0x62, 0x19, 0x49, 0x4a, 0xda, 0x30, 0x5d, 0x62, 0xa7, 0xbd, 0x61, 0xdf, 0x1a, 0x22, 0x0a, 0x20, 0xd6, 0x2c, 0xbf, 0x73, 0xa1, 0x15, 0x92, 0x01, 0x5b, 0x6b, 0x9f, 0x16, 0x82, 0xac, 0x30, 0x6f, 0xea, 0x3a, 0xaf, 0x38, 0x85, 0xb8, 0x4d, 0x12, 0xbc, 0xa6, 0x31, 0xe9, 0xd4, 0xfb, 0x3a, 0x4d };
39+
private static readonly byte[] BOB_SCANNABLE_FINGERPRINT_V2 = new byte[] { 0x08, 0x02, 0x12, 0x22, 0x0a, 0x20, 0xd6, 0x2c, 0xbf, 0x73, 0xa1, 0x15, 0x92, 0x01, 0x5b, 0x6b, 0x9f, 0x16, 0x82, 0xac, 0x30, 0x6f, 0xea, 0x3a, 0xaf, 0x38, 0x85, 0xb8, 0x4d, 0x12, 0xbc, 0xa6, 0x31, 0xe9, 0xd4, 0xfb, 0x3a, 0x4d, 0x1a, 0x22, 0x0a, 0x20, 0x1e, 0x30, 0x1a, 0x03, 0x53, 0xdc, 0xe3, 0xdb, 0xe7, 0x68, 0x4c, 0xb8, 0x33, 0x6e, 0x85, 0x13, 0x6c, 0xdc, 0x0e, 0xe9, 0x62, 0x19, 0x49, 0x4a, 0xda, 0x30, 0x5d, 0x62, 0xa7, 0xbd, 0x61, 0xdf };
3440

3541
[TestMethod]
36-
public void testVectors()
42+
public void testVectorsVersion1()
3743
{
3844
IdentityKey aliceIdentityKey = new IdentityKey(ALICE_IDENTITY, 0);
3945
IdentityKey bobIdentityKey = new IdentityKey(BOB_IDENTITY, 0);
46+
byte[] aliceStableId = Encoding.UTF8.GetBytes("+14152222222");
47+
byte[] bobStableId = Encoding.UTF8.GetBytes("+14153333333");
4048

4149
NumericFingerprintGenerator generator = new NumericFingerprintGenerator(5200);
42-
Fingerprint aliceFingerprint = generator.createFor(VERSION,
43-
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey,
44-
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey);
4550

46-
Fingerprint bobFingerprint = generator.createFor(VERSION,
47-
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey,
48-
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey);
51+
Fingerprint aliceFingerprint = generator.createFor(VERSION_1,
52+
aliceStableId, aliceIdentityKey,
53+
bobStableId, bobIdentityKey);
54+
55+
Fingerprint bobFingerprint = generator.createFor(VERSION_1,
56+
bobStableId, bobIdentityKey,
57+
aliceStableId, aliceIdentityKey);
58+
59+
Assert.AreEqual(DISPLAYABLE_FINGERPRINT_V1, aliceFingerprint.getDisplayableFingerprint().getDisplayText());
60+
Assert.AreEqual(DISPLAYABLE_FINGERPRINT_V1, bobFingerprint.getDisplayableFingerprint().getDisplayText());
61+
62+
CollectionAssert.AreEqual(ALICE_SCANNABLE_FINGERPRINT_V1, aliceFingerprint.getScannableFingerprint().getSerialized());
63+
CollectionAssert.AreEqual(BOB_SCANNABLE_FINGERPRINT_V1, bobFingerprint.getScannableFingerprint().getSerialized());
64+
}
65+
66+
[TestMethod]
67+
public void testVectorsVersion2()
68+
{
69+
IdentityKey aliceIdentityKey = new IdentityKey(ALICE_IDENTITY, 0);
70+
IdentityKey bobIdentityKey = new IdentityKey(BOB_IDENTITY, 0);
71+
byte[] aliceStableId = Encoding.UTF8.GetBytes("+14152222222");
72+
byte[] bobStableId = Encoding.UTF8.GetBytes("+14153333333");
4973

50-
Assert.AreEqual(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), DISPLAYABLE_FINGERPRINT);
51-
Assert.AreEqual(bobFingerprint.getDisplayableFingerprint().getDisplayText(), DISPLAYABLE_FINGERPRINT);
74+
NumericFingerprintGenerator generator = new NumericFingerprintGenerator(5200);
75+
76+
Fingerprint aliceFingerprint = generator.createFor(VERSION_2,
77+
aliceStableId, aliceIdentityKey,
78+
bobStableId, bobIdentityKey);
79+
80+
Fingerprint bobFingerprint = generator.createFor(VERSION_2,
81+
bobStableId, bobIdentityKey,
82+
aliceStableId, aliceIdentityKey);
83+
84+
Assert.AreEqual(DISPLAYABLE_FINGERPRINT_V2, aliceFingerprint.getDisplayableFingerprint().getDisplayText());
85+
Assert.AreEqual(DISPLAYABLE_FINGERPRINT_V2, bobFingerprint.getDisplayableFingerprint().getDisplayText());
5286

53-
CollectionAssert.AreEqual(aliceFingerprint.getScannableFingerprint().getSerialized(), ALICE_SCANNABLE_FINGERPRINT);
54-
CollectionAssert.AreEqual(bobFingerprint.getScannableFingerprint().getSerialized(), BOB_SCANNABLE_FINGERPRINT);
87+
CollectionAssert.AreEqual(ALICE_SCANNABLE_FINGERPRINT_V2, aliceFingerprint.getScannableFingerprint().getSerialized());
88+
CollectionAssert.AreEqual(BOB_SCANNABLE_FINGERPRINT_V2, bobFingerprint.getScannableFingerprint().getSerialized());
5589
}
5690

5791
[TestMethod]
@@ -64,11 +98,11 @@ public void testMatchingFingerprints()
6498
IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey());
6599

66100
NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024);
67-
Fingerprint aliceFingerprint = generator.createFor(VERSION,
101+
Fingerprint aliceFingerprint = generator.createFor(VERSION_1,
68102
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey,
69103
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey);
70104

71-
Fingerprint bobFingerprint = generator.createFor(VERSION,
105+
Fingerprint bobFingerprint = generator.createFor(VERSION_1,
72106
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey,
73107
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey);
74108

@@ -97,15 +131,15 @@ public void testMismatchingFingerprints()
97131
IdentityKey mitmIdentityKey = new IdentityKey(mitmKeyPair.getPublicKey());
98132

99133
NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024);
100-
Fingerprint aliceFingerprint = generator.createFor(VERSION,
134+
Fingerprint aliceFingerprint = generator.createFor(VERSION_1,
101135
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey,
102136
Encoding.UTF8.GetBytes("+14153333333"), mitmIdentityKey);
103137

104-
Fingerprint bobFingerprint = generator.createFor(VERSION,
138+
Fingerprint bobFingerprint = generator.createFor(VERSION_1,
105139
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey,
106140
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey);
107141

108-
Assert.AreNotEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
142+
Assert.AreNotEqual(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
109143
bobFingerprint.getDisplayableFingerprint().getDisplayText());
110144

111145
Assert.IsFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized()));
@@ -122,19 +156,43 @@ public void testMismatchingIdentifiers()
122156
IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey());
123157

124158
NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024);
125-
Fingerprint aliceFingerprint = generator.createFor(VERSION,
159+
Fingerprint aliceFingerprint = generator.createFor(VERSION_1,
126160
Encoding.UTF8.GetBytes("+141512222222"), aliceIdentityKey,
127161
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey);
128162

129-
Fingerprint bobFingerprint = generator.createFor(VERSION,
163+
Fingerprint bobFingerprint = generator.createFor(VERSION_1,
130164
Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey,
131165
Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey);
132166

133-
Assert.AreNotEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
167+
Assert.AreNotEqual(aliceFingerprint.getDisplayableFingerprint().getDisplayText(),
134168
bobFingerprint.getDisplayableFingerprint().getDisplayText());
135169
Assert.IsFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized()));
136170
Assert.IsFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized()));
137171
}
138172

173+
[TestMethod]
174+
public void testDifferentVersionsMakeSameFingerPrintsButDifferentScannable()
175+
{
176+
IdentityKey aliceIdentityKey = new IdentityKey(ALICE_IDENTITY, 0);
177+
IdentityKey bobIdentityKey = new IdentityKey(BOB_IDENTITY, 0);
178+
byte[] aliceStableId = Encoding.UTF8.GetBytes("+14152222222");
179+
byte[] bobStableId = Encoding.UTF8.GetBytes("+14153333333");
180+
181+
NumericFingerprintGenerator generator = new NumericFingerprintGenerator(5200);
182+
183+
Fingerprint aliceFingerprintV1 = generator.createFor(VERSION_1,
184+
aliceStableId, aliceIdentityKey,
185+
bobStableId, bobIdentityKey);
186+
187+
Fingerprint aliceFingerprintV2 = generator.createFor(VERSION_2,
188+
aliceStableId, aliceIdentityKey,
189+
bobStableId, bobIdentityKey);
190+
191+
Assert.IsTrue(aliceFingerprintV1.getDisplayableFingerprint().getDisplayText() ==
192+
aliceFingerprintV2.getDisplayableFingerprint().getDisplayText());
193+
194+
CollectionAssert.AreNotEqual(aliceFingerprintV1.getScannableFingerprint().getSerialized(),
195+
aliceFingerprintV2.getScannableFingerprint().getSerialized());
196+
}
139197
}
140198
}

0 commit comments

Comments
 (0)