【发布时间】:2021-01-05 12:27:21
【问题描述】:
我正在编写一个简单的 TLS 客户端/服务器程序来安全地通过网络进行通信。最初,我在运行 RHEL 8.2 的同一台机器上构建和运行客户端和服务器。
首先,我正在为我的程序使用自定义自签名 ssl 证书和密钥。我已将 rootCA.crt(我的自定义 CA 证书放在 /root/CA/rootCA.crt 中)。还将rootCA.pem复制到/etc/pki/ca-trust/source/anchors/并执行update-ca-trust enable然后update-ca-trust extract将证书安装到系统。 (不确定是否需要重启系统才能生效。)
最初,客户端和服务器能够使用 TLS 进行通信,直到我在客户端添加了代码的证书验证部分。
证书验证sn-p:
ctx = SSL_CTX_new(method); /* Create new context */
if ( ctx == NULL )
{
ERR_print_errors_fp(stderr);
abort();
}
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
SSL_CTX_set_verify_depth(ctx, 4);
const long flags = SSL_OP_NO_SSLv2 |
SSL_OP_NO_SSLv3 |
SSL_OP_NO_TLSv1 |
SSL_OP_NO_TLSv1_1 |
SSL_OP_NO_COMPRESSION;
SSL_CTX_set_options(ctx, flags);
if(SSL_CTX_load_verify_locations(ctx, NULL,
"/root/CA/") == 0){
ERR_print_errors_fp(stderr);
abort();
}
ssl = SSL_new(ctx); /* create new SSL connection state */
SSL_set_fd(ssl, server); /* attach the socket descriptor */
if ( SSL_connect(ssl) == FAIL ) /* perform the connection */
ERR_print_errors_fp(stderr);
else
{
sprintf(acClientRequest, "%s", cpRequestMessage); /* construct reply */
printf("\n\nConnected with %s encryption\n", SSL_get_ciphe
}
当我运行服务器和客户端程序时,我看到以下错误 messafe =>
客户端: 140736372886336:错误:1416F086:SSL 例程:tls_process_server_certificate:证书验证失败:ssl/statem/statem_clnt.c:1915:
在服务器上: 140736022137664:error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:ssl/record/rec_layer_s3.c:1543:SSL alert number 48
不确定,证书验证过程出了什么问题。谁能建议我如何解决这个错误?
【问题讨论】: