Пример #1
0
        public void TestMatchingFingerprints()
        {
            EcKeyPair aliceKeyPair = Curve.GenerateKeyPair();
            EcKeyPair bobKeyPair   = Curve.GenerateKeyPair();

            IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.GetPublicKey());
            IdentityKey bobIdentityKey   = new IdentityKey(bobKeyPair.GetPublicKey());

            NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024);

            Libsignal.Fingerprint.Fingerprint aliceFingerprint = generator.CreateFor("+14152222222", aliceIdentityKey,
                                                                                     "+14153333333", bobIdentityKey);

            Libsignal.Fingerprint.Fingerprint bobFingerprint = generator.CreateFor("+14153333333", bobIdentityKey,
                                                                                   "+14152222222", aliceIdentityKey);

            Assert.AreEqual <string>(aliceFingerprint.GetDisplayableFingerprint().GetDisplayText(),
                                     bobFingerprint.GetDisplayableFingerprint().GetDisplayText());

            Assert.IsTrue(
                aliceFingerprint.GetScannableFingerprint().CompareTo(
                    bobFingerprint.GetScannableFingerprint().GetSerialized()));
            Assert.IsTrue(
                bobFingerprint.GetScannableFingerprint().CompareTo(
                    aliceFingerprint.GetScannableFingerprint().GetSerialized()));

            Assert.AreEqual <int>(aliceFingerprint.GetDisplayableFingerprint().GetDisplayText().Length, 60);
        }
Пример #2
0
        public void TestVectors()
        {
            IdentityKey aliceIdentityKey = new IdentityKey(AliceIdentity, 0);
            IdentityKey bobIdentityKey   = new IdentityKey(BobIdentity, 0);

            NumericFingerprintGenerator generator = new NumericFingerprintGenerator(5200);

            Libsignal.Fingerprint.Fingerprint aliceFingerprint = generator.CreateFor(
                "+14152222222", aliceIdentityKey,
                "+14153333333", bobIdentityKey);

            Libsignal.Fingerprint.Fingerprint bobFingerprint = generator.CreateFor(
                "+14153333333", bobIdentityKey,
                "+14152222222", aliceIdentityKey);

            Assert.AreEqual(aliceFingerprint.GetDisplayableFingerprint().GetDisplayText(), DisplayableFingerprint);
            Assert.AreEqual(bobFingerprint.GetDisplayableFingerprint().GetDisplayText(), DisplayableFingerprint);

            CollectionAssert.AreEqual(aliceFingerprint.GetScannableFingerprint().GetSerialized(), AliceScannableFingerprint);
            CollectionAssert.AreEqual(bobFingerprint.GetScannableFingerprint().GetSerialized(), BobScannableFingerprint);
        }
Пример #3
0
        public void TestMismatchingIdentifiers()
        {
            EcKeyPair aliceKeyPair = Curve.GenerateKeyPair();
            EcKeyPair bobKeyPair   = Curve.GenerateKeyPair();

            IdentityKey aliceIdentityKey = new IdentityKey(aliceKeyPair.GetPublicKey());
            IdentityKey bobIdentityKey   = new IdentityKey(bobKeyPair.GetPublicKey());

            NumericFingerprintGenerator generator = new NumericFingerprintGenerator(1024);

            Libsignal.Fingerprint.Fingerprint aliceFingerprint = generator.CreateFor("+141512222222", aliceIdentityKey,
                                                                                     "+14153333333", bobIdentityKey);

            Libsignal.Fingerprint.Fingerprint bobFingerprint = generator.CreateFor("+14153333333", bobIdentityKey,
                                                                                   "+14152222222", aliceIdentityKey);

            Assert.AreNotEqual <string>(aliceFingerprint.GetDisplayableFingerprint().GetDisplayText(),
                                        bobFingerprint.GetDisplayableFingerprint().GetDisplayText());

            try
            {
                aliceFingerprint.GetScannableFingerprint().CompareTo(bobFingerprint.GetScannableFingerprint().GetSerialized());
                throw new Exception("Should mismatch!");
            }
            catch (FingerprintIdentifierMismatchException e)
            {
                // good
            }

            try
            {
                bobFingerprint.GetScannableFingerprint().CompareTo(aliceFingerprint.GetScannableFingerprint().GetSerialized());
                throw new Exception("Should mismatch!");
            }
            catch (FingerprintIdentifierMismatchException e)
            {
                // good
            }
        }