Brunet.Security.CertificateHandler.AddCertificateVerification C# (CSharp) Method

AddCertificateVerification() public method

Add an ICertificateVerification to be called during verification of certificates
public AddCertificateVerification ( ICertificateVerification certificate_verifier ) : bool
certificate_verifier ICertificateVerification
return bool
    public bool AddCertificateVerification(ICertificateVerification certificate_verifier) {
      _certificate_verifiers.Add(certificate_verifier);
      return true;
    }

Usage Example

        public void Test()
        {
            CertificateHandler ch = new CertificateHandler();
              ch.AddCACertificate(_ca_cert.X509);
              ch.AddCertificateVerification(this);

              ArrayList revoked_users = new ArrayList();
              revoked_users.Add("joker");
              revoked_users.Add("bad_guy");
              revoked_users.Add("adversary");
              revoked_users.Add("noobs");

              // create revocation list
              byte[] to_sign = null;
              using(MemoryStream ms = new MemoryStream()) {
            NumberSerializer.WriteLong(DateTime.UtcNow.Ticks, ms);
            AdrConverter.Serialize(revoked_users, ms); to_sign = ms.ToArray();
              }

              // sign revocation list
              SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
              byte[] hash = sha1.ComputeHash(to_sign);
              byte[] signature = _private_key.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
              byte[] data = new byte[4 + to_sign.Length + signature.Length];
              NumberSerializer.WriteInt(to_sign.Length, data, 0);
              to_sign.CopyTo(data, 4);
              signature.CopyTo(data, 4 + to_sign.Length);

              UpdateRl(data);

              X509Certificate likable_guy = CreateCert("likable_guy");
              X509Certificate joker = CreateCert("joker");
              X509Certificate bad_guy = CreateCert("bad_guy");
              X509Certificate good_guy = CreateCert("good_guy");
              X509Certificate adversary = CreateCert("adversary");
              X509Certificate noobs =  CreateCert("noobs");
              X509Certificate friendly_guy =  CreateCert("friendly_guy");

              Assert.IsTrue(ch.Verify(likable_guy, _remote_id), "Likable guy");
              bool success = false;
              try {
            success = ch.Verify(adversary, _remote_id);
              } catch { }
              Assert.AreEqual(success, false, "adversary");

              try {
            success = ch.Verify(joker, _remote_id);
              } catch { }
              Assert.AreEqual(success, false, "joker");

              Assert.IsTrue(ch.Verify(friendly_guy, _remote_id), "friendly guy");

              try {
            success = ch.Verify(noobs, _remote_id);
              } catch { }
              Assert.AreEqual(success, false, "noobs");

              try {
            success = ch.Verify(bad_guy, _remote_id);
              } catch { }
              Assert.AreEqual(success, false, "bad_guy");

              Assert.IsTrue(ch.Verify(good_guy, _remote_id), "good guy");
        }