c++ - GRPC CreateChannel() 错误无法获取默认 pem 根证书
问题描述
我在 Windows 10 上使用 grpc 1.35.0 并在此处遵循示例代码来创建供客户端使用的 grpc 通道。但是我提供了一个根证书来创建频道,否则它会抱怨以下错误。
然后我用 python 版本编写我的客户端,我可以在不提供根证书的情况下创建通道。
那么,这是一个 grpc 错误还是我误解了示例代码?
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);
}
解决方案
原来是 grpc 文档问题,用于 windows 的 grpc-core C++ 不支持默认根证书,需要用户指定一个。请参考这里。
推荐阅读
- laravel - Laravel 文件管理器独立 iframe 输入
- cmd - 通过命令行在 Spoon (Pentaho) 转换中传递参数
- google-cloud-dataprep - 将云数据准备迁移到其他帐户
- r - 在 R 中为 SQL Server R 默认加载的包
- amazon-web-services - AWS - 如何限制用户删除或修改他人创建的 lambda 函数
- typescript - AngularFire2 的类型安全使用
- batch-file - 替换没有大写和空格的csv中的文本
- dart - 如何在 Flutter 中将 RefreshIndicator 与 FutureBuilder 一起使用?
- java - 无法在 Android WebView 中设置 HttpURLConnection 标头
- python - “NoSuchWindowException:没有这样的窗口:窗口已经关闭”,同时通过 Python3 使用 Selenium 和 WebDriver 切换选项卡