【问题标题】:gRPC: Generate certificateChainFile and privateKeyFile to make TLS/SSL workgRPC:生成 certificateChainFile 和 privateKeyFile 以使 TLS/SSL 工作
【发布时间】:2018-05-19 02:59:43
【问题描述】:

我想在客户端和服务器之间建立 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);

我只需要 终端命令 来生成 certChainFileprivateKeyFile(in .pem) 以将这些文件传递给服务器代码,如上所示.

【问题讨论】:

    标签: java ssl openssl keytool


    【解决方案1】:

    我只需要终端命令来生成 certChainFile 和 privateKeyFile

    openssl req -x509 -newkey rsa:1024 -keyout ./testkey.pem -out ./testcert.crt -days 999 -subj "/CN=localhost"
    

    此命令生成一个 RSA 密钥和一个自签名证书。

    但你需要的不止这些。

    1. 默认情况下,SSL 检查公用名 (CN) 是否等于主机名。因此,您需要生成具有 CN=localhost 的证书

    2. 客户端必须信任服务器的证书,所以需要将证书导入到客户端的信任库中(虽然我不知道如何为客户端配置信任库,我会留给你) .

    【讨论】:

      猜你喜欢
      • 2017-12-07
      • 2021-10-03
      • 2023-02-03
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 2018-06-04
      • 2018-11-14
      • 1970-01-01
      相关资源
      最近更新 更多