1

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

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

在我的代码中,我已经尝试了几件事来明确告诉 nodejs 使用 TLS 1.1 / 1.2,但这没有用。

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。这些方法都不起作用。

任何帮助将不胜感激。

谢谢。

4

1 回答 1

2

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

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

在此处输入图像描述

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

在此处输入图像描述

因此,当外部实体决定停止支持 TLS 1.0 时,您的 nodejs 应用程序无法运行。

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

例子:

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;

此致。

于 2015-09-10T08:19:50.210 回答