From 919ffe672679b494c70cc1f735ffcddae9cccff7 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 30 May 2016 15:53:16 +0800 Subject: [PATCH] Fixed #93 Support password parameter when loads a PEM certificate from a local file. Signed-off-by: Bo-Yi Wu --- README.md | 2 ++ config/config.go | 2 ++ config/config.yml | 1 + gorush.go | 6 ++++++ gorush/notification.go | 2 +- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e09393..f758a17 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ android: ios: enabled: false pem_path: "key.pem" + password: "" # certificate password, default as empty string. production: false log: @@ -124,6 +125,7 @@ $ gorush -ios -m="your message" -i="your certificate path" -t="device token" -to * `-i`: Apple Push Notification Certificate path (`pem` file). * `-t`: Device token. * `-topic`: The topic of the remote notification. +* `-password`: The certificate password. The default endpoint is APNs development. Please add `-production` flag for APNs production push endpoint. diff --git a/config/config.go b/config/config.go index 6c47b47..c3d2052 100644 --- a/config/config.go +++ b/config/config.go @@ -46,6 +46,7 @@ type SectionAndroid struct { type SectionIos struct { Enabled bool `yaml:"enabled"` PemPath string `yaml:"pem_path"` + Password string `yaml:"password"` Production bool `yaml:"production"` } @@ -106,6 +107,7 @@ func BuildDefaultPushConf() ConfYaml { // iOS conf.Ios.Enabled = false conf.Ios.PemPath = "key.pem" + conf.Ios.Password = "" conf.Ios.Production = false // log diff --git a/config/config.yml b/config/config.yml index 0f791e9..a6387d1 100644 --- a/config/config.yml +++ b/config/config.yml @@ -21,6 +21,7 @@ android: ios: enabled: false pem_path: "key.pem" + password: "" production: false log: diff --git a/gorush.go b/gorush.go index f8bd672..ede3cfc 100644 --- a/gorush.go +++ b/gorush.go @@ -23,6 +23,7 @@ func main() { version := flag.Bool("v", false, "gorush version") confPath := flag.String("c", "", "yaml configuration file path for gorush") certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gorush") + certificatePassword := flag.String("password", "", "iOS certificate password for gorush") apiKey := flag.String("k", "", "Android api key configuration for gorush") port := flag.String("p", "", "port number for gorush") token := flag.String("t", "", "token string") @@ -61,6 +62,11 @@ func main() { gorush.PushConf.Ios.PemPath = *certificateKeyPath } + if *certificatePassword != "" { + log.Printf("Load yaml config file error: '%v'", certificatePassword) + gorush.PushConf.Ios.Password = *certificatePassword + } + if *apiKey != "" { gorush.PushConf.Android.APIKey = *apiKey } diff --git a/gorush/notification.go b/gorush/notification.go index fe17a91..a125367 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -141,7 +141,7 @@ func InitAPNSClient() error { if PushConf.Ios.Enabled { var err error - CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemPath, "") + CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemPath, PushConf.Ios.Password) if err != nil { LogError.Error("Cert Error:", err.Error())