protected override void DecodeDataBytes(ProtocolVersion version, byte[] data)
        {
            CertificateList.Clear();

            MemoryStream    memStream   = new MemoryStream(data);
            HandshakeStream stream      = new HandshakeStream(memStream);
            int             certsLength = (int)stream.ReadUInt24();

            int readBytes = 0;

            while (readBytes < certsLength)
            {
                int    certLength = (int)stream.ReadUInt24();
                byte[] certBytes  = stream.ReadBytes(certLength);
                readBytes += 3 + certLength;

                CertificateList.Add(new X509Certificate(certBytes));
            }
            if (readBytes != certsLength)
            {
                throw new AlertException(AlertDescription.IllegalParameter,
                                         "Certificate total length doesn't match contents");
            }
            stream.ConfirmEndOfStream();
        }
Exemple #2
0
        public int Init()
        {
            m_certs.Clear();

            IntPtr storeHandle;

            storeHandle = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, "MY");
            IntPtr currentCertContext;

            currentCertContext = CertEnumCertificatesInStore(storeHandle, (IntPtr)0);
            int i = 0;

            while (currentCertContext != (IntPtr)0)
            {
                m_certs.Insert(i++, new X509Certificate(currentCertContext));
                currentCertContext = CertEnumCertificatesInStore(storeHandle, currentCertContext);
            }
            CertCloseStore(storeHandle, 0);

            return(m_certs.Count);
        }
Exemple #3
0
        public static void X509CertificateCollectionInsertAndClear()
        {
            using (X509Certificate c1 = new X509Certificate())
            using (X509Certificate c2 = new X509Certificate())
            using (X509Certificate c3 = new X509Certificate())
            {
                X509CertificateCollection cc = new X509CertificateCollection();
                cc.Insert(0, c1);
                cc.Insert(1, c2);
                cc.Insert(2, c3);
                Assert.Equal(3, cc.Count);
                Assert.Same(c1, cc[0]);
                Assert.Same(c2, cc[1]);
                Assert.Same(c3, cc[2]);

                cc.Clear();
                Assert.Equal(0, cc.Count);

                cc.Add(c1);
                cc.Add(c3);
                Assert.Equal(2, cc.Count);
                Assert.Same(c1, cc[0]);
                Assert.Same(c3, cc[1]);

                cc.Insert(1, c2);
                Assert.Equal(3, cc.Count);
                Assert.Same(c1, cc[0]);
                Assert.Same(c2, cc[1]);
                Assert.Same(c3, cc[2]);

                cc.Clear();
                Assert.Equal(0, cc.Count);

                IList il = cc;
                il.Insert(0, c1);
                il.Insert(1, c2);
                il.Insert(2, c3);
                Assert.Equal(3, il.Count);
                Assert.Same(c1, il[0]);
                Assert.Same(c2, il[1]);
                Assert.Same(c3, il[2]);

                il.Clear();
                Assert.Equal(0, il.Count);

                il.Add(c1);
                il.Add(c3);
                Assert.Equal(2, il.Count);
                Assert.Same(c1, il[0]);
                Assert.Same(c3, il[1]);

                il.Insert(1, c2);
                Assert.Equal(3, il.Count);
                Assert.Same(c1, il[0]);
                Assert.Same(c2, il[1]);
                Assert.Same(c3, il[2]);

                il.Clear();
                Assert.Equal(0, il.Count);
            }
        }
 public void ClearCertificate()
 {
     Certificates.Clear();
 }