我现在让 SSL 加密的服务器和客户端工作的唯一方法是明确地向客户端提供服务器的证书。如何让服务器在不直接在客户端代码中设置证书的情况下向客户端提供证书?
我正在使用 C++ gRPC。当我创建 gRPC 服务器时,我设置了它的自签名证书和私钥:
grpc::SslServerCredentialsOptions sslServerOptions;
grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp;
pkcp.private_key = serverPrivateKey;
pkcp.cert_chain = serverCertChain;
sslServerOptions.pem_key_cert_pairs.push_back( pkcp );
sslServerOptions.pem_root_certs = “”;
grpc::SslServerCredentials( sslServerOptions );
在客户端,如果我明确地将 pem_root_certs 设置为服务器的证书——它工作正常
grpc::SslCredentialsOptions sslChannelOptions;
sslChannelOptions.pem_root_certs = serverCertChain;
sslChannelOptions.pem_cert_chain = “”;
sslChannelOptions.pem_private_key = “”;
grpc::SslCredentials( sslChannelOptions );
但是如果我使用 GRPC 示例中的代码:
grpc::SslCredentials( grpc::SslCredentialsOptions() );
我收到这个错误:
E0520 15:24:31.189310128 17046 ssl_transport_security.c:921] Handshake
failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL
routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED.
Translate to Communication exception: Exception encountered while
receiving response from localhost:10000, with status 14, message: Connect
Failed
unknown file: Failure
C++ exception with description "Exception encountered while receiving
response from localhost:10000, with status 14, message: Connect Failed"
thrown in the test body.
这是我创建 SSL key 的方式:
openssl req -new -key server.key -out server_selfsigned.csr
"/O=MyCompany/CN=localhost"
openssl x509 -req -days 1825 -in server_selfsigned.csr -signkey
server.key -set_serial 02 -out server_selfsigned.pem
我的问题:为什么客户端在没有显式服务器证书的情况下无法工作?谢谢!
我是一名优秀的程序员,十分优秀!