GRPC CreateChannel() 错误无法获取默认的 pem 根证书

问题描述 投票:0回答:2

我在 Windows 10 上使用 grpc 1.35.0 并按照示例代码此处创建一个 grpc 通道供客户端使用。但我提供了一个根证书来创建通道,否则它会抱怨以下错误。

然后我用 python 版本编写我的客户端,我可以在不提供根证书的情况下创建通道。

那么,这是 grpc bug 还是我误解了示例代码?

GRPC 示例代码

// Create a default SSL ChannelCredentials object.
auto channel_creds = grpc::SslCredentials(grpc::SslCredentialsOptions());
// Create a channel using the credentials created in the previous step.
auto channel = grpc::CreateChannel(server_name, channel_creds);
// Create a stub on the channel.
std::unique_ptr<Greeter::Stub> stub(Greeter::NewStub(channel));
// Make actual RPC calls on the stub.
grpc::Status s = stub->sayHello(&context, *request, response);

我的代码

const std::string SECURE_GRPC_CHANNEL_ADDRESS = <MY_SERVER>;

class GrpcChannel
{
    GrpcChannel()
    {
        auto ca_cert = get_file_contents(cacert_path);
        SslCredentialsOptions options = { ca_cert, "", "" };
        auto channel_creds = SslCredentials(options);
        channel_ = grpc::CreateChannel(SECURE_GRPC_CHANNEL_ADDRESS, channel_creds);            
    }
c++ ssl grpc grpc-python
2个回答
3
投票

原来是grpc文档问题,grpc-core C++ for windows不支持默认的根证书,需要用户指定一个。请参阅此处


0
投票

当我在 Windows 10 上使用 Google Text-To-Speech API 时,我遇到了类似的问题。gRPC 抱怨无法在非 Windows 文件夹中找到 pem 文件。 要解决此问题,以下步骤可能会有所帮助:

  • https://pki.google.com/roots.pem
  • 下载 Google 的 root.pem
  • 添加名为“GRPC_DEFAULT_SSL_ROOTS_FILE_PATH”的环境变量并将其值设置为下载文件的路径(包括文件名)
© www.soinside.com 2019 - 2024. All rights reserved.