因此,我继承了一个运行在Vagrant框中的Nodes.js应用程序。通过SSL/TLS连接访问Vagrant上的Node.js应用程序
我将应用程序绑定到“0.0.0.0”,并且它在securekey文件夹中有自己的server.key和certs。
var https = require('https');
var fs = require('fs');
var ssl_options = {
key: fs.readFileSync('./securekey/server.key'),
cert: fs.readFileSync('./securekey/server.crt'),
ca: fs.readFileSync('./securekey/ca.crt')
};
https.createServer(ssl_options, app).listen(3001, '0.0.0.0');
当我运行应用程序,我希望能够通过URL https://localhost:3001
访问它在我的Windows(流浪是我的Windows PC上运行)浏览器,但我得到“安全连接失败”在Mozilla上。
我没有使用Cygwin尝试这个在Windows PC:
$ openssl s_client -host 127.0.0.1 -port 3001
CONNECTED(00000003)
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 316 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1461923745
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
而且
$ curl -v -k 'https://localhost:3001'
* STATE: INIT => CONNECT handle 0x6000574a0; line 1103 (connection #-5000)
* Rebuilt URL to: https://localhost:3001/
* Added connection 0. The cache now contains 1 members
* Trying 127.0.0.1...
* STATE: CONNECT => WAITCONNECT handle 0x6000574a0; line 1156 (connection #0)
* Connected to localhost (127.0.0.1) port 3001 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000574a0; line 1253 (connection #0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x6000574a0; line 1267 (connection #0)
* Unknown SSL protocol error in connection to localhost:3001
* Curl_done
* Closing connection 0
* The cache now contains 0 members
curl: (35) Unknown SSL protocol error in connection to localhost:3001
但是当流浪VM终端上运行这些命令返回的成功连接!
我需要做些什么来让我的Windows PC /浏览器接受应用程序的证书,以便我可以从Mozilla Firefox访问应用程序?既然它已经有server.key和certs,当然我不需要为应用程序再次生成我自己的密钥?
编辑: 这里是我的流浪文件:
Vagrant.configure(2) do |config|
config.vm.box = "centos7"
config.vm.network "forwarded_port", guest: 3000, host: 3000, auto_correct: true
config.vm.network "forwarded_port", guest: 3001, host: 3001, auto_correct: true
end
我只得到了端口转发configs..the其余默认。
而当应用程序是在流浪运行参数,netstat显示该端口监听连接
$ netstat -an | grep 3001
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING
当我在浏览器上访问https://localhost:3001,我看到:
netstat -an | grep 3001
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING
TCP 127.0.0.1:3001 127.0.0.1:49651 ESTABLISHED
TCP 127.0.0.1:49651 127.0.0.1:3001 ESTABLISHED
似乎像端口连接没问题,但是vm不能够返回数据。
嗨,我已经添加了我的流浪文件。我转发了端口3000和3001,但目前只使用3001进行SSL。 – evkwan
好的,虚拟机中'sudo iptables -L'的输出是什么?而且你也许希望检查'vagrant up'的输出 - 因为你有端口auto_correct它可以分配不同的端口,如果在3001上有其他的监听(尽管这是不太可能的)。 – joelnb
因为我只运行应用程序进行测试,所以我实际上禁用了vm上的iptables。 – evkwan