/// <summary>
        /// Creates a <see cref="TrustDB"/> from <see cref="TrustNode"/>s.
        /// </summary>
        public static TrustDB ToTrustDB([NotNull] this IEnumerable<TrustNode> nodes)
        {
            #region Sanity checks
            if (nodes == null) throw new ArgumentNullException("nodes");
            #endregion

            var trustDB = new TrustDB();
            foreach (var node in nodes)
                trustDB.TrustKey(node.Fingerprint, node.Domain);
            return trustDB;
        }
示例#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 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();
        }
示例#4
0
 /// <summary>
 /// Handles new keys that have not been trusted yet.
 /// </summary>
 /// <param name="uri">The URI the signed file originally came from.</param>
 /// <param name="fingerprint">The fingerprint of the key to trust.</param>
 /// <param name="domain">The domain to trust the key for.</param>
 /// <returns><c>true</c> if the user decided to trust the key, <c>false</c> if they decided not to trust the key.</returns>
 /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
 private bool HandleNewKey([NotNull] FeedUri uri, [NotNull] string fingerprint, Domain domain)
 {
     if (AskKeyApproval(uri, fingerprint, domain))
     {
         _trustDB.TrustKey(fingerprint, domain);
         _trustDB.Save();
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#5
0
 private bool TrustNew(TrustDB trustDB, FeedUri uri, ValidSignature signature, Domain domain)
 {
     if (AskKeyApproval(uri, signature, domain))
     {
         trustDB.TrustKey(signature.Fingerprint, domain);
         trustDB.Save();
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#6
0
        /// <summary>
        /// Creates a <see cref="TrustDB"/> from <see cref="TrustNode"/>s.
        /// </summary>
        public static TrustDB ToTrustDB(this IEnumerable <TrustNode> nodes)
        {
            #region Sanity checks
            if (nodes == null)
            {
                throw new ArgumentNullException(nameof(nodes));
            }
            #endregion

            var trustDB = new TrustDB();
            foreach (var node in nodes)
            {
                trustDB.TrustKey(node.Fingerprint, node.Domain);
            }
            return(trustDB);
        }
 /// <summary>
 /// Handles new keys that have not been trusted yet.
 /// </summary>
 /// <param name="uri">The URI the signed file originally came from.</param>
 /// <param name="fingerprint">The fingerprint of the key to trust.</param>
 /// <param name="domain">The domain to trust the key for.</param>
 /// <returns><c>true</c> if the user decided to trust the key, <c>false</c> if they decided not to trust the key.</returns>
 /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
 private bool HandleNewKey(FeedUri uri, string fingerprint, Domain domain)
 {
     if (AskKeyApproval(uri, fingerprint, domain))
     {
         _trustDB.TrustKey(fingerprint, domain);
         try
         {
             _trustDB.Save();
         }
         #region Error handling
         catch (Exception ex)
         {
             Log.Error(ex);
         }
         #endregion
         return(true);
     }
     else
     {
         return(false);
     }
 }
 private void TrustKey()
 => _trustDB.TrustKey(OpenPgpUtilsTest.TestSignature.FormatFingerprint(), new Domain("localhost"));