GRPC SSL服务器崩溃-C ++

问题描述

我有一个用C ++编写的Grpc服务器,可以完美地用于不安全的连接。

现在我正尝试将连接更改为使用安全连接,因此我将凭据从 grpc :: InsecureServerCredentials()更改为 grpc :: SslServerCredentials(opts) ,但是服务器由于分段错误而崩溃。

这是我的代码(我使用了与grpc示例完全相同的代码):

        grpc::ServerBuilder builder;
        grpc::SslServerCredentialsOptions ssl_opts;

        ssl_opts.pem_root_certs = "";
        grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp = {server_key,server_cert};
        ssl_opts.pem_key_cert_pairs.push_back(pkcp);
        auto server_creds = SslServerCredentials(ssl_opts);

        // builder.AddListeningPort(server_address,grpc::InsecureServerCredentials());
        builder.AddListeningPort("localhost:5000",server_creds);

        ServiceListerImpl service;
        builder.RegisterService(&service);
        builder.RegisterService("foo.test.youtube.com",&service);

        auto server = builder.BuildAndStart();

我检查了server_key,server_cert,它们都有效。

错误堆栈跟踪:

stacktrace:
0x1d6265a SSL_CTX_new :0
0x1bfc98c tsi_create_ssl_server_handshaker_factory_with_options(tsi_ssl_server_handshaker_options const*,tsi_ssl_server_handshaker_factory**) :0
0x1bb828a (anonymous namespace)::grpc_ssl_server_security_connector::InitializeHandshakerFactory() :0
0x1bb8ab5 grpc_ssl_server_security_connector_create(grpc_core::RefCountedPtr<grpc_server_credentials>) :0
0x1bb26ac grpc_ssl_server_credentials::create_security_connector() :0
0x1b6c8bb grpc_server_add_secure_http2_port :0
0x1a24bf0 grpc_impl::SecureServerCredentials::AddPortToServer(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char> > const&,grpc_server*) :0
0x1a3c207 grpc_impl::Server::AddListeningPort(std::__cxx11::basic_string<char,grpc_impl::ServerCredentials*) :0
0x1a2b0fb grpc_impl::ServerBuilder::BuildAndStart() :0

试图通过valgrind获取更多信息:

==26834== Conditional jump or move depends on uninitialised value(s)
==26834==    at 0x1FBCA18: init_openssl() (in /home/ofir)
==26834==    by 0xCF0C47E: __pthread_once_slow (pthread_once.c:116)
==26834==    by 0x227592A: gpr_once_init (in /home/ofir)
==26834==    by 0x1FC1089: tsi_create_ssl_server_handshaker_factory_with_options(tsi_ssl_server_handshaker_options const*,tsi_ssl_server_handshaker_factory**) (in /home/ofir)
==26834==    by 0x1F7CAF9: (anonymous namespace)::grpc_ssl_server_security_connector::InitializeHandshakerFactory() (in /home/ofir)
==26834==    by 0x1F7D324: grpc_ssl_server_security_connector_create(grpc_core::RefCountedPtr<grpc_server_credentials>) (in /home/ofir)
==26834==    by 0x1F76F1B: grpc_ssl_server_credentials::create_security_connector() (in /home/ofir)
==26834==    by 0x1F3113C: grpc_server_add_secure_http2_port (in /home/ofir)
==26834==    by 0x1DEA56D: grpc_impl::SecureServerCredentials::AddPortToServer(std::__cxx11::basic_string<char,grpc_server*) (in /home/ofir)
==26834==    by 0x1E01B26: grpc_impl::Server::AddListeningPort(std::__cxx11::basic_string<char,grpc_impl::ServerCredentials*) (in /home/ofir)
==26834==    by 0x1DF0A78: grpc_impl::ServerBuilder::BuildAndStart() (in /home/ofir)

我正在Ubuntu 20上运行grpc版本1.30.0

我在这里发现了完全相同的问题,但没有评论:https://github.com/grpc/grpc/issues/8796

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)