【问题标题】:Redis TLS configuration with Nodejs使用 Nodejs 配置 Redis TLS
【发布时间】:2020-06-24 00:48:47
【问题描述】:

我正在使用 ioRedis 节点包将我的节点 js 应用程序连接到受 TLS 保护的 redis 服务器。我使用的 Redis 版本是 Redis 6.0。我的服务器使用证书运行良好,但从节点应用程序连接时出现错误。

 Redis({
          host: "localhost",
          port: 6379,
          tls: {
            key: fs.readFileSync('./redis.key'),
            cert: fs.readFileSync('./redis.crt'),
            maxVersion: 'TLSv1.3',
            minVersion: 'TLSv1.3',
            ca: [fs.readFileSync('./redis.pem')]
          }
        })

nodejs应用端的错误是

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
   Error: read ECONNRESET
            at TCP.onStreamRead (internal/stream_base_commons.js:205:27)

尝试从 nodejs 应用程序连接时服务器出错

17:29:44.295 # Error accepting a client connection: error:1408F10B:SSL routines:ssl3_get_record:wrong version number

目的只是为了有一个具有TLS安全性的redis连接。

【问题讨论】:

标签: node.js ssl redis ioredis


【解决方案1】:

我也在做同样的事情,我尝试了这种方法。

const redis = require('redis');
const fs = require('fs');

const client = redis.createClient({
    host: '<hostname>',
    port: <port>,
    tls: {}
});

而不是传递证书密钥,一切都尝试将 tls 作为空对象传递。 这种方法的指南如下。 https://docs.upstash.com/docs/howto/connectwithtls

【讨论】:

    【解决方案2】:

    我认为您需要指定需要读取文件的编码方式

    const redis = require('ioredis');
    const fs = require('fs');
    
    const client = redis.createClient({
        host: 'hostName',
        port: 'port',
        tls: {
           key: fs.readFileSync('pathToFile', 'ascii')  /* this is usually the encoding */
           cert: fs.readFileSync('pathToFile', 'ascii')
           ca: fs.readFileSync('pathToFile', 'ascii')  /* this is usually the encoding */
        }
    
    })
    

    查找更多信息here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      相关资源
      最近更新 更多