Skip to content

Commit

Permalink
Merge pull request go-acme#234 from jboelter/master
Browse files Browse the repository at this point in the history
Add optional support for .pem output (.crt + .key)
  • Loading branch information
xenolf authored Jun 21, 2016
2 parents b2fad61 + 941e753 commit 02f0c50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func main() {
Name: "dns-timeout",
Usage: "Set the DNS timeout value to a specific value in seconds. The default is 10 seconds.",
},
cli.BoolFlag{
Name: "pem",
Usage: "Generate a .pem file by concatanating the .key and .crt files together.",
},
}

err = app.Run(os.Args)
Expand Down
13 changes: 13 additions & 0 deletions cli_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"bytes"
"crypto/x509"
"encoding/json"
"encoding/pem"
Expand Down Expand Up @@ -143,6 +144,7 @@ func saveCertRes(certRes acme.CertificateResource, conf *Configuration) {
// as web servers would not be able to work with a combined file.
certOut := path.Join(conf.CertPath(), certRes.Domain+".crt")
privOut := path.Join(conf.CertPath(), certRes.Domain+".key")
pemOut := path.Join(conf.CertPath(), certRes.Domain+".pem")
metaOut := path.Join(conf.CertPath(), certRes.Domain+".json")

err := ioutil.WriteFile(certOut, certRes.Certificate, 0600)
Expand All @@ -156,6 +158,17 @@ func saveCertRes(certRes acme.CertificateResource, conf *Configuration) {
if err != nil {
logger().Fatalf("Unable to save PrivateKey for domain %s\n\t%s", certRes.Domain, err.Error())
}

if conf.context.GlobalBool("pem") {
err = ioutil.WriteFile(pemOut, bytes.Join([][]byte{certRes.Certificate, certRes.PrivateKey}, nil), 0600)
if err != nil {
logger().Fatalf("Unable to save Certificate and PrivateKey in .pem for domain %s\n\t%s", certRes.Domain, err.Error())
}
}

} else if conf.context.GlobalBool("pem") {
// we don't have the private key; can't write the .pem file
logger().Fatalf("Unable to save pem without private key for domain %s\n\t%s; are you using a CSR?", certRes.Domain, err.Error())
}

jsonBytes, err := json.MarshalIndent(certRes, "", "\t")
Expand Down

0 comments on commit 02f0c50

Please sign in to comment.