Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS & SSL - "bad password read"

Node is failing to create a secure context for SSL communications.

Specifically, I'm trying to get remote notifications to work on iOS. I use a module, called node-apn which throws this error:

Error: error:0906A068:PEM routines:PEM_do_header:bad password read at Error (native) at Object.createSecureContext (_tls_common.js:108:19) at Object.exports.connect (_tls_wrap.js:852:21) at apnSocket (/home/Slurp/node_modules/apn/lib/socket.js:56:19) at Connection.<anonymous> (/home/Slurp/node_modules/apn/lib/connection.js:188:17) at _fulfilled (/home/Slurp/node_modules/apn/node_modules/q/q.js:834:54) at self.promiseDispatch.done (/home/Slurp/node_modules/apn/node_modules/q/q.js:863:30) at Promise.promise.promiseDispatch (/home/Slurp/node_modules/apn/node_modules/q/q.js:796:13) 

This seems to be a generic error though, and isn't really related to APN specifically.

like image 786
MrQuiw Avatar asked Jun 20 '15 19:06

MrQuiw


People also ask

What is Node JS used for?

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.

Is Node JS better than Python?

js vs Python, Node. js is faster due to JavaScript, whereas Python is very slow compared to compiled languages. Node. js is suitable for cross-platform applications, whereas Python is majorly used for web and desktop applications.

Is Node JS frontend or backend?

A common misconception among developers is that Node. js is a backend framework and is only used for building servers. This isn't true: Node. js can be used both on the frontend and the backend.

Is Node JS a programming language?

Introduction: Node. js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and it's not a programming language.


1 Answers

This is because you've specified a passphrase when generating the cert. This is a password that must be supplied by anyone wanting to use it.

Adding a passphrase field to the credentials solves the problem.

var credentials = {     key: fs.readFileSync('XXX.key', 'utf8'),     cert: fs.readFileSync('XXX.crt', 'utf8'),     passphrase: 'XXXX' }  var httpsServer = https.createServer(credentials, app); 
like image 74
Gang Su Avatar answered Sep 22 '22 19:09

Gang Su