【问题标题】:gRPC in CPP providing TLS supportCPP 中的 gRPC 提供 TLS 支持
【发布时间】:2015-12-23 21:10:56
【问题描述】:

在 CPP 中使用 TLS 的 gRPC 服务器的任何示例?

我正在尝试构建一个 gRPC 应用程序。如果客户端想要通过 TLS 而不是 TCP 连接,服务器应该提供 TLS 支持。

这是我的服务器

void RunServer() {
    std::string server_address("0.0.0.0:50051");
    GreeterServiceImpl service;
    ServerBuilder builder;
    std::shared_ptr<ServerCredentials> creds;

    if(enable_ssl)
    {
            grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp ={"a","b"};
            grpc::SslServerCredentialsOptions ssl_opts;
            ssl_opts.pem_root_certs="";
            ssl_opts.pem_key_cert_pairs.push_back(pkcp);
            creds = grpc::SslServerCredentials(ssl_opts);
    }
    else
            creds=grpc::InsecureServerCredentials();
    // Listen on the given address without any authentication mechanism.
    builder.AddListeningPort(server_address, creds);
    // Register "service" as the instance through which we'll communicate with
    // clients. In this case it corresponds to an *synchronous* service.
    builder.RegisterService(&service);
    // Finally assemble the server.
    std::unique_ptr<Server> server(builder.BuildAndStart());

错误: 未定义对 grpc::SslServerCredetials(grpc::ssl_opts) 的引用 我已经包含了所有必要的文件..

【问题讨论】:

  • 他可能指的是加密的东西而不是线程本地存储。
  • 耶!不是关于线程库,而是关于 TLS 的使用方式。

标签: c++ grpc


【解决方案1】:

您的代码看起来不错。如果你是从examples/cpp/helloworld适配的,需要在Makefile中把-lgrpc++_unsecure改成-lgrpc++

为了他人的利益,可以在https://github.com/grpc/grpc/blob/master/test/cpp/interop/server_helper.cc#L50找到使用 tls/ssl 代码的示例

【讨论】:

  • lib/libgrpc.so.0.11.0.0:未定义引用 EVP_DigestVerifyInit' lib/libgrpc.so.0.11.0.0: undefined reference to SSL_get0_next_proto_negotiated' /lib/libgrpc.so.0.11.0.0:未定义引用 SSL_get_servername' lib/libgrpc.so.0.11.0.0: undefined reference to SSL_set_SSL_CTX' lib/libgrpc.so .0.11.0.0: undefined reference to `EVP_DigestVerifyFinal' 等。得到这些未定义的引用,不知道为什么。
猜你喜欢
  • 2018-04-26
  • 1970-01-01
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多