0

I've created a self-signed certificate for testing purposes with the pass phrase "foobar" using this command:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365

I'm then trying to call tls.createSecureContext with that certificate-key pair like so:

var tls = require('tls');
var fs = require('fs');

const [key, cert] = [
    fs.readFileSync("key.pem"),
    fs.readFileSync("cert.pem"),
];

tls.createSecureContext({key, cert})

However, this leads to the following error:

> node main.js
node:internal/tls/secure-context:69
    context.setCert(cert);
            ^

Error: error:0909006C:PEM routines:get_name:no start line
    at node:internal/tls/secure-context:69:13
    at Array.forEach (<anonymous>)
    at setCerts (node:internal/tls/secure-context:67:3)
    at configSecureContext (node:internal/tls/secure-context:156:5)
    at Object.createSecureContext (node:_tls_common:116:3)
    at Object.<anonymous> (/Users/kurtpeek/go/src/github.pie.apple.com/kurt-peek/scratch/node/main.js:9:5)
    at Module._compile (node:internal/modules/cjs/loader:1246:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
    at Module.load (node:internal/modules/cjs/loader:1103:32)
    at Module._load (node:internal/modules/cjs/loader:942:12) {
  library: 'PEM routines',
  function: 'get_name',
  reason: 'no start line',
  code: 'ERR_OSSL_PEM_NO_START_LINE'
}

Node.js v19.5.0

This question appears to be the same as Error: error:0909006C:PEM routines:get_name:no start line - node but I wasn't able to find an answer there. (For example, I tried applying unix2dos to cert.pem and key.pem, but to no avail). Any ideas on how to fix this?

Kurt Peek
  • 52,165
  • 91
  • 301
  • 526

0 Answers0