我已經使用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