Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think there are two parts to the question: </p> <ol> <li>How do you retrieve the server's certificate</li> <li>How do you retrieve the certificate's chain</li> </ol> <p>To rertrieve the server's certificate you use SslStream whose methods are similar to .NET's own <a href="http://msdn.microsoft.com/en-us/library/system.net.security.sslstream.aspx" rel="noreferrer">SslStream</a></p> <pre><code>var serverName = "...; var client = new TcpClient(serverName, 443); // Create an SSL stream that will close the client's stream. using (var sslStream = new SslStream(client.GetStream(),true)) { sslStream.AuthenticateAsClient(serverName); var serverCertificate = sslStream.RemoteCertificate; } </code></pre> <p>It seems that OpenSSL.Net can't retrieve a certificate's chain. The -showcerts parameter uses the <a href="http://www.openssl.org/docs/ssl/SSL_get_peer_cert_chain.html" rel="noreferrer">SSL_get_peer_cert_chain</a> function which is not implemented in OpenSSL.NET. </p> <p>If you don't mind mixing OpenSSL.Net and the built-in .NET classes, you can convert an OpenSSL.Net certificate to a .NET certificate and retrieve the chain using .NET's <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509chain.build.aspx" rel="noreferrer">X509Chain.Build</a> . You can convert the .NET certificates back to OpenSSL.NET certificates using the .NET certificate's <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.rawdata" rel="noreferrer">RawData</a> property.</p> <pre><code>var managedCert = new System.Security.Cryptography.X509Certificates.X509Certificate2(serverCertificate.DER); var chain = new System.Security.Cryptography.X509Certificates.X509Chain(); chain.Build(managedCert); foreach (var element in chain.ChainElements) { var raw = element.Certificate.RawData; using (var bio = new BIO(raw)) { var oc = OpenSSL.X509.X509Certificate.FromDER(bio); } } </code></pre> <p>Perhaps you can use .NET's SslStream and X509Certificate2 object to do what you want using the raw certificate data without using OpenSSL.Net at all. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload