0

I already had a functioning application on HTTP using nodeJs language. I would like to start using HTTPS instead. My current implementation is:

var fs = require('fs');
var https = require('https');
var certificate = fs.readFileSync('filename.pfx', 'utf8');
var credentials = {key: 'password', pfx: certificate};
dotenv.config({ silent: true });

const app = express();
app.use(/^\/(?!ready).*/);

var httpsServer = https.createServer(credentials, app);
httpsServer.listen(PORT, logger.info(`Server listening on port: ${PORT}`));

The error i am facing is:

_tls_common.js:144
c.context.setKey(key, passphrase);
            ^

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Object.createSecureContext (_tls_common.js:144:17)
at Server (_tls_wrap.js:867:27)
at new Server (https.js:62:14)

Can anyone help on this?

user666
  • 1,750
  • 3
  • 18
  • 34
  • 1
    Possible Duplicate : https://stackoverflow.com/questions/22584268/node-js-https-pem-error-routinespem-read-biono-start-line/34004949 – Mukesh Verma Sep 28 '18 at 14:08
  • The mentioned link is not solved. Despite i am already not using cert and i tried without utf8 and the issue remains. The certification is for sure not expired as its used in other projects normally. – user666 Oct 01 '18 at 05:17

1 Answers1

2

Solved using:

 var options = {
   pfx: fs.readFileSync([filename]),
   passphrase: [password]
 };     

  [...app definition...]
 var httpsServer = https.createServer(options, app);

  httpsServer.listen(PORT, logger.info(`Server listening on port: ${PORT}`));
user666
  • 1,750
  • 3
  • 18
  • 34
  • Hi @user666, Mine is not a `pfx` file. its `pem` files. How can I fix the same using `{ key: privateKey, cert: cert, ca: ca };`? – Jyothu Nov 07 '22 at 13:49