【问题标题】:How to access a public certificate in a node.js azure function如何在 node.js 天蓝色函数中访问公共证书
【发布时间】:2020-02-19 23:56:46
【问题描述】:
我已通过
将公共证书导入我的 azure 函数
我的 Azure 函数应用服务 -> 平台功能选项卡 -> SSL ->
公钥证书 (.cer)
现在如何通过我的 azure 函数访问它?
我试过研究这个但唯一的results I can find are for using a private certificate
目前为了解决这个问题,我告诉节点通过设置 process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 来忽略我正在集成的端点的自签名证书
我想改用证书。
编辑:
我最终将证书链添加到一个文件夹并从我的应用程序的文件夹中读取文件。仍然没有回答关于如何使用天蓝色上传证书的问题
const https = require('https');
https.globalAgent.options.ca = [
fs.readFileSync(__dirname + '/certs/master.pem'),
fs.readFileSync(__dirname + '/certs/root.pem')
];
【问题讨论】:
标签:
node.js
ssl-certificate
azure-functions
【解决方案1】:
您可以通过使用证书指纹的值配置应用设置 WEBSITE_LOAD_CERTIFICATES 来获取上传到 TLS/SSL 设置的证书。
以下是您可以使用 node.js(使用 npm 包“win-ca”)以编程方式获取证书的代码。
const http = require('http');
const ca = require('win-ca');
// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
// Set a response type of plain text for the response
res.writeHead(200, { 'Content-Type': 'text/plain' });
// certificate fetch
let certificates = []
// Fetch all certificates in PEM format from My store
ca({
format: ca.der2.pem,
store: ['My'],
ondata: crt => certificates.push(crt)
})
// Send back a response and end the connection
res.end("Certificate count under 'My' store is" + certificates.length);
});
let port = process.env.PORT || 3000;
// Start the server on port 3000
app.listen(port);
console.log('Node server running on port ' + port);
您可以更改您想要证书的存储参数,例如:Root、My、CertificationAuthority、AuthRoot。
【解决方案2】:
我在documentation page 上创建了一个问题,他们更新它说您只能使用 c# 加载存储在 azure 中的 SSL 证书
如果您不使用 c#,则必须将 ssl 证书与您的代码一起存储在一个文件夹中,并从文件中读取它,如我的示例所示。