使用带有 NodeJs HTTPS 的certificates.cer [英] Using certificates.cer with NodeJs HTTPS
问题描述
我已经为 IOS 推送通知生成了一个 .cer 文件,我想将它与 NodeJS HTTPS 模块一起使用.
我发现的 HTTPS 模块的唯一示例使用 .pem 和 .sfx 文件,而不是 .cer :
var 选项 = {key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),证书:fs.readFileSync('test/fixtures/keys/agent2-cert.pem')};或者变量选项 = {pfx: fs.readFileSync('server.pfx')}https.createServer(options, function (req, res) {res.writeHead(200);res.end("你好世界\n");}).听(8000);
有什么解决办法吗?
HTTPS/TLS 加密是非对称的,有两部分使其起作用,一个公钥和一个私钥.
上传证书签名请求 (CSR) 后从 Apple 推送通知服务 (APNS) 获得的 .cer
文件是已签名的公钥.>
私钥的位置取决于您如何生成它.
如果您使用的是 Mac 并使用 Apple Keychain 应用程序,则它具有私钥.将 .cer
公钥 导入回 Keychain.然后使用 Export 选项获取一个受密码保护的 .p12
文件,该文件将包含私钥和公钥.请参阅链接 [1] 和 [2].
在您的 node.js 应用程序中,导出的 .p12
文件和密码可用作 pfx
和 passphrase
选项以https.createServer
.
例如:
var 选项 = {pfx: fs.readFileSync('./exported-cert.p12'),密码短语:'导出时设置的密码'};https.createServer(options, ...);
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, ...);
这篇关于使用带有 NodeJs HTTPS 的certificates.cer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!