Example #1
0
        static TspTest()
        {
            string signDN = "O=Bouncy Castle, C=AU";
            AsymmetricCipherKeyPair signKP   = TspTestUtil.MakeKeyPair();
            X509Certificate         signCert = TspTestUtil.MakeCACertificate(signKP, signDN, signKP, signDN);


            string origDN = "CN=Eric H. Echidna, [email protected], O=Bouncy Castle, C=AU";
            AsymmetricCipherKeyPair origKP = TspTestUtil.MakeKeyPair();

            privateKey = origKP.Private;



            cert = TspTestUtil.MakeCertificate(origKP, origDN, signKP, signDN);

            IList certList = new ArrayList();

            certList.Add(cert);
            certList.Add(signCert);

            certs = X509StoreFactory.Create(
                "Certificate/Collection",
                new X509CollectionStoreParameters(certList));
        }
Example #2
0
        internal static SignerInfoGenerator MakeInfoGenerator(AsymmetricKeyParameter key, X509Certificate cert,
                                                              string digestOID, Asn1.Cms.AttributeTable signedAttr, Asn1.Cms.AttributeTable unsignedAttr)
        {
            TspUtil.ValidateCertificate(cert);

            //
            // Add the ESSCertID attribute
            //
            IDictionary signedAttrs;

            if (signedAttr != null)
            {
                signedAttrs = signedAttr.ToDictionary();
            }
            else
            {
                signedAttrs = new Hashtable();
            }

            string digestName    = TspTestUtil.GetDigestAlgName(digestOID);
            string signatureName = digestName + "with" + TspTestUtil.GetEncryptionAlgName(
                TspTestUtil.GetEncOid(key, digestOID));

            Asn1SignatureFactory sigfact = new Asn1SignatureFactory(signatureName, key);

            return(new SignerInfoGeneratorBuilder()
                   .WithSignedAttributeGenerator(
                       new DefaultSignedAttributeTableGenerator(
                           new Asn1.Cms.AttributeTable(signedAttrs)))
                   .WithUnsignedAttributeGenerator(
                       new SimpleAttributeTableGenerator(unsignedAttr))
                   .Build(sigfact, cert));
        }
Example #3
0
        public void TestGeneral()
        {
            string signDN = "O=Bouncy Castle, C=AU";
            AsymmetricCipherKeyPair signKP   = TspTestUtil.MakeKeyPair();
            X509Certificate         signCert = TspTestUtil.MakeCACertificate(signKP, signDN, signKP, signDN);

            string origDN = "CN=Eric H. Echidna, [email protected], O=Bouncy Castle, C=AU";
            AsymmetricCipherKeyPair origKP = TspTestUtil.MakeKeyPair();
            var privateKey = origKP.Private;

            var cert = TspTestUtil.MakeCertificate(origKP, origDN, signKP, signDN);

            IList certList = new ArrayList();

            certList.Add(cert);
            certList.Add(signCert);

            var certs = X509StoreFactory.Create(
                "Certificate/Collection",
                new X509CollectionStoreParameters(certList));


            basicTest(origKP.Private, cert, certs);
            resolutionTest(origKP.Private, cert, certs, Resolution.R_SECONDS, "19700101000009Z");
            resolutionTest(origKP.Private, cert, certs, Resolution.R_TENTHS_OF_SECONDS, "19700101000009.9Z");
            resolutionTest(origKP.Private, cert, certs, Resolution.R_HUNDREDTHS_OF_SECONDS, "19700101000009.99Z");
            resolutionTest(origKP.Private, cert, certs, Resolution.R_MILLISECONDS, "19700101000009.999Z");
            basicSha256Test(origKP.Private, cert, certs);
            basicTestWithTSA(origKP.Private, cert, certs);
            overrideAttrsTest(origKP.Private, cert, certs);
            responseValidationTest(origKP.Private, cert, certs);
            incorrectHashTest(origKP.Private, cert, certs);
            badAlgorithmTest(origKP.Private, cert, certs);
            timeNotAvailableTest(origKP.Private, cert, certs);
            badPolicyTest(origKP.Private, cert, certs);
            tokenEncodingTest(origKP.Private, cert, certs);
            certReqTest(origKP.Private, cert, certs);
            testAccuracyZeroCerts(origKP.Private, cert, certs);
            testAccuracyWithCertsAndOrdering(origKP.Private, cert, certs);
            testNoNonse(origKP.Private, cert, certs);
            extensionTest(origKP.Private, cert, certs);
            additionalExtensionTest(origKP.Private, cert, certs);
        }