【问题标题】:using correct SSL protocol when using client from node-json-rpc library使用 node-json-rpc 库中的客户端时使用正确的 SSL 协议
【发布时间】:2018-08-22 00:55:06
【问题描述】:

我正在使用这个库 https://www.npmjs.com/package/node-json-rpc 对 https 服务器进行客户端调用以公开 RPC api。

但是,当我运行代码时,我得到了这个错误

Error: SSLv3 methods disabled
    at new SecureContext (_tls_common.js:50:20)
    at Object.createSecureContext (_tls_common.js:89:13)
    at Object.connect (_tls_wrap.js:1120:48)
    at Agent.createConnection (https.js:119:22)
    at Agent.createSocket 

我的代码是

var rpc = require('node-json-rpc');

var options = {
      port: 443,
      host: 'mynode',
      path: '/rpc',
      strict: true,
      ssl: {
        // protocol: 'TLSv1.2'
      }

    };

this.client = new rpc.Client(options);

this.client.call(
          {"jsonrpc": "2.0", "method": "txpool_content", "params": [], "id": 1},
          function (err, res) {
            if( err ) {
                resolve(null);
            }
            else {
                resolve(res.result);
            }
          }
        );

我确保这个 api 可以从 Postman 使用这个端点 https://mynode/rpc

我了解此协议 SSLv3 可能对节点 js 被禁用,但我在文档中找不到任何其他选项。 我没有证书和密钥。

【问题讨论】:

  • 这个库是古老的,很久没更新了,在GitHub上好像也没有了。我建议您重写代码以直接使用 Node 的 https 模块。

标签: node.js json-rpc


【解决方案1】:

来自图书馆代码(node_modules/node-json-rpc/lib/rpcclient.js):

if (conf.ssl) {
  options.servername = conf.ssl.sniName || 'RPC-Server';
  options.secureProtocol = conf.ssl.protocol || 'SSLv3_client_method';
  ...

因此,您似乎可以在选项中设置{ ssl: { protocol: 'something' } }

something 是什么?让我们浏览一下 Node.js 文档:

https://nodejs.org/api/https.html:

还接受来自tls.connect() 的以下附加选项:... secureProtocol ...

https://nodejs.org/api/tls.html#tls_tls_connect_options_callback:

secureProtocol <string> 要使用的可选 SSL 方法。可能的值被列为SSL_METHODS,使用函数名作为字符串。例如,'TLSv1_2_method' 强制 TLS 版本 1.2

他们提供的示例是一个很好的起点,但该页面还链接到可用 SSL 方法的完整列表:https://www.openssl.org/docs/man1.1.0/ssl/ssl.html#Dealing-with-Protocol-Methods

【讨论】:

  • 非常感谢,我用TLSv1_2_client_method解决了这个问题
猜你喜欢
  • 1970-01-01
  • 2018-04-21
  • 2015-09-25
  • 1970-01-01
  • 2021-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-07
相关资源
最近更新 更多