Пример #1
0
        public void TestAddRemoveTrust()
        {
            var trust = new TrustDB();
            trust.IsTrusted("abc", new Domain("domain")).Should().BeFalse();

            trust.TrustKey("abc", new Domain("domain"));
            trust.Keys.Should().Equal(new Key {Fingerprint = "abc", Domains = {new Domain("domain")}});
            trust.IsTrusted("abc", new Domain("domain")).Should().BeTrue();

            trust.UntrustKey("abc", new Domain("domain"));
            trust.IsTrusted("abc", new Domain("domain")).Should().BeFalse();
        }
Пример #2
0
        public void TestAddRemoveTrust()
        {
            var trust = new TrustDB();
            Assert.IsFalse(trust.IsTrusted("abc", new Domain("domain")));

            trust.TrustKey("abc", new Domain("domain"));
            CollectionAssert.AreEqual(new[] {new Key {Fingerprint = "abc", Domains = {new Domain("domain")}}}, trust.Keys);
            Assert.IsTrue(trust.IsTrusted("abc", new Domain("domain")));

            trust.UntrustKey("abc", new Domain("domain"));
            Assert.IsFalse(trust.IsTrusted("abc", new Domain("domain")));
        }
Пример #3
0
        public ValidSignature CheckTrust(byte[] data, FeedUri uri, string localPath = null)
        {
            #region Sanity checks
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            #endregion

            if (uri.IsFile)
            {
                throw new UriFormatException(Resources.FeedUriLocal);
            }

            var domain = new Domain(uri.Host);
KeyImported:
            var signatures = FeedUtils.GetSignatures(_openPgp, data).ToList();

            foreach (var signature in signatures.OfType <ValidSignature>())
            {
                if (_trustDB.IsTrusted(signature.FormatFingerprint(), domain))
                {
                    return(signature);
                }
            }

            foreach (var signature in signatures.OfType <ValidSignature>())
            {
                if (HandleNewKey(uri, signature.FormatFingerprint(), domain))
                {
                    return(signature);
                }
            }

            foreach (var signature in signatures.OfType <MissingKeySignature>())
            {
                Log.Info("Missing key for " + signature.FormatKeyID());
                AcquireMissingKey(signature, uri, localPath);
                goto KeyImported;
            }

            throw new SignatureException(string.Format(Resources.FeedNoTrustedSignatures, uri));
        }
 private bool IsKeyTrusted()
 => _trustDB.IsTrusted(OpenPgpUtilsTest.TestSignature.FormatFingerprint(), new Domain {
     Value = "localhost"
 });