|
1 |
| -/** |
2 |
| - * Copyright (C) 2017 langboost, golf1052 |
3 |
| - * |
4 |
| - * This program is free software: you can redistribute it and/or modify |
5 |
| - * it under the terms of the GNU General Public License as published by |
6 |
| - * the Free Software Foundation, either version 3 of the License, or |
7 |
| - * (at your option) any later version. |
8 |
| - * |
9 |
| - * This program is distributed in the hope that it will be useful, |
10 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
| - * GNU General Public License for more details. |
13 |
| - * |
14 |
| - * You should have received a copy of the GNU General Public License |
15 |
| - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 |
| - */ |
17 |
| - |
18 |
| -using System; |
19 |
| -using Microsoft.VisualStudio.TestTools.UnitTesting; |
20 |
| -using libsignal.ecc; |
21 |
| -using libsignal; |
22 |
| -using libsignal.fingerprint; |
23 |
| - |
24 |
| -namespace org.whispersystems.libsignal.fingerprint |
25 |
| -{ |
26 |
| - [TestClass] |
27 |
| - public class NumericFingerprintGeneratorTest |
28 |
| - { |
29 |
| - 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 }; |
30 |
| - 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 }; |
34 |
| - |
35 |
| - [TestMethod] |
36 |
| - public void testVectors() |
| 1 | +/** |
| 2 | + * Copyright (C) 2017 langboost, golf1052 |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +using System.Text; |
| 19 | +using libsignal; |
| 20 | +using libsignal.ecc; |
| 21 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 22 | + |
| 23 | +namespace org.whispersystems.libsignal.fingerprint |
| 24 | +{ |
| 25 | + [TestClass] |
| 26 | + public class NumericFingerprintGeneratorTest |
| 27 | + { |
| 28 | + private const int VERSION = 1; |
| 29 | + 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 }; |
| 30 | + 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 }; |
| 34 | + |
| 35 | + [TestMethod] |
| 36 | + public void testVectors() |
37 | 37 | {
|
38 |
| - return; //disable for now |
39 |
| - IdentityKey aliceIdentityKey = new IdentityKey(ALICE_IDENTITY, 0); |
40 |
| - IdentityKey bobIdentityKey = new IdentityKey(BOB_IDENTITY, 0); |
41 |
| - |
42 |
| - NumericFingerprintGenerator generator = new NumericFingerprintGenerator(5200); |
43 |
| - Fingerprint aliceFingerprint = generator.createFor( |
44 |
| - "+14152222222", aliceIdentityKey, |
45 |
| - "+14153333333", bobIdentityKey); |
46 |
| - |
47 |
| - Fingerprint bobFingerprint = generator.createFor( |
48 |
| - "+14153333333", bobIdentityKey, |
49 |
| - "+14152222222", aliceIdentityKey); |
50 |
| - |
51 |
| - Assert.AreEqual(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), DISPLAYABLE_FINGERPRINT); |
52 |
| - Assert.AreEqual(bobFingerprint.getDisplayableFingerprint().getDisplayText(), DISPLAYABLE_FINGERPRINT); |
53 |
| - |
54 |
| - CollectionAssert.AreEqual(aliceFingerprint.getScannableFingerprint().getSerialized(), ALICE_SCANNABLE_FINGERPRINT); |
55 |
| - CollectionAssert.AreEqual(bobFingerprint.getScannableFingerprint().getSerialized(), BOB_SCANNABLE_FINGERPRINT); |
56 |
| - } |
57 |
| - |
58 |
| - [TestMethod] |
59 |
| - public void testMatchingFingerprints() |
60 |
| - { |
61 |
| - ECKeyPair aliceKeyPair = Curve.generateKeyPair(); |
62 |
| - ECKeyPair bobKeyPair = Curve.generateKeyPair(); |
63 |
| - |
64 |
| - IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey()); |
65 |
| - IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey()); |
66 |
| - |
67 |
| - NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024); |
68 |
| - Fingerprint aliceFingerprint = generator.createFor("+14152222222", aliceIdentityKey, |
69 |
| - "+14153333333", bobIdentityKey); |
70 |
| - |
71 |
| - Fingerprint bobFingerprint = generator.createFor("+14153333333", bobIdentityKey, |
72 |
| - "+14152222222", aliceIdentityKey); |
73 |
| - |
74 |
| - Assert.AreEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), |
75 |
| - bobFingerprint.getDisplayableFingerprint().getDisplayText()); |
76 |
| - |
77 |
| - Assert.IsTrue( |
78 |
| - aliceFingerprint.getScannableFingerprint().compareTo( |
79 |
| - bobFingerprint.getScannableFingerprint().getSerialized())); |
80 |
| - Assert.IsTrue( |
81 |
| - bobFingerprint.getScannableFingerprint().compareTo( |
82 |
| - aliceFingerprint.getScannableFingerprint().getSerialized())); |
83 |
| - |
84 |
| - Assert.AreEqual<int>(aliceFingerprint.getDisplayableFingerprint().getDisplayText().Length, 60); |
85 |
| - } |
86 |
| - |
87 |
| - [TestMethod] |
88 |
| - public void testMismatchingFingerprints() |
89 |
| - { |
90 |
| - ECKeyPair aliceKeyPair = Curve.generateKeyPair(); |
91 |
| - ECKeyPair bobKeyPair = Curve.generateKeyPair(); |
92 |
| - ECKeyPair mitmKeyPair = Curve.generateKeyPair(); |
93 |
| - |
94 |
| - IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey()); |
95 |
| - IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey()); |
96 |
| - IdentityKey mitmIdentityKey = new IdentityKey(mitmKeyPair.getPublicKey()); |
97 |
| - |
98 |
| - NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024); |
99 |
| - Fingerprint aliceFingerprint = generator.createFor("+14152222222", aliceIdentityKey, |
100 |
| - "+14153333333", mitmIdentityKey); |
101 |
| - |
102 |
| - Fingerprint bobFingerprint = generator.createFor("+14153333333", bobIdentityKey, |
103 |
| - "+14152222222", aliceIdentityKey); |
104 |
| - |
105 |
| - Assert.AreNotEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), |
106 |
| - bobFingerprint.getDisplayableFingerprint().getDisplayText()); |
107 |
| - |
108 |
| - Assert.IsFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized())); |
109 |
| - Assert.IsFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized())); |
110 |
| - } |
111 |
| - |
112 |
| - [TestMethod] |
113 |
| - public void testMismatchingIdentifiers() |
114 |
| - { |
115 |
| - ECKeyPair aliceKeyPair = Curve.generateKeyPair(); |
116 |
| - ECKeyPair bobKeyPair = Curve.generateKeyPair(); |
117 |
| - |
118 |
| - IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey()); |
119 |
| - IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey()); |
120 |
| - |
121 |
| - NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024); |
122 |
| - Fingerprint aliceFingerprint = generator.createFor("+141512222222", aliceIdentityKey, |
123 |
| - "+14153333333", bobIdentityKey); |
124 |
| - |
125 |
| - Fingerprint bobFingerprint = generator.createFor("+14153333333", bobIdentityKey, |
126 |
| - "+14152222222", aliceIdentityKey); |
127 |
| - |
128 |
| - Assert.AreNotEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), |
129 |
| - bobFingerprint.getDisplayableFingerprint().getDisplayText()); |
130 |
| - Assert.IsFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized())); |
131 |
| - Assert.IsFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized())); |
132 |
| - } |
133 |
| - |
134 |
| - } |
135 |
| -} |
| 38 | + IdentityKey aliceIdentityKey = new IdentityKey(ALICE_IDENTITY, 0); |
| 39 | + IdentityKey bobIdentityKey = new IdentityKey(BOB_IDENTITY, 0); |
| 40 | + |
| 41 | + NumericFingerprintGenerator generator = new NumericFingerprintGenerator(5200); |
| 42 | + Fingerprint aliceFingerprint = generator.createFor(VERSION, |
| 43 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey, |
| 44 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey); |
| 45 | + |
| 46 | + Fingerprint bobFingerprint = generator.createFor(VERSION, |
| 47 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey, |
| 48 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey); |
| 49 | + |
| 50 | + Assert.AreEqual(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), DISPLAYABLE_FINGERPRINT); |
| 51 | + Assert.AreEqual(bobFingerprint.getDisplayableFingerprint().getDisplayText(), DISPLAYABLE_FINGERPRINT); |
| 52 | + |
| 53 | + CollectionAssert.AreEqual(aliceFingerprint.getScannableFingerprint().getSerialized(), ALICE_SCANNABLE_FINGERPRINT); |
| 54 | + CollectionAssert.AreEqual(bobFingerprint.getScannableFingerprint().getSerialized(), BOB_SCANNABLE_FINGERPRINT); |
| 55 | + } |
| 56 | + |
| 57 | + [TestMethod] |
| 58 | + public void testMatchingFingerprints() |
| 59 | + { |
| 60 | + ECKeyPair aliceKeyPair = Curve.generateKeyPair(); |
| 61 | + ECKeyPair bobKeyPair = Curve.generateKeyPair(); |
| 62 | + |
| 63 | + IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey()); |
| 64 | + IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey()); |
| 65 | + |
| 66 | + NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024); |
| 67 | + Fingerprint aliceFingerprint = generator.createFor(VERSION, |
| 68 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey, |
| 69 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey); |
| 70 | + |
| 71 | + Fingerprint bobFingerprint = generator.createFor(VERSION, |
| 72 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey, |
| 73 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey); |
| 74 | + |
| 75 | + Assert.AreEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), |
| 76 | + bobFingerprint.getDisplayableFingerprint().getDisplayText()); |
| 77 | + |
| 78 | + Assert.IsTrue( |
| 79 | + aliceFingerprint.getScannableFingerprint().compareTo( |
| 80 | + bobFingerprint.getScannableFingerprint().getSerialized())); |
| 81 | + Assert.IsTrue( |
| 82 | + bobFingerprint.getScannableFingerprint().compareTo( |
| 83 | + aliceFingerprint.getScannableFingerprint().getSerialized())); |
| 84 | + |
| 85 | + Assert.AreEqual<int>(aliceFingerprint.getDisplayableFingerprint().getDisplayText().Length, 60); |
| 86 | + } |
| 87 | + |
| 88 | + [TestMethod] |
| 89 | + public void testMismatchingFingerprints() |
| 90 | + { |
| 91 | + ECKeyPair aliceKeyPair = Curve.generateKeyPair(); |
| 92 | + ECKeyPair bobKeyPair = Curve.generateKeyPair(); |
| 93 | + ECKeyPair mitmKeyPair = Curve.generateKeyPair(); |
| 94 | + |
| 95 | + IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey()); |
| 96 | + IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey()); |
| 97 | + IdentityKey mitmIdentityKey = new IdentityKey(mitmKeyPair.getPublicKey()); |
| 98 | + |
| 99 | + NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024); |
| 100 | + Fingerprint aliceFingerprint = generator.createFor(VERSION, |
| 101 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey, |
| 102 | + Encoding.UTF8.GetBytes("+14153333333"), mitmIdentityKey); |
| 103 | + |
| 104 | + Fingerprint bobFingerprint = generator.createFor(VERSION, |
| 105 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey, |
| 106 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey); |
| 107 | + |
| 108 | + Assert.AreNotEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), |
| 109 | + bobFingerprint.getDisplayableFingerprint().getDisplayText()); |
| 110 | + |
| 111 | + Assert.IsFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized())); |
| 112 | + Assert.IsFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized())); |
| 113 | + } |
| 114 | + |
| 115 | + [TestMethod] |
| 116 | + public void testMismatchingIdentifiers() |
| 117 | + { |
| 118 | + ECKeyPair aliceKeyPair = Curve.generateKeyPair(); |
| 119 | + ECKeyPair bobKeyPair = Curve.generateKeyPair(); |
| 120 | + |
| 121 | + IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.getPublicKey()); |
| 122 | + IdentityKey bobIdentityKey = new IdentityKey(bobKeyPair.getPublicKey()); |
| 123 | + |
| 124 | + NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024); |
| 125 | + Fingerprint aliceFingerprint = generator.createFor(VERSION, |
| 126 | + Encoding.UTF8.GetBytes("+141512222222"), aliceIdentityKey, |
| 127 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey); |
| 128 | + |
| 129 | + Fingerprint bobFingerprint = generator.createFor(VERSION, |
| 130 | + Encoding.UTF8.GetBytes("+14153333333"), bobIdentityKey, |
| 131 | + Encoding.UTF8.GetBytes("+14152222222"), aliceIdentityKey); |
| 132 | + |
| 133 | + Assert.AreNotEqual<string>(aliceFingerprint.getDisplayableFingerprint().getDisplayText(), |
| 134 | + bobFingerprint.getDisplayableFingerprint().getDisplayText()); |
| 135 | + Assert.IsFalse(aliceFingerprint.getScannableFingerprint().compareTo(bobFingerprint.getScannableFingerprint().getSerialized())); |
| 136 | + Assert.IsFalse(bobFingerprint.getScannableFingerprint().compareTo(aliceFingerprint.getScannableFingerprint().getSerialized())); |
| 137 | + } |
| 138 | + |
| 139 | + } |
| 140 | +} |
0 commit comments