| 1 | package provisioner |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/pkg/errors" |
| 7 | "github.com/smallstep/certificates/pki" |
| 8 | "github.com/smallstep/cli/errs" |
| 9 | "github.com/smallstep/cli/flags" |
| 10 | "github.com/urfave/cli" |
| 11 | ) |
| 12 | |
| 13 | func getEncryptedKeyCommand() cli.Command { |
| 14 | return cli.Command{ |
| 15 | Name: "jwe-key", |
| 16 | Action: cli.ActionFunc(getEncryptedKeyAction), |
| 17 | Usage: "retrieve and print a provisioning key in the CA", |
| 18 | UsageText: `**step ca provisioner jwe-key** <kid> |
| 19 | [**--ca-url**=<uri>] [**--root**=<file>]`, |
| 20 | Description: `**step ca provisioner jwe-key** returns the encrypted |
| 21 | private jwk for the given key-id. |
| 22 | |
| 23 | ## EXAMPLES |
| 24 | |
| 25 | Retrieve the encrypted private jwk for the given key-id: |
| 26 | ''' |
| 27 | $ step ca provisioner jwe-key 1234 --ca-url https://127.0.0.1 --root ./root.crt |
| 28 | ''' |
| 29 | `, |
| 30 | Flags: []cli.Flag{ |
| 31 | cli.StringFlag{ |
| 32 | Name: "ca-url", |
| 33 | Usage: "<URI> of the targeted Step Certificate Authority.", |
| 34 | }, |
| 35 | cli.StringFlag{ |
| 36 | Name: "root", |
| 37 | Usage: "The path to the PEM <file> used as the root certificate authority.", |
| 38 | }, |
| 39 | }, |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func getEncryptedKeyAction(ctx *cli.Context) error { |
| 44 | if err := errs.NumberOfArguments(ctx, 1); err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | kid := ctx.Args().Get(0) |
| 49 | root := ctx.String("root") |
| 50 | caURL, err := flags.ParseCaURL(ctx) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | key, err := pki.GetProvisionerKey(caURL, root, kid) |
| 56 | if err != nil { |
| 57 | return errors.Wrap(err, "error getting the provisioning key") |
| 58 | } |
| 59 | |
| 60 | fmt.Println(key) |
| 61 | return nil |
| 62 | } |