当前我正在为gRPC客户端设置通道身份验证,如下所示:
std::shared_ptr<grpc::ChannelCredentials> channel_creds;
auto metadata = grpc::ChannelArguments();
// ...
grpc::SslCredentialsOptions sslOpts{};
sslOpts.pem_root_certs = // PEM with the Root CA cert's public key
sslOpts.pem_cert_chain = // PEM for client cert's public key
sslOpts.pem_private_key = // PEM for client cert's private key
channel_creds = grpc::SslCredentials(sslOpts);
metadata.SetSslTargetNameOverride(mbServerCertSubjectName.second.get());
// ...
grpc::CreateCustomChannel(addr_str, channel_creds, metadata);
这几乎是完美的,但我想禁用证书名称验证:我只想接受任何东西,只要它链接到我提供的pem_root_certs
。
如果我可以创建一个TlsChannelCredentialsOptions结构,其grpc_tls_server_verification_option字段设置为grpc_tls_SKIP_HOSTNAME_verification,这似乎是可以实现的,但TlsCredentialsOption的接口与SslCredentialsOptions完全不同,我不知道如何将其设置为基于我在这里提供给sslOpts的PEM文件进行身份验证。
如何将我想要的逻辑转换为TlsChannelCredentialsOptions?
试试这个:
grpc::ChannelArguments gargs;
gargs.SetSslTargetNameOverride("domian name you want to ignore");
client client(grpc::CreateCustomChannel("ipverson:xxx.xxx.xxx.xxx:port", ssl_creds, gargs));