NodeJS & SSL - "bad password read"

29,905

Solution 1

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

Solution 2

The following command will generate an unencrypted key, so you won't need to provide a passphrase:

openssl rsa -in yourKey.key -out newKey.key

This command will prompt you for the passphrase.

Share:
29,905

Related videos on Youtube

MrQuiw
Author by

MrQuiw

Updated on July 09, 2022

Comments

  • MrQuiw
    MrQuiw almost 2 years

    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.

  • Sravan
    Sravan over 7 years
    Is this passphrase used to create the .pem or '.crt' files?
  • Gang Su
    Gang Su over 7 years
    I think it was used to create the .crt file