Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using certificates.cer with NodeJs HTTPS

I have generated a .cer file for IOS push notifications and I would ike to use it with NodeJS HTTPS module.

The only examples I found for HTTPS module work with .pem and .sfx files, not .cer :

var options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};

or 

var options = {
  pfx: fs.readFileSync('server.pfx')
}

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

Any solution ?

like image 793
Cherif Avatar asked Mar 03 '14 12:03

Cherif


1 Answers

HTTPS/TLS encryption is asymmetric, there are two parts to make it work, a public key and a private key.

The .cer file you get from Apple Push Notification Services (APNS) after you have uploaded the certificate signing request (CSR) is the signed public key.

The location of the private key depends on how you generated it.

If you're on a mac and using the Apple Keychain application, it has the private key. Import the .cer public key back into Keychain. Then use the Export option to get a single password protected .p12 file that will contain both the private and public keys. See links [1] and [2].

In your node.js application, the exported .p12 file and password can be used as the pfx and passphrase options to https.createServer.

For example:

var options = {
  pfx: fs.readFileSync('./exported-cert.p12'),
  passphrase: 'password-that-was-set-on-export'
};

https.createServer(options, ...);
like image 197
poida Avatar answered Sep 28 '22 19:09

poida