2016-04-29 54 views
4

因此,我继承了一个运行在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不能够返回数据。

回答

1

很多周围挖后,我偶然发现了这个评论: https://unix.stackexchange.com/a/255404

因为我在CentOS 7,禁用firewalld的伎俩我。我没有意识到改变。从某种意义上说,joelnb在回答评论中检查iptables的注释是正确的方向(谢谢!)。请检查您的操作系统的防火墙,并尝试禁用它,看看它是否有助于解决问题。如果是的话,那么你可以继续为你的端口配置一个规则。

为CentOS 7,打开firewalld端口: centos 7 - open firewall port

我希望这可以帮助别人。

0

我怀疑你没有Vagrantfile中的端口转发设置,因为如果我没有/如果没有在该端口上监听的话,我会得到确切的错误。你的Vagrantfile看起来像下面那样吗? forwarded_port部分是重要的一点。

Vagrant.configure(2) do |config| 
    config.vm.box = "ubuntu/trusty64" 
    config.vm.network "forwarded_port", guest: 3001, host: 3001 
end 

否则可否请您发布您的Vagrantfile,我会修改我的答案。

+0

嗨,我已经添加了我的流浪文件。我转发了端口3000和3001,但目前只使用3001进行SSL。 – evkwan

+0

好的,虚拟机中'sudo iptables -L'的输出是什么?而且你也许希望检查'vagrant up'的输出 - 因为你有端口auto_correct它可以分配不同的端口,如果在3001上有其他的监听(尽管这是不太可能的)。 – joelnb

+0

因为我只运行应用程序进行测试,所以我实际上禁用了vm上的iptables。 – evkwan

相关问题