My pem cert is a trust chain that begins with a subject, like this:
subject=CN=test-client, O=My Company, L=New York, S=New York, C=US
issuer=CN=My Company T3 001 Certificate Authority G1, DC=nyt, DC=net
-----BEGIN CERTIFICATE-----
MIIHRzCCBi+gAwIBAgITYwAAFnfJ+jbV6pZS7gAHAAAWdzANBgkqhkiG9w0BAQsF
...
Everything works well when I pass the cert via a file path, e.g.:
{
cert: './client.pem',
key: './client.key'
}
But if I pass the cert via a variable it crashes the app:
{
cert: CLIENT_CERT, // contains a pem cert with a subject as the first line
key: CLIENT_KEY
}
The reason is that the line testing if the variable contains the cert and not a path to the cert evaluates to false. The given cert does not start with -----BEGIN, but with subject=, so this test does not pass:
!/^-----BEGIN/.test(self.options.ssl.cert.toString('utf8'))
Instead of treating the string as a cert, it erroneously treats it as a file path and attempts to use it to load the cert from disk.
My pem cert is a trust chain that begins with a subject, like this:
Everything works well when I pass the cert via a file path, e.g.:
But if I pass the cert via a variable it crashes the app:
The reason is that the line testing if the variable contains the cert and not a path to the cert evaluates to false. The given cert does not start with
-----BEGIN
, but withsubject=
, so this test does not pass:!/^-----BEGIN/.test(self.options.ssl.cert.toString('utf8'))
Instead of treating the string as a cert, it erroneously treats it as a file path and attempts to use it to load the cert from disk.