如何将 PEM 证书/密钥作为变量传递给 node.js 项目
我正在尝试使用 node-apn 设置 Apple 推送通知服务。我已经编写了项目的其他部分(RESTful API、后端、消息队列),但我遇到了 node.js 部分的阻塞问题。
我必须向 node-apn 传递一个密钥和一个证书,这通常是通过传递一对文件名作为选项来完成的。然而,这种设置并不理想,我需要将它们作为变量传递。我已经更改了node-aps的源代码,如果不是我在研究解决方案时没有考虑到的问题,它会很乐意寻找这些变量。
Javascript不接受多行变量,所以我无法传递这种格式的证书或密钥:
var cert = '-----BEGIN CERTIFICATE-----
[cut]
-----END CERTIFICATE-----';
我尝试用 \ 转义换行符,但最终得到单行证书/密钥,所以我得到“PEM_read_bio:no start”行”错误。
有什么好的解决方法吗?
I am trying to set up an Apple Push Notification service with node-apn. I have written the other parts of the project (RESTful API, backend, message queueing) but I run into a blocking problem with the node.js portion.
I have to pass node-apn a key and a certificate and this is normally done passing a pair of filenames as option to it. However this setup is not ideal and I need to pass them as variables. I have already changed node-aps' source and it would happily look for these variables if it wasn't for an issue I didn't considerate while studying a solution.
Javascript doesn't accept multiline variables so I can't pass a certificate or a key in this format:
var cert = '-----BEGIN CERTIFICATE-----
[cut]
-----END CERTIFICATE-----';
I tried escaping newlines with \ but then I end up with a one line certificate/key and so I get a "PEM_read_bio:no start line" error.
Is there any decent workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在字符串中包含换行符,如下所示:
但我认为单独放置证书文件是一个更好的主意。我认为上面的代码看起来并不理想。
You can have newlines in your string like this:
But I think that it's a better idea to put your certificate files separately. Above code doesn't look ideal in my opinion.