Esempio n. 1
0
        public void TestTLSTrustedCertProperites()
        {
            Properties testprops = new Properties();

            testprops.Set("pemFile", "fixture/testPems/caBundled.pems".Locate() + "," + // has 3 certs
                          "fixture/testPems/Org1MSP_CA.pem".Locate());                  // has 1

            testprops.Set("pemBytes", File.ReadAllText("fixture/testPems/Org2MSP_CA.pem".Locate()));

            CryptoPrimitives cpto = new CryptoPrimitives();

            cpto.Init();

            HFCAClient client = HFCAClient.Create("client", "https://localhost:99", testprops);

            client.CryptoSuite = cpto;
            client.SetUpSSL();
            int               count      = 0;
            KeyStore          trustStore = client.CryptoSuite.Store;
            List <BigInteger> expected   = new List <BigInteger>
            {
                new BigInteger("4804555946196630157804911090140692961"),
                new BigInteger("127556113420528788056877188419421545986539833585"),
                new BigInteger("704500179517916368023344392810322275871763581896"),
                new BigInteger("70307443136265237483967001545015671922421894552"),
                new BigInteger("276393268186007733552859577416965113792")
            };

            foreach (X509Certificate2 cert in trustStore.Certificates.Select(a => a.X509Certificate2))
            {
                BigInteger serialNumber = new BigInteger(cert.SerialNumber.FromHexString());
                Assert.IsTrue(expected.Contains(serialNumber), $"Missing certifiate with serial no. {serialNumber}");
                ++count;
            }

            Assert.AreEqual(expected.Count, count, "Number of CA certificates mismatch");
        }