コード例 #1
0
        public static AsyncCertificateRequest Parse(ProtocolVersion version, IByteBuffer data)
        {
            int numTypes = data.ReadByte() & 0x0FF;

            byte[] certificateTypes = new byte[numTypes];
            for (int i = 0; i < numTypes; ++i)
            {
                certificateTypes[i] = data.ReadByte();
            }

            IList supportedSignatureAlgorithms = null;

            if (ProtocolVersion.TLSv12.IsEqualOrEarlierVersionOf(version.GetEquivalentTLSVersion()))
            {
                supportedSignatureAlgorithms = DtlsHelper.ParseSupportedSignatureAlgorithms(false, data);
            }

            IList certificateAuthorities = new List <X509Name>();
            int   remainingBytes         = data.ReadUnsignedShort();

            while (remainingBytes > 0)
            {
                byte[] derEncoding = new byte[data.ReadUnsignedShort()];
                data.ReadBytes(derEncoding);
                Asn1InputStream asn1   = new Asn1InputStream(derEncoding);
                Asn1Object      result = asn1.ReadObject();
                asn1.Close();

                if (null == result)
                {
                    throw new TlsFatalAlert(AlertDescription.decode_error);
                }

                if (null != asn1.ReadObject())
                {
                    throw new TlsFatalAlert(AlertDescription.decode_error);
                }

                certificateAuthorities.Add(X509Name.GetInstance(result));
                remainingBytes -= 2 + derEncoding.Length;
            }

            return(new AsyncCertificateRequest(certificateTypes, supportedSignatureAlgorithms, certificateAuthorities));
        }