Send Client Certificate and Private Key to Server with SSL - c#

I have been working on Windows application in C#, which will act as TCP client and communicate with server. Tool has to send Certificate and Private key to Server, once the server authentication is successful there will a handshake at TLS level.
I used SSL stream class to send certificate, but on server end it does shows that the certificate.
But once I make connection, server log the client connection.
I am so new to this, Can someone help through the process and examples.
Thanks in advance.

Related

SSL Stream with Client Certificate

I have followed the Microsoft Documentation (https://learn.microsoft.com/en-us/dotnet/api/system.net.security.sslstream?view=netframework-4.7.2) and able to create a
server that allows Https Connection.
Currently , The implementation does only Authentication from the Server end but I would like to
issue an another certificate from the Client that server can authenticate to establish the connection.
Most of the Documents only cover examples with client Authentication set to false. I am looking for sample example in which Server can receive and Authenticate the client certificate as well .
Any suggestions would be much helpful.
Thanks a lot in advance !!

Shall I have client certificates for consumers of my REST API?

I have a REST API which uses JWT bearer authentication over HTTPS. SSL certificate is installed on the web server hosting my REST API. Do I need to provide client certificates to different applications(users) who want to consume my API, to have a handshake between their server and my server using the client certificate which i provide them.
I tried calling my HTTPS REST API which I developed in C# from a python script running locally from my machine but I had to specify the verify flag to False or ssl.CERT_NONE for the call to succeed
import requests
requests.get('some https url', verify=False)
I know we can also use self signed certificates. I am worried about Man in the Middle attacks if they call my endpoint with verify=False and If someone tries to use my API in his app which is in production over https do I need to give him the client certificate for handshake or his app would be able to call my https api endpoint without me specifically providing a client certificate.
I tried to take some leads from this question but it doesn't explain how different users whose apps are trying to call my endpoint over https, will be able to perform a handshake with my rest api
Any guidance would be highly appreciated.
Quick answer: keep your private key file safe and you wont have any problems.
The long answer has to do with explaining asymmetrical encryption and how its implemented in a TLS handshake. When a client opens a HTTPS connection with your server a series of requests are sent back and forth:
Client sends HELLO
Server sends HELLO back including the servers SSL certificate
Client verifies the certificate with the certificate authority
The client sends back a random string of bytes encrypted with the servers public key
The server decrypts the string using the private key
After the final step a session is created between the client and server. In order for a man-in-the-middle attack to be successful the "man in the middle" needs to have your private key and proxy every action just described back to your server, otherwise one of the steps will fail and the client will get that "SERVER UNVERIFIED" error in their browser warning them that the connection is not secure.
This is a pretty brief explanation of the process, you can do some more reading here

TCPClient With SSL and Client Certificate not required Server Connection with Client Fails

I had Implemented TCP Client With SSlstream and try to connect server. I had provided Client certificate. Now the Problem is that when i tried to run the client when server Certificate is required and ClientAuthentication Required in that case it works succesfully.
But when i tried to connect with server settings Client Authentication not required at that time i am not able to do the proper communication and it is giving me that connection to port is not successful because underlying connection is closed. so please suggest what is exact tcpclient sslstream implementation which will connect with SSL Enabled server and Client Authentication is not required.
it seems like when there is clientAuthentication is not required at that time it gives it is still checking for authentication so it is giving me IsMutuallyAuthenticated Property of sslStream class false where is IsAuthenticatedProperty true.
The issue was with the server implementation , due to configuring it with the not required client certificate, it was internally taking that into consideration, once i tried with fresh implementation of server i was able to connect when there is no client authentication required implementation as well.

TLS/SSL where to install certificates

I need to provide mutual authentication using TLS protocol in my server-client communication. Now under development, client and server run on the same machine. My colleague created one certificate (.pfx file) for me. As it is a two-way authenticate, server and client have to authenticate each other.
This thread Mutual authentication in SSL/TLS discussed in which certificate store a certificate should be located on server side or client side. Now I am confused, as I only have one certificate, I dont know whether it is a client certificate or a server certificate, Can I use one certificate for both, if so where should I locate this certificate for both server and client ?
Thank you for your help !
You can use certificate for both ways, however what's the problem to generate standalone certificate (even self-signed) for client authentication?

.Net windows app development: Detecting if SSL Client Certificate is required and which ones are valid

In the same way as IE handles the client certificate authentication procedure, I would like to do the same from an installed .Net client app that connects to our web server which has been setup for requiring client certificates.
I know how to open the Select Certificate UI allowing the user to select a client certificate from a list of those that are installed, and then add the certificate to the outgoing HttpWebRequest.
What I can figure out is:
How to determine when a client certificate is required by the server. It's not in the HttpResponse. The status code is 403 but I can't read the substatus.
How to then filter the client certificates in the UI to list only those that are valid based on the server certificate (issued by?).
Thanks in advance.

Categories