I am new to SSL and Certificates . I have been doing my research about client certificate authentication. I have read this and wiki.
So If I have to implement a client certificate auth solution for my B2B REST service should I do following
- Ask clients to generate their own private-public key and generate certificate (CA issued?) for their public key. Send that certificate over email or USB key.
- On the server side import client's public certificate into trust store and enable client authentication
- During the hand shake client presents it's certificate and gets authenticated, because server has a copy of cert in it's trust store and can verify CertificateVerify message
My question is how does it stop anybody to pose as my client. Let's say a hacker X sends a CA issued certified to the server as part of handshake. Then server would automatically trust it and grant access.
I've to break down your question into two parts.
Part one:
Let's say a hacker X sends a CA issued certified to the server as part of handshake. Then server would automatically trust it and grant access.
If X aquires the client certificate of an authentic client then that's ok. Because the certificate itself does not contain any secret. Those certificate can be published anywhere without doing any damage (Except if you want to keep your email address a secret, try not to publish it. But it may will get out there after some time. And company crafted X509CertificateExtensions are not considered as well.).
The private key is the important key which must be kept secret by your client. If X gets the private key as well, X can impose an authentic client and login into your system. Therefore clients must protect those private keys from getting stolen!
That's because within the client-auth handshake, the server not only requests the client certificate. The client must also prove that he's the real owner of the certificate, by using his private key as stated in the wiki you referenced:
The client sends a CertificateVerify message, which is a signature over the previous handshake messages using the client's certificate's private key.
Such a signature can only be done if the client posesses the private key belonging to the certificate, as stated in the wiki as well:This lets the server know that the client has access to the private key of the certificate and thus owns the certificate.
!Part two:
How do establish a initial trust relationship?
That part is difficult if there are many clients involved. That's why the PKI was established. You trust the CA, and the CA should to the identity check on that clients who request a certificate.
For homebrew solutions in which case you have your own CA, or you don't trust a CA, the part is up to you. You must be sure that you grand access to your services only to authentic clients. If you do this via USB keys and the clients hand them over to you in person, that's ok.
If you receive an email which says "hello, i'm your friend XYZ from ABC, remember? Btw. here's my certificate" - check it twice.