diff --git a/acme/messages.go b/acme/messages.go index 4f99bcff..609e8b70 100644 --- a/acme/messages.go +++ b/acme/messages.go @@ -33,6 +33,7 @@ type authorizationResource struct { Body authorization Domain string NewCertURL string + AuthURL string } type authorization struct { diff --git a/cli_handlers.go b/cli_handlers.go index 918ade17..fb60bf8a 100644 --- a/cli_handlers.go +++ b/cli_handlers.go @@ -2,7 +2,9 @@ package main import ( "bufio" + "io/ioutil" "os" + "path" "strings" "github.com/codegangsta/cli" @@ -92,5 +94,29 @@ func run(c *cli.Context) { logger().Fatal("Please specify --domains") } - client.ObtainCertificates(c.GlobalStringSlice("domains")) + certs, err := client.ObtainCertificates(c.GlobalStringSlice("domains")) + if err != nil { + logger().Fatalf("Could not obtain certificates -> %v", err) + } + + err = checkFolder(conf.CertPath()) + if err != nil { + logger().Fatalf("Cound not check/create path: %v", err) + } + + for _, certRes := range certs { + certOut := path.Join(conf.CertPath(), certRes.Domain+".crt") + privOut := path.Join(conf.CertPath(), certRes.Domain+".key") + + err = ioutil.WriteFile(certOut, certRes.Certificate, 0700) + if err != nil { + logger().Printf("Unable to save Certificate for domain %s -> %v", certRes.Domain, err) + } + + err = ioutil.WriteFile(privOut, certRes.PrivateKey, 0700) + if err != nil { + logger().Printf("Unable to save PrivateKey for domain %s -> %v", certRes.Domain, err) + } + + } } diff --git a/configuration.go b/configuration.go index 3d4186ed..0bd27f3b 100644 --- a/configuration.go +++ b/configuration.go @@ -35,6 +35,10 @@ func (c *Configuration) ServerPath() string { return strings.Replace(srvStr, "/", string(os.PathSeparator), -1) } +func (c *Configuration) CertPath() string { + return path.Join(c.context.GlobalString("path"), "certificates") +} + // AccountsPath returns the OS dependent path to the // local accounts for a specific CA func (c *Configuration) AccountsPath() string {