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 ?
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, ...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With