【问题标题】:#grpc node client allow signed certificate#grpc 节点客户端允许签名证书
【发布时间】:2020-05-30 20:01:08
【问题描述】:

我在服务器上有一个自签名的 grpc 服务,并让它在带有 dart 客户端的 dart 服务器上工作。 但我不知道如何绕过或允许节点客户端的自签名证书.. 我试过这个:

const sslCreds = await grpc.credentials.createSsl(
    fs.readFileSync('./ssl/client.crt'),
    null, // privatekey
    null, // certChain
    {
      checkServerIdentity: function(host, info) {
  console.log('verify?', host, info);
  if (
    host.startsWith('127.0.0.1') ||
    host.startsWith('logs.example.com')
  ) {
    return true;
  }
  console.log('verify other?', host);
  return true;
},
    },
  );

  // sslCreds.options.checkServerIdentity = checkCert;

  const gLogClient = new synagieLogGrpc.LoggerClient(
    'host:port',
    sslCreds,
  );

但是当我打电话时,我的验证 checkServerIdentity 没有调用。

有人知道吗?

【问题讨论】:

    标签: grpc grpc-node


    【解决方案1】:

    在检查了多个 github 问题并测试了 2 天后, 下面的代码有效。 关键点是,实际的主机:端口是目的地,可能是本地主机。但我们需要用实际生成的 ssl 域覆盖 ssl 目标名称。

    对于 tls 生成的示例: https://github.com/grpc/grpc-node/issues/1451

    const host = 'localhost';
    const port = 8088;;
    const hostPort = `${host}:${port}`;
    const gLogClient = new synagieLogGrpc.LoggerClient(hostPort, sslCreds, {
      'grpc.ssl_target_name_override': 'actual_tlsdomain.example.com',
    });
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 2018-09-21
      • 2013-07-14
      • 2022-01-07
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多