【发布时间】:2018-05-19 15:15:59
【问题描述】:
我正在尝试设置使用 HTTPS 的 node.js 服务器。然后我将在 Perl 中编写一个脚本来向服务器发出 HTTPS 请求并测量往返的延迟。
这是我的 node.js:
var express = require('express');
var https = require('https');
var fs = require('fs');
var key = fs.readFileSync('encrypt/rootCA.key');
var cert = fs.readFileSync('encrypt/rootCA.pem');
// This line is from the Node.js HTTPS documentation.
var options = {
key: key,
cert: cert
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world - https\n");
}).listen(8088);
密钥/证书生成如下:
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
这是我的 Perl 脚本:
#!/usr/bin/perl
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'https://127.0.0.1:8080');
my $res = $ua->request($req);
if ($res->is_success) {
print $res->as_string;
} else {
print "Failed: ", $res->status_line, "\n";
}
返回错误:
Failed: 500 Can't verify SSL peers without knowing which Certificate Authorities to trust
node.js 文档描述了如何设置 HTTPS 服务器,但对生成主证书和中间证书的内容含糊不清。
https://medium.com/netscape/everything-about-creating-an-https-server-using-node-js-2fc5c48a8d4e
【问题讨论】:
-
所以您的问题实际上是“如何配置 LWP::UserAgent 以接受 HTTPS 的自签名证书?”
-
实际上是的。你知道怎么做吗?
-
我明白了。感谢@amon 为我指明了正确的方向
标签: node.js perl networking https lwp-useragent