Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been given a certificate, key, and chain file (.crt, .key, and .pem) that I'm supposed to use to connect to a server. I've tried using openssl to create a .pfx file and used it with a TcpClient / SslStream / authenticate as client. It didn't work. What I understand now is that if the server uses openssl, the client must also (or painfully learn how openssl does its thing and write a lot of code). I've included the available openssl C# wrapper in a project but have no clue how to connect to the server using it. The openssl command line that works is...
openssl s_client -key provided.key -cert provided.crt -CAfile providedChain.pem -connect 127.0.0.1:12345
This statement works but how do I use the wrapper to do the same thing in C#?

What I have tried:

I've tried the standard TcpClient and in the connection callback, created the SslStream and attempted to authenticate as client. The call takes a certificate but from what I understand, it is one file that contains certificate information as well as the key. I've used openssl to combine the two but that didn't work. The server kicks me out because the initial handshake doesn't event work (don't get to the authentication part).
Posted
Updated 14-Sep-17 10:26am

1 solution

Google Search is your best friend.

I did a quick search using: c# ssl - Google Search[^] which then had the following suggestion at the bottom of the page: c# ssl client example - Google Search[^] which then had this as the first result: SslStream Class (System.Net.Security) - MSDN[^] which has a working example.

If you need other examples, the above two searches has tonnes of useful material for you.
 
Share this answer
 
Comments
Hendrik Vis 24-Oct-17 8:50am    
Unfortunately, that example doesn't contain the generation of a client certificate to apply on the Authenticate As Client call. My issue is that I have a client certificate file (.crt), a private key file (.key), and a chain file (.pem) but cannot generate an X509Certificate from them to provide my server. The private key is AES 256 CBC if that helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900