如何使用LWP :: UserAgent接受自签名证书

编程入门 行业动态 更新时间:2024-10-07 20:30:17
本文介绍了如何使用LWP :: UserAgent接受自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试设置使用HTTPS的node.js服务器.然后,我将在Perl中编写脚本以向服务器发出HTTPS请求,并测量往返的延迟.

I am attempting to set up a node.js server that uses HTTPS. I will then write a scripts in Perl to make a HTTPS request to the server and measure latency of the round trip.

这是我的node.js:

Here is my 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);

密钥/证书的生成如下:

Key/cert generation was done as follows:

openssl genrsa -out rootCA.key 2048 openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem

这是我的Perl脚本:

This is my Perl script:

#!/usr/bin/perl use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => '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服务器,但是对于生成主证书和中间证书是含糊的.

The node.js documentation describes how to set up an HTTPS server but it is vague about generating primary cert and intermediate cert.

medium/netscape/everything-about-creating-an-https-server-using-node-js-2fc5c48a8d4e

推荐答案

要使LWP :: UserAgent忽略服务器证书,请使用以下配置:

To make LWP::UserAgent ignore server certificate use the following configuration:

my $ua = LWP::UserAgent->new; $ua->ssl_opts( SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0 );

更多推荐

如何使用LWP :: UserAgent接受自签名证书

本文发布于:2023-11-28 08:10:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   证书   LWP   UserAgent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!