|
|
5#

楼主 |
发表于 2016-7-16 18:27:30
|
只看该作者
google搜索的可能解决方法:
Node.js https pem error: routines EM_read_bio:no start line
up vote
7
down vote
favorite
6
I am messing with login form right now with node.js, I tried creating a pem key and csr using
openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
However I been getting errors for running node server.js
Here is my server.js
var http = require('http'),
express = require('express'),
UserServer = require('./lib/user-server');
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('./key.pem', 'utf8'),
cert: fs.readFileSync('./csr.pem', 'utf8')
};
var app = express();
app.configure(function(){
app.use(express.bodyParser());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
var httpserver = http.createServer(app).listen('3004', '127.0.0.1');
var https_server = https.createServer(options, app).listen('3005', '127.0.0.1');
UserServer.listen(https_server);
Here is the error
crypto.js:104
if (options.cert) c.context.setCert(options.cert);
^
Error: error:0906D06C EM routines EM_read_bio:no start line
at Object.exports.createCredentials (crypto.js:104:31)
at Server (tls.js:1107:28)
at new Server (https.js:35:14)
at Object.exports.createServer (https.js:54:10)
I tried running
openssl x509 -text -inform DER -in key.pem
It gives
unable to load certificate
140735208206812:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319:
140735208206812:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:381:Type=X509
I am not exactly sure what does the error mean as my encryption file is .pem file already, so any help would be much appreciated.
Thanks
node.js security login https pem
shareimprove this question
edited Mar 23 '14 at 2:10
asked Mar 22 '14 at 22:08
xbd
8018
Did you fix this error? – elranu May 8 '14 at 13:53
add a comment
5 Answers
active oldest votes
up vote
19
down vote
You are probably using the wrong certificate file, what you need to do is generate a self signed certificate which can be done as follows
openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt
then use the server.crt
var options = {
key: fs.readFileSync('./key.pem', 'utf8'),
cert: fs.readFileSync('./server.crt', 'utf8')
};
shareimprove this answer
answered Jun 18 '14 at 10:27
Hassaan
19116
This worked for me. Thank you. – Mr Bell Nov 20 '15 at 16:02
Thank you, this worked perfectly. – monarch Dec 1 '15 at 3:28
I tried this, but when I reload my services I get an error "EACCES, permission denied" – harryBundles Dec 10 '15 at 18:36
The node process may not have the rights to read the certificates or bind to the port. Try running through sudo if you are on linux. – Hassaan Jan 25 at 11:19
This was very helpful when getting setup. Thank you so much! – Robert McMahan Feb 13 at 19:27
add a comment
up vote
0
down vote
If you are using windows, you should make sure that the certificate file csr.pem and key.pem don't have unix-style line endings. Openssl will generate the key files with unix style line endings. You can convert these files to dos format using a utility like unix2dos or a text editor like notepad++
shareimprove this answer
answered May 23 '14 at 16:35
neesh
2,79632227
add a comment
up vote
0
down vote
Generate the private key and server certificate with specific expiry date or with infinite(XXX) expiry time and self sign it.
$ openssl req -x509 -sha256 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX
$ Enter a private key passphrase...`
Then it will work!
shareimprove this answer
answered Nov 30 '15 at 17:57
Robel sharma
757720
add a comment
up vote
0
down vote
If you log the
var options = {
key: fs.readFileSync('./key.pem', 'utf8'),
cert: fs.readFileSync('./csr.pem', 'utf8')
};
You might notice there are invalid characters due to improper encoding.
shareimprove this answer
answered Apr 4 at 15:24
F.O.O
6161519
add a comment
up vote
0
down vote
Was facing the same problem In my case I changed the option parameter of cert to pfx & removed utf8 encoding.
before:
var options = {
hostname : 'localhost',
path : '/',
method : 'POST',
cert: fs.readFileSync(testCert, 'utf8'),
passphrase:passphrase,
agent:false,
rejectUnauthorized:false
};
after:
var options = {
hostname : 'localhost',
path : '/',
method : 'POST',
pfx: fs.readFileSync(testCert),
passphrase:passphrase,
agent:false,
rejectUnauthorized:false
};
|
|