SSLSSL示例表明,我可以使用默认的C++凭据来确保连接是加密的(基于用于验证服务器端证书的设备证书存储区)。具体代码(来自https://grpc.io/docs/guides/auth/)是:
// 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);不幸的是,该代码不允许我的应用程序连接到服务器。只有当我提供要设置为有效证书颁发机构密钥(如Baltimore)的SslCredentialsOptions的pem_root_certs字段时,它才起作用。
有没有一种方法可以像在示例代码中那样工作,以便使用设备自己的证书存储来验证服务器证书?
发布于 2020-10-29 04:07:30
如果您在iOS上使用gRPC-Objc,则可以将GRPCCallOptions.transportType设置为GRPCTransportTypeChttp2BoringSSL以使用ssl通道。要使用设备的证书,您只需将其传递给GRPCCallOptions.PEMRootCertificates。
https://github.com/grpc/grpc/blob/master/src/objective-c/GRPCClient/GRPCCallOptions.h#L135-L149
https://stackoverflow.com/questions/64564863
复制相似问题