private void SendCertificates () { TlsStream chain = new TlsStream (); X509Certificate currentCert = this.ClientCertificate; while (currentCert != null) { byte[] rawCert = currentCert.GetRawCertData (); chain.WriteInt24 (rawCert.Length); chain.Write(rawCert); currentCert = FindParentCertificate (currentCert); } this.WriteInt24 ((int)chain.Length); this.Write (chain.ToArray ()); }
protected override void ProcessAsTls1() { #warning "Client certificate selection is unfinished" ClientContext context = (ClientContext)this.Context; string msg = "Client certificate requested by the server and no client certificate specified."; if (context.ClientSettings.Certificates == null || context.ClientSettings.Certificates.Count == 0) { throw new TlsException(AlertDescription.UserCancelled, msg); } // Select a valid certificate X509Certificate clientCert = this.Context.ClientSettings.Certificates[0]; clientCert = context.SslStream.RaiseClientCertificateSelection( this.Context.ClientSettings.Certificates, new X509Certificate(this.Context.ServerSettings.Certificates[0].RawData), this.Context.ClientSettings.TargetHost, null); if (clientCert == null) { throw new TlsException(AlertDescription.UserCancelled, msg); } // Update the selected client certificate context.ClientSettings.ClientCertificate = clientCert; // Write client certificates information to a stream TlsStream stream = new TlsStream(); stream.WriteInt24(clientCert.GetRawCertData().Length); stream.Write(clientCert.GetRawCertData()); // Compose the message this.WriteInt24((int)stream.Length); this.Write(stream.ToArray()); }