mardi 31 mars 2015

Node.js HTTPS request using Elliptic Curve key

I want to build an HTTPS client that connects to a HTTPS Server that requires mutual authentication. Additionally, the client key is an Elliptic Curve key instead of a RSA key. To support Elliptic Curve keys, I have recompiled Node.js with OpenSSL 1.0.2a.


In my node.js program, I set the options to specify a key and certificate,



var options = {
// These are necessary only if using the client certificate authentication
key: fs.readFileSync('client-key.pem'),
cert: fs.readFileSync('client-cert.pem'),


and when I run it, I get this error:



Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Error (native)
at Object.createSecureContext (_tls_common.js:110:19)
at Object.exports.connect (_tls_wrap.js:854:21)
at Agent.createConnection (https.js:84:14)
at Agent.createSocket (_http_agent.js:196:16)
at Agent.addRequest (_http_agent.js:168:23)
at new ClientRequest (_http_client.js:156:16)
at Object.exports.request (http.js:51:10)
at exports.request (https.js:138:15)
...


This indicates that Node.js is not able to read the EC key. This error message is similar to when openssl attempts to read the key as an X509 cert:



openssl x509 -text -in sample.key
unable to load certificate
140735234208608:error:0906D06C:PEM routines:PEM_read_bio:no start
line:pem_lib.c:701:Expecting: TRUSTED CERTIFICATE


How can I force Node.js to load this key as an EC key?


Aucun commentaire:

Enregistrer un commentaire