ReadCrls() public method

public ReadCrls ( Stream inStream ) : ICollection
inStream Stream
return ICollection
示例#1
0
        private void pkcs7Test()
        {
            Asn1Encodable rootCert = Asn1Object.FromByteArray(CertPathTest.rootCertBin);
            Asn1Encodable rootCrl = Asn1Object.FromByteArray(CertPathTest.rootCrlBin);

            X509CertificateParser certParser = new X509CertificateParser();
            X509CrlParser crlParser = new X509CrlParser();

            SignedData sigData = new SignedData(
                DerSet.Empty,
                new ContentInfo(CmsObjectIdentifiers.Data, null),
                new DerSet(
                    rootCert,
                    new DerTaggedObject(false, 2, Asn1Object.FromByteArray(AttrCertTest.attrCert))),
                new DerSet(rootCrl),
                DerSet.Empty);

            ContentInfo info = new ContentInfo(CmsObjectIdentifiers.SignedData, sigData);

            X509Certificate cert = certParser.ReadCertificate(info.GetEncoded());
            if (cert == null || !AreEqual(cert.GetEncoded(), rootCert.ToAsn1Object().GetEncoded()))
            {
                Fail("PKCS7 cert not read");
            }
            X509Crl crl = crlParser.ReadCrl(info.GetEncoded());
            if (crl == null || !AreEqual(crl.GetEncoded(), rootCrl.ToAsn1Object().GetEncoded()))
            {
                Fail("PKCS7 crl not read");
            }
            ArrayList col = new ArrayList(certParser.ReadCertificates(info.GetEncoded()));
            if (col.Count != 1 || !col.Contains(cert))
            {
                Fail("PKCS7 cert collection not right");
            }
            col = new ArrayList(crlParser.ReadCrls(info.GetEncoded()));
            if (col.Count != 1 || !col.Contains(crl))
            {
                Fail("PKCS7 crl collection not right");
            }

            // data with no certificates or CRLs

            sigData = new SignedData(DerSet.Empty, new ContentInfo(CmsObjectIdentifiers.Data, null), DerSet.Empty, DerSet.Empty, DerSet.Empty);

            info = new ContentInfo(CmsObjectIdentifiers.SignedData, sigData);

            cert = certParser.ReadCertificate(info.GetEncoded());
            if (cert != null)
            {
                Fail("PKCS7 cert present");
            }
            crl = crlParser.ReadCrl(info.GetEncoded());
            if (crl != null)
            {
                Fail("PKCS7 crl present");
            }

            // data with absent certificates and CRLS

            sigData = new SignedData(DerSet.Empty, new ContentInfo(CmsObjectIdentifiers.Data, null), null, null, DerSet.Empty);

            info = new ContentInfo(CmsObjectIdentifiers.SignedData, sigData);

            cert = certParser.ReadCertificate(info.GetEncoded());
            if (cert != null)
            {
                Fail("PKCS7 cert present");
            }
            crl = crlParser.ReadCrl(info.GetEncoded());
            if (crl != null)
            {
                Fail("PKCS7 crl present");
            }

            //
            // sample message
            //
            ICollection certCol = certParser.ReadCertificates(pkcs7CrlProblem);
            ICollection crlCol = crlParser.ReadCrls(pkcs7CrlProblem);

            if (crlCol.Count != 0)
            {
                Fail("wrong number of CRLs: " + crlCol.Count);
            }

            if (certCol.Count != 4)
            {
                Fail("wrong number of Certs: " + certCol.Count);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.Cryptography.DefaultSecureMimeContext"/> class.
        /// </summary>
        /// <param name="revokedFileName">The path to the revoked certificate lists.</param>
        /// <param name="addressbookFileName">The path to the addressbook certificates.</param>
        /// <param name="rootFileName">The path to the root certificates.</param>
        /// <param name="userFileName">The path to the pkcs12-formatted user certificates.</param>
        /// <param name="password">The password for the pkcs12 user certificates file.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="addressbookFileName"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="rootFileName"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="userFileName"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="password"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// An error occurred while reading the file.
        /// </exception>
        protected DefaultSecureMimeContext(string revokedFileName, string addressbookFileName, string rootFileName, string userFileName, string password)
        {
            addressbook = new X509CertificateStore ();
            store = new X509CertificateStore ();
            root = new X509CertificateStore ();
            crls = new HashSet<X509Crl> ();

            try {
                using (var file = File.OpenRead (revokedFileName)) {
                    var parser = new X509CrlParser ();
                    foreach (X509Crl crl in parser.ReadCrls (file))
                        crls.Add (crl);
                }
            } catch (FileNotFoundException) {
            }

            try {
                addressbook.Import (addressbookFileName);
            } catch (FileNotFoundException) {
            }

            try {
                store.Import (userFileName, password);
            } catch (FileNotFoundException) {
            }

            try {
                root.Import (rootFileName);
            } catch (FileNotFoundException) {
            }

            this.addressbookFileName = addressbookFileName;
            this.revokedFileName = revokedFileName;
            this.userFileName = userFileName;
            this.password = password;
        }