I have set up my client-server communication using OpenSSL and my server is sending it's certificate. Now, I want to make my client send a certificate to the server as well. On my client side, i have the following code:
ctx = InitCTX();
LoadCertificates(ctx, "clientCert.pem", "clientCert.pem"); /* load certs */
server = OpenConnection(hostname, atoi(portnum));
ssl = SSL_new(ctx); /* create new SSL connection state */
SSL_set_fd(ssl, server); /* attach the socket descriptor */
and this is my LoadCertificates
function:
void LoadCertificates(SSL_CTX* ctx, char* CertFile, char* KeyFile)
{
if ( SSL_CTX_use_certificate_file(ctx, CertFile, SSL_FILETYPE_PEM) <= 0 )
{
ERR_print_errors_fp(stderr);
abort();
}
/* set the private key from KeyFile (may be the same as CertFile) */
if ( SSL_CTX_use_PrivateKey_file(ctx, KeyFile, SSL_FILETYPE_PEM) <= 0 )
{
ERR_print_errors_fp(stderr);
abort();
}
/* verify private key */
if ( !SSL_CTX_check_private_key(ctx) )
{
fprintf(stderr, "Private key does not match the public certificate\n");
abort();
}
printf("Certificate attached.\n");
}
I have the same LoadCertificates
function on the server side, and that seems to be working perfectly.
However, my client-side certificate is not getting detected on the server side. Is there anything different I need to do on the client side to send a certificate across?
I made modifications to the client code using the code from here as base: http://simplestcodings.blogspot.in/2010/08/secure-server-client-using-openssl-in-c.html