使用C++实现的gRPC提供TLS支持

6

有没有使用TLS的gRPC服务器CPP示例?

我正在尝试构建一个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::ssl_opts,未定义引用grpc::SslServerCredentials() 我已经包含了所有必要的文件..


2
他可能是指加密问题而不是线程本地存储。 - Ronny Brendel
嗨!这不是关于线程库的问题,而是关于如何使用TLS的方式。 - JS_SJC
1个回答

2

lib/libgrpc.so.0.11.0.0: 对“EVP_DigestVerifyInit”的引用未定义 lib/libgrpc.so.0.11.0.0: 对“SSL_get0_next_proto_negotiated”的引用未定义 /lib/libgrpc.so.0.11.0.0: 对“SSL_get_servername”的引用未定义 lib/libgrpc.so.0.11.0.0: 对“SSL_set_SSL_CTX”的引用未定义 lib/libgrpc.so.0.11.0.0: 对“EVP_DigestVerifyFinal”的引用未定义 等等...出现这些未定义的引用,不知道为什么。 - JS_SJC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接