我有一个gRPC客户机/服务器组合,它使用SSLCredentials方法加密通信。我试图在服务器端(用C++编写)检索客户端的SSL证书,以便区分调用服务器的不同客户端。
到目前为止,我只找到了一个围棋的例子,这似乎很粗略,但在C++方面,我只能找到只提供下面信息的AuthMetadataProcessor过载,这不是我所需要的。
:authority = localhost:50051
:path = /API.GameDatabase/saveData
grpc-accept-encoding = identity,deflate,gzip
grpc-encoding = identity
user-agent = grpc-csharp/1.0.1 grpc-c/1.0.1 (linux; chttp2)
Dispatch value: "/API.GameDatabase/saveData"这是可能的,还是我必须自己发送这种元数据?
发布于 2017-04-19 03:49:57
如果您决定使用此类拦截器从处理程序的业务逻辑中提取身份验证/授权逻辑,则可以在响应处理程序的响应处理程序中使用AuthContext检索客户端的SSL证书。context.html
如果存在或不存在CN,则将X509的对等标识属性设置为SAN。但是,您可以通过使用8h.html#ad46c3fd565d6a24eeb25d1fdc342cb28属性访问完整的证书,该属性在AuthContext中填充。
发布于 2017-06-02 08:52:09
在Julien的回答的帮助下,我能够让它开始工作,我接受了他的答案,但是给出了下面的代码示例:
grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp =
{"<key>", "<cert>"};
// The client must be force to present a cert every time a call is made,
// else it will only happen once when the first connection is made.
// The other options can be found here:
// http://www.grpc.io/grpc/core/grpc__security__constants_8h.html#a29ffe63a8bb3b4945ecab42d82758f09
grpc::SslServerCredentialsOptions
ssl_opts(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY);
ssl_opts.pem_root_certs = "<CA cert>";
ssl_opts.pem_key_cert_pairs.push_back(pkcp);
std::shared_ptr<grpc::ServerCredentials> sslCredentials =
grpc::SslServerCredentials(ssl_opts);
builder.AddListeningPort("<server address>", sslCredentials);有两个选项可以检索ssl证书:
我希望这能帮到你。
https://stackoverflow.com/questions/42718957
复制相似问题