public void ValidityTest() {
   CertificateHandler ch = new CertificateHandler();
   RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
   byte[] blob = rsa.ExportCspBlob(false);
   RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
   rsa_pub.ImportCspBlob(blob);
   string ID = "brunet:node:PXYSWDL5SZDHDDXJKZCLFENOP2KZDMBU";
   CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
       "*****@*****.**", rsa_pub, ID);
   Certificate cert_0 = cm.Sign(cm, rsa);
   ch.AddSignedCertificate(cert_0.X509);
   ch.AddCACertificate(cert_0.X509);
   rsa = new RSACryptoServiceProvider(1024);
   rsa_pub.ImportCspBlob(rsa.ExportCspBlob(false));
   cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
       "*****@*****.**", rsa_pub, ID);
   Certificate cert_1 = cm.Sign(cm, rsa);
   Assert.IsTrue(ch.Verify(cert_0.X509, ID), "Valid");
   bool success = false;
   try {
     success = ch.Verify(cert_1.X509, ID);
   } catch { }
   Assert.IsTrue(!success, "Valid cert2");
 }
    public void FindCertificateTest() {
      CertificateHandler ch = new CertificateHandler();

      RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
      byte[] blob = rsa.ExportCspBlob(false);
      RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
      rsa_pub.ImportCspBlob(blob);

      List<MemBlock> supported = new List<MemBlock>();
      List<MemBlock> unsupported = new List<MemBlock>();

      for(int i = 0; i < 20; i++) {
        CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
            "*****@*****.**" + i, rsa_pub, i.ToString());
        Certificate cert = cm.Sign(cm, rsa);
        if(i % 2 == 0) {
          ch.AddCACertificate(cert.X509);
          ch.AddSignedCertificate(cert.X509);
          supported.Add(cert.SerialNumber);
        } else {
          unsupported.Add(cert.SerialNumber);
        }
      }

      Assert.IsNotNull(ch.FindCertificate(supported), "Should find a certificate");

      bool success = false;
      try {
        success = ch.FindCertificate(unsupported) != null;
      } catch { }

      Assert.IsTrue(!success, "Should not find a certificate");

      List<MemBlock> mixed = new List<MemBlock>(unsupported);
      mixed.Insert(4 ,supported[1]);
      Assert.AreEqual(supported[1],
          MemBlock.Reference(ch.FindCertificate(mixed).SerialNumber),
          "Only one supported");
    }
예제 #3
0
    protected PeerSecOverlord CreateInvalidSO(string name, int level) {
      if(rsa == null) {
        rsa = new RSACryptoServiceProvider();
        byte[] blob = rsa.ExportCspBlob(false);
        RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
        rsa_pub.ImportCspBlob(blob);
        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
            "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
            "brunet:node:abcdefghijklmnopqrs");
        Certificate cert = cm.Sign(cm, rsa);
        x509 = cert.X509;
      }

      CertificateHandler ch = new CertificateHandler();
      if(level == 2 || level == 0) {
        ch.AddCACertificate(x509);
      }
      if(level == 3 || level == 0) {
        ch.AddSignedCertificate(x509);
      }
      Random rand = new Random();
      ReqrepManager rrm = new ReqrepManager("so" + name + rand.Next());
      _timeout += rrm.TimeoutChecker;

      PeerSecOverlord so = new PeerSecOverlord(rsa_safe, ch, rrm);
      so.AnnounceSA += AnnounceSA;
      RoutingDataHandler rdh = new RoutingDataHandler();
      rrm.Subscribe(so, null);
      so.Subscribe(rdh, null);
      rdh.Subscribe(rrm, null);
      return so;
    }