我已经使用 OpenSSL 设置了客户端-服务器通信,并且我的服务器正在发送它的证书。现在,我想让我的客户端也向服务器发送证书。在我的客户端,我有以下代码:
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 */
这是我的LoadCertificates
功能:
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");
}
我LoadCertificates
在服务器端具有相同的功能,而且似乎工作得很好。
但是,在服务器端未检测到我的客户端证书。我需要在客户端做些什么来发送证书吗?
我使用此处的代码作为基础对客户端代码进行了修改:http: //simplestcodings.blogspot.in/2010/08/secure-server-client-using-openssl-in-c.html