在CPP中使用TLS的gRPC服務器的任何示例?CPP中的gRPC提供TLS支持
我想構建一個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可以使用的方式。 –