示例#1
0
        /**
         * Parse a {@link Certificate} from a {@link Stream}.
         *
         * @param input the {@link Stream} to parse from.
         * @return a {@link Certificate} object.
         * @throws IOException
         */
        public static Certificate Parse(Stream input)
        {
            int totalLength = TlsUtilities.ReadUint24(input);

            if (totalLength == 0)
            {
                return(EmptyChain);
            }

            byte[] certListData = TlsUtilities.ReadFully(totalLength, input);

            MemoryStream buf = new MemoryStream(certListData, false);

            IList certificate_list = Platform.CreateArrayList();

            while (buf.Position < buf.Length)
            {
                byte[]     derEncoding = TlsUtilities.ReadOpaque24(buf);
                Asn1Object asn1Cert    = TlsUtilities.ReadDerObject(derEncoding);
                certificate_list.Add(X509CertificateStructure.GetInstance(asn1Cert));
            }

            X509CertificateStructure[] certificateList = new X509CertificateStructure[certificate_list.Count];
            for (int i = 0; i < certificate_list.Count; ++i)
            {
                certificateList[i] = (X509CertificateStructure)certificate_list[i];
            }
            return(new Certificate(certificateList));
        }
    public static Certificate Parse(Stream input)
    {
        int num = TlsUtilities.ReadUint24(input);

        if (num == 0)
        {
            return(EmptyChain);
        }
        byte[]       buffer       = TlsUtilities.ReadFully(num, input);
        MemoryStream memoryStream = new MemoryStream(buffer, writable: false);
        IList        list         = Platform.CreateArrayList();

        while (memoryStream.Position < memoryStream.Length)
        {
            byte[]     encoding = TlsUtilities.ReadOpaque24(memoryStream);
            Asn1Object obj      = TlsUtilities.ReadDerObject(encoding);
            list.Add(X509CertificateStructure.GetInstance(obj));
        }
        X509CertificateStructure[] array = new X509CertificateStructure[list.Count];
        for (int i = 0; i < list.Count; i++)
        {
            array[i] = (X509CertificateStructure)list[i];
        }
        return(new Certificate(array));
    }
示例#3
0
        /**
         * Parse a {@link OcspStatusRequest} from a {@link Stream}.
         *
         * @param input
         *            the {@link Stream} to parse from.
         * @return an {@link OcspStatusRequest} object.
         * @throws IOException
         */
        public static OcspStatusRequest Parse(Stream input)
        {
            IList responderIDList = Platform.CreateArrayList();
            {
                int length = TlsUtilities.ReadUint16(input);
                if (length > 0)
                {
                    byte[]       data = TlsUtilities.ReadFully(length, input);
                    MemoryStream buf  = new MemoryStream(data, false);
                    do
                    {
                        byte[]      derEncoding = TlsUtilities.ReadOpaque16(buf);
                        ResponderID responderID = ResponderID.GetInstance(TlsUtilities.ReadDerObject(derEncoding));
                        responderIDList.Add(responderID);
                    }while (buf.Position < buf.Length);
                }
            }

            X509Extensions requestExtensions = null;

            {
                int length = TlsUtilities.ReadUint16(input);
                if (length > 0)
                {
                    byte[] derEncoding = TlsUtilities.ReadFully(length, input);
                    requestExtensions = X509Extensions.GetInstance(TlsUtilities.ReadDerObject(derEncoding));
                }
            }

            return(new OcspStatusRequest(responderIDList, requestExtensions));
        }
        /**
         * Parse a {@link CertificateRequest} from a {@link Stream}.
         *
         * @param context
         *            the {@link TlsContext} of the current connection.
         * @param input
         *            the {@link Stream} to parse from.
         * @return a {@link CertificateRequest} object.
         * @throws IOException
         */
        public static CertificateRequest Parse(TlsContext context, Stream input)
        {
            int numTypes = TlsUtilities.ReadUint8(input);

            byte[] certificateTypes = new byte[numTypes];
            for (int i = 0; i < numTypes; ++i)
            {
                certificateTypes[i] = TlsUtilities.ReadUint8(input);
            }

            IList supportedSignatureAlgorithms = null;

            if (TlsUtilities.IsTlsV12(context))
            {
                // TODO Check whether SignatureAlgorithm.anonymous is allowed here
                supportedSignatureAlgorithms = TlsUtilities.ParseSupportedSignatureAlgorithms(false, input);
            }

            IList certificateAuthorities = Platform.CreateArrayList();

            byte[]       certAuthData = TlsUtilities.ReadOpaque16(input);
            MemoryStream bis          = new MemoryStream(certAuthData, false);

            while (bis.Position < bis.Length)
            {
                byte[]     derEncoding = TlsUtilities.ReadOpaque16(bis);
                Asn1Object asn1        = TlsUtilities.ReadDerObject(derEncoding);
                // TODO Switch to X500Name when available
                certificateAuthorities.Add(X509Name.GetInstance(asn1));
            }

            return(new CertificateRequest(certificateTypes, supportedSignatureAlgorithms, certificateAuthorities));
        }
    public static OcspStatusRequest Parse(Stream input)
    {
        IList list = Platform.CreateArrayList();
        int   num  = TlsUtilities.ReadUint16(input);

        if (num > 0)
        {
            byte[]       buffer       = TlsUtilities.ReadFully(num, input);
            MemoryStream memoryStream = new MemoryStream(buffer, writable: false);
            do
            {
                byte[]      encoding = TlsUtilities.ReadOpaque16(memoryStream);
                ResponderID instance = ResponderID.GetInstance(TlsUtilities.ReadDerObject(encoding));
                list.Add(instance);
            }while (memoryStream.Position < memoryStream.Length);
        }
        X509Extensions requestExtensions = null;
        int            num2 = TlsUtilities.ReadUint16(input);

        if (num2 > 0)
        {
            byte[] encoding2 = TlsUtilities.ReadFully(num2, input);
            requestExtensions = X509Extensions.GetInstance(TlsUtilities.ReadDerObject(encoding2));
        }
        return(new OcspStatusRequest(list, requestExtensions));
    }
示例#6
0
    public static CertificateRequest Parse(TlsContext context, Stream input)
    {
        int num = TlsUtilities.ReadUint8(input);

        byte[] array = new byte[num];
        for (int i = 0; i < num; i++)
        {
            array[i] = TlsUtilities.ReadUint8(input);
        }
        IList supportedSignatureAlgorithms = null;

        if (TlsUtilities.IsTlsV12(context))
        {
            supportedSignatureAlgorithms = TlsUtilities.ParseSupportedSignatureAlgorithms(allowAnonymous: false, input);
        }
        IList list = Platform.CreateArrayList();

        byte[]       buffer       = TlsUtilities.ReadOpaque16(input);
        MemoryStream memoryStream = new MemoryStream(buffer, writable: false);

        while (memoryStream.Position < memoryStream.Length)
        {
            byte[]     encoding = TlsUtilities.ReadOpaque16(memoryStream);
            Asn1Object obj      = TlsUtilities.ReadDerObject(encoding);
            list.Add(X509Name.GetInstance(obj));
        }
        return(new CertificateRequest(array, supportedSignatureAlgorithms, list));
    }
示例#7
0
    public static CertificateStatus Parse(Stream input)
    {
        byte b  = TlsUtilities.ReadUint8(input);
        byte b2 = b;

        if (b2 == 1)
        {
            byte[] encoding = TlsUtilities.ReadOpaque24(input);
            object instance = OcspResponse.GetInstance(TlsUtilities.ReadDerObject(encoding));
            return(new CertificateStatus(b, instance));
        }
        throw new TlsFatalAlert(50);
    }
示例#8
0
        /**
         * Parse a {@link CertificateStatus} from a {@link Stream}.
         *
         * @param input
         *            the {@link Stream} to parse from.
         * @return a {@link CertificateStatus} object.
         * @throws IOException
         */
        public static CertificateStatus Parse(Stream input)
        {
            byte   status_type = TlsUtilities.ReadUint8(input);
            object response;

            switch (status_type)
            {
            case CertificateStatusType.ocsp:
            {
                byte[] derEncoding = TlsUtilities.ReadOpaque24(input);
                response = OcspResponse.GetInstance(TlsUtilities.ReadDerObject(derEncoding));
                break;
            }

            default:
                throw new TlsFatalAlert(AlertDescription.decode_error);
            }

            return(new CertificateStatus(status_type, response));
        }