2016-07-06 28 views
1

我给自己买了从证书颁发机构此文件:Node.js的HTTPS PEM错误:错误:0906D06C:PEM套路:PEM_read_bio:没有启动线

  • domain.com.p7b
  • domain.com.crt
  • domain.com.ca束

我想这一点代码:

var express = require('express'); 
var app = express(); 
var fs = require("fs"); 
var https = require('https'); 

var privateKey = fs.readFileSync('domain.com.p7b').toString(); 
var certificate = fs.readFileSync('domain.com.crt').toString(); 
var ca_bundle = fs.readFileSync('domain.com.ca-bundle').toString(); 

var credentials = { key: privateKey, 
        ca : ca_bundle, 
        cert: certificate}; 


https.createServer(credentials,app).listen(8080, function() { 
    console.log('Example app listening on port 8080!'); 
}); 

启动脚本后,我得到以下错误:

(err):  at Object.createSecureContext (_tls_common.js:87:19) 
(err):  at Server (_tls_wrap.js:721:25) 
(err):  at new Server (https.js:17:14) 
(err):  at Object.exports.createServer (https.js:37:10) 
(err):  at Object.<anonymous> (/utec_temp/https/web.js:27:7) 
(err):  at Module._compile (module.js:435:26) 
(err):  at Object.Module._extensions..js (module.js:442:10) 
(err):  at Module.load (module.js:356:32) 
(err):  at Function.Module._load (module.js:311:12) 
(err): Error: error:0906D06C:PEM routines:PEM_read_bio:no start line 
(err):  at Error (native) 
(err):  at Object.createSecureContext (_tls_common.js:87:19) 
(err):  at Server (_tls_wrap.js:721:25) 
(err):  at new Server (https.js:17:14) 
(err):  at Object.exports.createServer (https.js:37:10) 
(err):  at Object.<anonymous> (/utec_temp/https/web.js:27:7) 
(err):  at Module._compile (module.js:435:26) 
(err):  at Object.Module._extensions..js (module.js:442:10) 
(err):  at Module.load (module.js:356:32) 
(err):  at Function.Module._load (module.js:311:12) 

,你可以在互联网上使用自签名证书谷歌大部分的例子,但是当我在一个真实的环境中工作发生了什么?

我少的代码开发工作与自签名密钥,如下面的例子:

https://stackoverflow.com/a/24283204/3957754

我研究,我发现这一点:

https://www.namecheap.com/support/knowledgebase/article.aspx/9705/0/nodejs

http://www.backwardcompatible.net/155-Setting-up-real-SSL-Nodejs-Express

Node.js https pem error: routines:PEM_read_bio:no start line

但我无法更正错误。

我也降低到一个文件:

var credentials = {cert: certificate};  

和错误是一样的。所以我认为,也许从Windows到UNIX的格式错误。我使用dos2unix工具,错误是一样的。

我的节点版本是4.4.7

任何帮助表示赞赏。

提前致谢!

UPDATED

我在答案部分作品node.js的答案!但在一个优雅的或健康的方式,DONT修改您的应用代码,离开这个工作了Apache,Nginx的,HAProxy的或一些负载平衡器:

# apache 2.2 example 
SSLCertificateFile /some/folder/certificate.crt 
SSLCertificateKeyFile /some/folder/initial.key 
SSLCertificateChainFile /some/folder/certificate.ca-bundle 

这种复杂性必须是透明的开发团队和应由系统管理员,基础设施或与贵公司网络相关的其他团队管理。

回答

4

我有点晚了,但我希望这有助于。

如果某人有此文件的工作:PB7,CRT,CA-束,并有此错误:

error:0906D06C:PEM routines:PEM_read_bio:no start line 

这意味着,这个文件是错误的,损坏或者被要求用于另一个环境(窗户例如),因为这在帖子中写道:https://serverfault.com/a/317038

所以在我的情况的解决方案是要求提供新的证书,并在especifications,把下面的:

  • Linux下C ompatibility

而且是很重要的保存,CSR将被创建并发送至certificator提供商的关键(我叫initial.key)。

http://www.backwardcompatible.net/155-Setting-up-real-SSL-Nodejs-Express

最后,你的供应商都会给你一个带拉链的几个文件。你只需要为您的节点应用一个.crt文件:

var privateKey = fs.readFileSync('/some/folder/initial.key').toString(); 
var certificate = fs.readFileSync('/some/folder/certificate.crt').toString(); 
var credentials = {key: privateKey, cert: certificate}; 

注:certificate.ca束和certificate.crt文件必须由certificator提供商发送。

HTH