/** * 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 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)); }