Esempio n. 1
0
        public static void ReadCertificates(ReadableBuffer buffer, SecurePipeListener listener)
        {
            buffer = buffer.Slice(HandshakeProcessor.HandshakeHeaderSize);
            //ignore context
            BufferExtensions.SliceVector <byte>(ref buffer);
            //slice the list
            buffer = BufferExtensions.SliceVector24Bit(ref buffer);
            X509Certificate2Collection collection;

            if (listener.CertificateValidation == null)
            {
                collection = null;
            }
            else
            {
                collection = new X509Certificate2Collection();
            }
            while (buffer.Length > 0)
            {
                var cert = BufferExtensions.SliceVector24Bit(ref buffer);
                var ext  = BufferExtensions.SliceVector <ushort>(ref buffer);
                if (cert.Length > 0 && collection != null)
                {
                    var x509 = new X509Certificate2(cert.ToArray());
                    collection.Add(x509);
                }
            }
            if (collection != null)
            {
                if (!listener.CertificateValidation(collection))
                {
                    Alerts.AlertException.ThrowAlert(Alerts.AlertLevel.Fatal, Alerts.AlertDescription.bad_certificate, "Failed to verify the certificate chain via the callback");
                }
            }
        }