public static void ReadOids()
        {
            byte[] derEncoded =
            {
                // Noise
                0x10, 0x20, 0x30, 0x04, 0x05,

                // Data
                0x30, 27,
                0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
                0x06, 0x03, 0x55, 0x04, 0x03,
                0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x07,

                // More noise.
                0x85, 0x71, 0x23, 0x74, 0x01,
            };

            DerSequenceReader reader = new DerSequenceReader(derEncoded, 5, derEncoded.Length - 10);
            Assert.True(reader.HasData);
            Assert.Equal(27, reader.ContentLength);

            Oid first = reader.ReadOid();
            Assert.Equal("1.2.840.113549.1.1.11", first.Value);

            Oid second = reader.ReadOid();
            Assert.Equal("2.5.4.3", second.Value);

            Oid third = reader.ReadOid();
            Assert.Equal("1.3.6.1.4.1.311.21.7", third.Value);

            // And... done.
            Assert.False(reader.HasData);
        }
Beispiel #2
0
        public static void ReadOids()
        {
            byte[] derEncoded =
            {
                // Noise
                0x10, 0x20, 0x30, 0x04, 0x05,

                // Data
                0x30,   34,
                0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
                0x06, 0x03, 0x55, 0x04, 0x03,
                0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x15, 0x07,
                0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22,

                // More noise.
                0x85, 0x71, 0x23, 0x74, 0x01,
            };

            DerSequenceReader reader = new DerSequenceReader(derEncoded, 5, derEncoded.Length - 10);

            Assert.True(reader.HasData);
            Assert.Equal(34, reader.ContentLength);

            Oid first = reader.ReadOid();

            Assert.Equal("1.2.840.113549.1.1.11", first.Value);

            Oid second = reader.ReadOid();

            Assert.Equal("2.5.4.3", second.Value);

            Oid third = reader.ReadOid();

            Assert.Equal("1.3.6.1.4.1.311.21.7", third.Value);

            Oid fourth = reader.ReadOid();

            Assert.Equal("1.3.132.0.34", fourth.Value);

            // And... done.
            Assert.False(reader.HasData);
        }
        public void FindByTemplateName(string templateName)
        {
            FindCore(
                cert =>
                {
                    X509Extension ext = FindExtension(cert, Oids.EnrollCertTypeExtension);

                    if (ext != null)
                    {
                        // Try a V1 template structure, just a string:
                        string decodedName = Interop.Crypto.DerStringToManagedString(ext.RawData);

                        // If this doesn't match, maybe a V2 template will
                        if (StringComparer.OrdinalIgnoreCase.Equals(templateName, decodedName))
                        {
                            return true;
                        }
                    }

                    ext = FindExtension(cert, Oids.CertificateTemplate);

                    if (ext != null)
                    {
                        DerSequenceReader reader = new DerSequenceReader(ext.RawData);
                        // SEQUENCE (
                        //     OID oid,
                        //     INTEGER major,
                        //     INTEGER minor OPTIONAL
                        //  )

                        if (reader.PeekTag() == (byte)DerSequenceReader.DerTag.ObjectIdentifier)
                        {
                            Oid oid = reader.ReadOid();

                            if (StringComparer.Ordinal.Equals(templateName, oid.Value))
                            {
                                return true;
                            }
                        }
                    }

                    return false;
                });
        }