从 Node.JS 向 DocuSign 发送请求时强制设置 TLS 版本 1.2

Force setting TLS vresion 1.2 when sending out a request from Node.JS to DocuSign

我们无法通过公司代理将请求从我们的 Node.JS 应用程序发送到 DocuSign(demo.docusign.net 和帐户-d.docusign.com)/我们已经确定问题是可能是因为 DocuSign 服务器只接受 TLS 1.1 和 1.2。

有什么方法可以强制将请求的 TLS 版本设置为 TLS 1.2?如果有任何请求模块(axios、got、request)支持这个,如果有代码示例,那将非常有帮助。

提前致谢!

您可以通过设置 tls.DEFAULT_MAX_VERSION 和 tls.DEFAULT_MIN_VERSION 来指定要使用的最小和最大 TLS 版本。

这应该适用于任何使用核心 Node.js TLS 代码的模块。

例如:

const axios = require("axios");
const tls = require("tls");

tls.DEFAULT_MIN_VERSION = "TLSv1.1";
tls.DEFAULT_MAX_VERSION = "TLSv1.3";

async function testTLSVersion() {
    let response = await axios({ url: "https://httpbin.org/get"});
    console.log("TLS Version of connection:", response.request.connection.getProtocol());
}

testTLSVersion();

这里我们连接到 https 服务器并记录连接的 TLS 版本。您可以尝试使用 MIN 和 MAX TLS 版本,看看它如何影响所使用的协议。