现在,使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密钥的方法:
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
我的问题:为什么没有显式服务器的证书客户端无法工作?谢谢!
答案 0 :(得分:0)
我不熟悉C ++,但是-盯着您的代码-我怀疑:
grpc::SslCredentialsOptions()
对应于Go的grpc.WithInsecure()
。如果正确,则此方法不使用TLS。我认为您是指此: https://grpc.io/docs/guides/auth/#using-client-side-ssl-tls