在使用 git 跟踪的 heroku 项目时,如何安全地存储 .pem 文件



我有一个 git 跟踪的存储库,正在将其设置为与 APN 一起使用以进行 IOS 推送通知。我正在考虑以类似于PushNotificationSample的方式实现npm模块node-apn

在此代码中,有

var options = {
    gateway: 'gateway.sandbox.push.apple.com', // this URL is different for Apple's Production Servers and changes when you go to production
    errorCallback: callback,
    cert: 'your-cert.pem', // ** NEED TO SET TO YOURS - see this tutorial - http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
    key:  'your-key.pem',  // ** NEED TO SET TO YOURS
    passphrase: 'your-pw', // ** NEED TO SET TO YOURS
    port: 2195,                       
    enhanced: true,                   
    cacheLength: 100                  
}

但是,我该如何引用我的 .pem 文件而不将它们提交到 Github?

目前,我正在部署到Heroku。

通过 Heroku 的(环境)配置变量执行此操作。

如果您使用的是 node-apn 或类似的东西,您应该能够传入证书和密钥内容,而不是路径。按照 Heroku 的建议,使用 ENV vars 传入关键内容。

cert: process.env.APN_CERT,
key:  process.env.APN_KEY,
passphrase: process.env.APN_PASSPHRASE,

由于您无法在 Web 界面中为应用程序配置设置多行值,因此您必须使用命令行来设置 APN_CERTAPN_KEY

$ heroku config:set APN_CERT="-----BEGIN CERTIFICATE-----
> MIIDOjCCAiICCQCZTWzQNz6sqTANBgkqhkiG9w0BAQsFADBfMQswCQYDVQQGEwJB
> VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
...