Node.js https pem错误:错误:0906D06C:PEM例程:PEM_read_bio:无起始行 [英] Node.js https pem error: error:0906D06C:PEM routines:PEM_read_bio:no start line

查看:3186
本文介绍了Node.js https pem错误:错误:0906D06C:PEM例程:PEM_read_bio:无起始行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




  • domain.com.p7b

  • domain.com.crt

  • domain.com.ca-bundle



我尝试过小代码:

  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('应用程序侦听端口8080!');
});

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



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $($) b $ b(err):在新服务器(https.js:17:14)
(err):在Object.exports.createServer(https.js:37:10)
(err)在Object。< anonymous> (/utec_temp/https/web.js:27:7)
(err):在Module._compile(module.js:435:26)
(err):在Object.Module._extensions。 。$($ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s :错误:0906D06C:PEM例程:PEM_read_bio:没有起始行
(err):at Error(native)
(err):at Object .createSecureContext(_tls_common.js:87:19)
(err):at server(_tls_wrap.js:721:25)
(err):在新服务器(https.js:17:14)
(err):在Object.exports.createServer(https.js:37:10)
(err):在Object。< anonymous> (/utec_temp/https/web.js:27:7)
(err):在Module._compile(module.js:435:26)
(err):在Object.Module._extensions。 。$($ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s :311:12)

您可以在互联网上使用Google的大多数示例使用自签名证书,但是什么在一个真实的环境中工作时,发生了什么?



我的小代码在自签名密钥的开发中起作用,如下例所示:



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错误:例程:PEM_read_bio:没有开始行



但我无法更正错误。



另外我还原到一个文件:

  var credentials = {证书:证书}; 

错误是一样的。所以我以为可能是从windows到unix的格式错误。我使用dos2unix工具,错误是一样的。



我的节点版本是4.4.7



任何帮助感谢。



提前感谢!


UPDATED


我在答案部分的回答适用于node.js!但是以优雅或健康的方式,您可以将此工作改为apache,nginx,haproxy或某些负载平衡器:

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

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

解决方案

我迟到了,但希望这有帮助。



有人使用这个文件:pb7,crt,ca-bundle,并有这个错误:

 错误:0906D06C:PEM例程: PEM_read_bio:没有起始行

这意味着这个文件是错误的,损坏的或被要求为另一个环境(例如Windows), https://serverfault.com/a/317038



所以在我的情况下,解决方案是要求一个新的证书,并在特别提出了以下内容:




  • Linux兼容性



同样重要的是保存csr创建的密钥并发送给认证提供者(我称为 initial.key )。



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



最后,您的提供商将发送你有几个文件的zip。你只需要一个.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-bundle和certificate.crt文件必须由认证提供商发送。 p>

HTH


I got myself this files from Certificate Authority:

  • domain.com.p7b
  • domain.com.crt
  • domain.com.ca-bundle

And I tried this little code:

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!');
});

After start script, I get the following error:

(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)

Most examples you can google on the Internet use self-signed certificates , but what happend when I work in a real environment?

My little code works in development with self signed keys , as in this example:

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

I researched and I found this:

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

but I could not correct the error.

Also I reduced to one file :

var credentials = {cert: certificate};      

And the error is the same. So I thought that maybe a format error from windows to unix. I used dos2unix tool and the error is the same.

My node version is 4.4.7

Any help is appreciated.

Thanks in advance!

UPDATED

My answer in the answers section works for node.js !! but in a elegant or healthy way, DONT MODIFY YOUR APP CODE and leave this work to apache , nginx, haproxy or some load balancer:

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

This kind of complexity must be transparent for the development team and should be managed by sysadmin,infrastructure or another teams related to networks of your company.

解决方案

I little late but I hope this helps.

If someone have work with this files : pb7, crt,ca-bundle and have this error:

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

This would mean that this files are wrong, corrupt or was requested for another environments (windows for example) as this post says:https://serverfault.com/a/317038

So the solution in my case was request for a new certificates and in the especifications , put the following:

  • Linux compatibility

Also is important save the key with which the csr was created and sent to the certificator provider(I called initial.key).

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

Finally , your provider will send you a zip with several files. You only need a .crt file for your node app:

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

Note : certificate.ca-bundle and certificate.crt files must be sent by certificator provider.

HTH

这篇关于Node.js https pem错误:错误:0906D06C:PEM例程:PEM_read_bio:无起始行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆