#grpc节点客户端允许签名证书

时间:2020-05-30 20:01:08

标签: grpc grpc-node

我在服务器上具有一个自签名的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没有打电话。

有人有什么线索吗?

1 个答案:

答案 0 :(得分:0)

在检查了多个github问题并测试了2天后, 下面的代码有效。 关键是,实际host:port是目标,可以是localhost。但我们需要使用实际生成的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',
});