关于node.js:Azure AMS节点js应用无法建立TLS 1.2连接

Azure AMS node js app failing to make a TLS 1.2 connection

我有一个节点js应用程序,在Azure AMS上作为移动服务运行。 我一直在使用请求库对外部服务器进行HTTPS get / post api调用。 直到几天前外部实体决定不再支持TLS 1.0及更低版本时,一切都可以正常工作。

我想知道是否有人知道Azure AMS阻止/失败与外部主机的TLS 1.1 / 1.2通信的任何已知问题? 该主机使用DigiCert颁发的有效SSL证书。

在我的代码内部,我已经尝试了一些事情来明确地告诉nodejs使用TLS 1.1 / 1.2,但这没有用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var httpRequest = require("request"),
https = require('https');

https.globalAgent.options.secureProtocol = 'TLSv1_2_method'; // Instructing to use TLS 1.2
....


httpRequest.post('https://external-api-url.com', {
    'json': true,
    'body': params,
    'timeout': 20000,
    'jar': false,
    'headers': {
       "Arr-Disable-Session-Affinity": true
    }

}, function(err, response, body) {
    // Code to handle response.
});

除了globalAgent之外,我还尝试从agentOptions以及直接在options对象中设置secureProtocol。 这些方法均无效。

任何帮助将不胜感激。

谢谢。


您的问题是Azure移动服务上NodeJS版本的原因。

Azure移动服务上的NodeJS版本是v0.8.28。 您可以在Azure Kudu Env页面.scm.azure-mobile.net / Env"> https:// .scm.azure-mobile.net / Env的" AppSettings"部分中看到它,如下图所示 。

enter image description here

但是,NodeJS从0.11.6版本开始将TLS 1.1 / 1.2添加到secureProtocol列表中,如下图所示。

enter image description here

因此,当外部实体决定停止支持TLS 1.0时,您的nodejs应用程序将无法正常工作。

但是您可以使用具有Https API支持TLS的NodeJS示例或具有API支持TLS / SSL协议的请求模块来设置options.key和options.cert来执行此操作。
请参考https://nodejs.org/docs/v0.8.28/api/https.html#https_https_request_options_callback和https://github.com/request/request#tlsssl-protocol。

例:

1
2
3
4
5
6
7
8
var fs = require('fs')
    , path = require('path')
    , certFile = path.resolve(__dirname, 'ssl/client.crt')
    , keyFile = path.resolve(__dirname, 'ssl/client.key')
    , request = require('request');

https.globalAgent.options.cert = certFile;
https.globalAgent.options.key = keyFil;

最好的祝福。