我想在客户端和服务器之间建立 tls/ssl 连接(不是相互的,一种方式)。
这是我的设置:
服务器:
Server server = ServerBuilder.forPort(8443)
// Enable TLS
.useTransportSecurity(certChainFile, privateKeyFile)
.addService(new GreetingServiceImpl())
.build();
客户端
// With server authentication SSL/TLS
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8443)
.build();
GreetingServiceGrpc.GreetingServiceBlockingStub stub =
GreetingServiceGrpc.newBlockingStub(channel);
我只需要终端命令来生成certChainFile和privateKeyFile(in .pem)来将这些文件传递给服务器代码,如上所示.
最佳答案
All I need is Terminal commands to generate certChainFile and privateKeyFile
openssl req -x509 -newkey rsa:1024 -keyout ./testkey.pem -out ./testcert.crt -days 999 -subj "/CN=localhost"
此命令生成一个 RSA key 和一个自签名证书。
但您需要的不止于此。
默认情况下,SSL 检查通用名称 (CN) 是否等于主机名。因此,您需要生成具有 CN=localhost 的证书
客户端必须信任服务器的证书,因此需要将证书导入到客户端的信任库中(虽然我不确定如何为客户端配置信任库,但我会留给你) .
关于java - gRPC : Generate certificateChainFile and privateKeyFile to make TLS/SSL work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47653799/