Exemple #1
0
        // helper methods
        /// <param name="certificate">the certificate from which we need the ExtensionValue</param>
        /// <param name="oid">the Object Identifier value for the extension.</param>
        /// <returns>the extension value as an ASN1Primitive object</returns>
        private static Asn1Object GetExtensionValue(X509Certificate certificate, String oid)
        {
            byte[] bytes = SignUtils.GetExtensionValueByOid(certificate, oid);
            if (bytes == null)
            {
                return(null);
            }
            Asn1InputStream aIn  = new Asn1InputStream(new MemoryStream(bytes));
            Asn1OctetString octs = (Asn1OctetString)aIn.ReadObject();

            aIn = new Asn1InputStream(new MemoryStream(octs.GetOctets()));
            return(aIn.ReadObject());
        }
Exemple #2
0
        // Time Stamp Authority
        /// <summary>Gets the URL of the TSA if it's available on the certificate</summary>
        /// <param name="certificate">a certificate</param>
        /// <returns>a TSA URL</returns>
        public static String GetTSAURL(X509Certificate certificate)
        {
            byte[] der = SignUtils.GetExtensionValueByOid(certificate, SecurityIDs.ID_TSA);
            if (der == null)
            {
                return(null);
            }
            Asn1Object asn1obj;

            try {
                asn1obj = Asn1Object.FromByteArray(der);
                DerOctetString octets = (DerOctetString)asn1obj;
                asn1obj = Asn1Object.FromByteArray(octets.GetOctets());
                Asn1Sequence asn1seq = Asn1Sequence.GetInstance(asn1obj);
                return(GetStringFromGeneralName(asn1seq[1].ToAsn1Object()));
            }
            catch (System.IO.IOException) {
                return(null);
            }
        }