Exemplo n.º 1
0
        // Parse an X.509-format name and convert it into a string.
        private static String ParseName(ASN1Parser certInfo)
        {
            StringBuilder builder = new StringBuilder();
            ASN1Parser    outer;
            ASN1Parser    set;
            ASN1Parser    pair;

            // Process the outer sequence.
            outer = certInfo.GetSequence();
            while (!outer.IsAtEnd())
            {
                // Process the next name attribute set.
                set = outer.GetSet();
                while (!set.IsAtEnd())
                {
                    // Process the next attribute name/value pair.
                    pair = set.GetSequence();
                    pair.Skip(ASN1Type.ObjectIdentifier);
                    if (pair.IsString())
                    {
                        // Add the value to the string we are building.
                        if (builder.Length > 0)
                        {
                            builder.Append(", ");
                        }
                        builder.Append(pair.GetString());
                    }
                }
            }

            // Convert the result into a name.
            return(builder.ToString());
        }
Exemplo n.º 2
0
        // Parse the contents of a certificate data block.
        private void Parse(byte[] data)
        {
            // Clone the data for internal storage.
            rawData = (byte[])(data.Clone());

            // Parse the ASN.1 data to get the field we are interested in.
            ASN1Parser parser   = new ASN1Parser(rawData);
            ASN1Parser signed   = parser.GetSequence();
            ASN1Parser certInfo = signed.GetSequence();

            if (certInfo.Type == ASN1Parser.ContextSpecific(0))
            {
                // Skip the version field.
                certInfo.Skip();
            }
            serialNumber = certInfo.GetContentsAsArray(ASN1Type.Integer);
            ASN1Parser algId = certInfo.GetSequence();

            issuer = ParseName(certInfo);
            ASN1Parser validity = certInfo.GetSequence();

            effectiveDate  = validity.GetUTCTime();
            expirationDate = validity.GetUTCTime();
            name           = ParseName(certInfo);
            ASN1Parser keyInfo = certInfo.GetSequence();

            algId        = keyInfo.GetSequence();
            keyAlgorithm = ToHex(algId.GetObjectIdentifier());
            if (algId.IsAtEnd() || algId.IsNull())
            {
                keyAlgorithmParameters = null;
            }
            else
            {
                keyAlgorithmParameters = algId.GetWholeAsArray();
            }
            publicKey = keyInfo.GetBitString();

#if CONFIG_CRYPTO
            // Construct an MD5 hash of the certificate.  Is this correct?
            MD5 md5 = new MD5CryptoServiceProvider();
            md5.InternalHashCore(rawData, 0, rawData.Length);
            hash = md5.InternalHashFinal();
            md5.Initialize();
#endif
        }