Skip to content

Commit

Permalink
Add import-pem-account command
Browse files Browse the repository at this point in the history
Fixes #187.

©! I hereby licence these changes under the licence with SHA256 hash
©! fd80a26fbb3f644af1fa994134446702932968519797227e07a1368dea80f0bc.
  • Loading branch information
hlandau committed Aug 5, 2016
1 parent f9893f0 commit cfb995c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/acmetool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ var (
importJWKURLArg = importJWKAccountCmd.Arg("provider-url", "Provider URL (e.g. https://acme-v01.api.letsencrypt.org/directory)").Required().String()
importJWKPathArg = importJWKAccountCmd.Arg("private-key-file", "Path to private_key.json").Required().ExistingFile()

importPEMAccountCmd = kingpin.Command("import-pem-account", "Import a PEM account key")
importPEMURLArg = importPEMAccountCmd.Arg("provider-url", "Provider URL (e.g. https://acme-v01.api.letsencrypt.org/directory)").Required().String()
importPEMPathArg = importPEMAccountCmd.Arg("private-key-file", "Path to private key PEM file").Required().ExistingFile()

importKeyCmd = kingpin.Command("import-key", "Import a certificate private key")
importKeyArg = importKeyCmd.Arg("private-key-file", "Path to PEM-encoded private key").Required().ExistingFile()

Expand Down Expand Up @@ -162,6 +166,8 @@ func main() {
cmdImportKey()
case "import-jwk-account":
cmdImportJWKAccount()
case "import-pem-account":
cmdImportPEMAccount()
case "import-le":
cmdImportLE()
cmdReconcile()
Expand Down Expand Up @@ -189,6 +195,24 @@ func cmdImportJWKAccount() {
log.Fatale(err, "cannot import account key")
}

func cmdImportPEMAccount() {
s, err := storage.NewFDB(*stateFlag)
log.Fatale(err, "storage")

f, err := os.Open(*importPEMPathArg)
log.Fatale(err, "cannot open private key file")
defer f.Close()

b, err := ioutil.ReadAll(f)
log.Fatale(err, "cannot read file")

pk, err := acmeutils.LoadPrivateKey(b)
log.Fatale(err, "cannot parse private key")

_, err = s.ImportAccount(*importPEMURLArg, pk)
log.Fatale(err, "cannot import account key")
}

func cmdImportKey() {
s, err := storage.NewFDB(*stateFlag)
log.Fatale(err, "storage")
Expand Down

0 comments on commit cfb995c

Please sign in to comment.