The reason you want to use a client certificate is for additional authentication.
The handshake works a bit like this:
- The client sends the
ClientHello. - The server replies with the
ServerHello, which includes that the server wants to see a certificate from the client. Optionally, the server also includes details on which certificate authority the client certificate should be signed by. This is useful for clients automatically selecting the correct certificate out of many, but clients are free to ignore this.
What happens now depends on how the server is configured. There are several possibilities:
1. The server expects a certificate signed by a specific Certificate Authority.
The server has the certificate of a certificate authority (usually an internal one) and the server checks whether or not the certificate sent by the client was signed by this certificate authority.
This means that any client who does not possess a certificate signed by this specific (internal) Certificate Authority cannot make a connection to the server.
2. The server offers an optional client certificate.
This means that the client can send a client certificate, but the connection is not aborted if no client certificate is sent. Usually, in such cases, the certificate data (or lack thereof) is passed onto the application layer for processing.
For example, access to example.com does not require a client certificate, but access to example.com/admin/ does require a client certificate. Parsing of the URL path can however not be done purely through TLS and requires a HTTP server. So all the TLS library can offer is an optional certificate and the HTTP server needs to determine if it's valid and if the path requires it.
3. The client sends the wrong client certificate
For example, the server may require a client certificate signed by Example Corp. Root CA, but the client sends a client certificate signed by Attacker Corp. Internal CA. The server doesn't care about that, and rejects the certificate and ends the connection.
Also it should be noted that when I say a participant "sends a certificate", it's not just the certificate they send. There is also a validation that the participant possesses the associated private key.