Skip to content

客户端和服务端双向认证的连接 #123

Discussion options

You must be logged in to vote

C示例参考
服务端:针对SSL_CTX配置客户端认证并加载认证所需的根证书(在simple_server.c server_load_ssl_ctx函数中添加)

SSL_CTX_set_verify(server->ssl_ctx, SSL_VERIFY_FAIL_IF_NO_PEER_CERT | SSL_VERIFY_PEER, NULL); // 启用客户端认证,如果客户端不携带证书则认证失败
SSL_CTX_load_verify_locations(server->ssl_ctx, "ca.crt", NULL); // 加载客户端认证所使用的根证书

客户端:针对SSL_CTX配置携带客户端证书(在simple_client.c client_load_ssl_ctx函数中添加)

SSL_CTX_use_certificate_chain_file(client->ssl_ctx, "cert_client.crt");
SSL_CTX_use_PrivateKey_file(client->ssl_ctx, "cert_client.key", SSL_FILETYPE_PEM);

TLS版本不需要设置。
可参考boringssl文档 SSL_CTX_set_verify相关部分。

另外,你的证书和TLS版本如何设置的?

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@djtroubleyin
Comment options

@xiaofei0800
Comment options

Answer selected by djtroubleyin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants