Skip to content

Commit

Permalink
Teach step ca init about --key-password-file
Browse files Browse the repository at this point in the history
This commit permits you, when using the --root and --key options, to pass
the password for decrypting the key in --key-password-file rather than
requiring an interactive prompt.

Example usage:

    step ca init --root root.crt --key root.key \
      --key-password-file root_key_password ...

Closes #453
  • Loading branch information
larsks authored and maraino committed Feb 13, 2024
1 parent 3d2769a commit c592ed4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions command/ca/init.go
Expand Up @@ -37,7 +37,7 @@ func initCommand() cli.Command {
Action: cli.ActionFunc(initAction),
Usage: "initialize the CA PKI",
UsageText: `**step ca init**
[**--root**=<file>] [**--key**=<file>] [**--pki**] [**--ssh**]
[**--root**=<file>] [**--key**=<file>] [**--key-password-file**=<file>] [**--pki**] [**--ssh**]
[**--helm**] [**--deployment-type**=<name>] [**--name**=<name>]
[**--dns**=<dns>] [**--address**=<address>] [**--provisioner**=<name>]
[**--admin-subject**=<string>] [**--provisioner-password-file**=<file>]
Expand All @@ -57,6 +57,10 @@ func initCommand() cli.Command {
Usage: "The path of an existing key <file> of the root certificate authority.",
EnvVar: step.IgnoreEnvVar,
},
cli.StringFlag{
Name: "key-password-file",
Usage: `The path to the <file> containing the password to decrypt the existing root certificate key.`,
},
cli.BoolFlag{
Name: "pki",
Usage: "Generate only the PKI without the CA configuration.",
Expand Down Expand Up @@ -240,10 +244,14 @@ func initAction(ctx *cli.Context) (err error) {
case root == "" && key != "":
return errs.RequiredWithFlag(ctx, "key", "root")
case root != "" && key != "":
opts := []pemutil.Options{}
if keyPasswordFile := ctx.String("key-password-file"); keyPasswordFile != "" {
opts = append(opts, pemutil.WithPasswordFile(keyPasswordFile))
}
if rootCrt, err = pemutil.ReadCertificate(root); err != nil {
return err
}
if rootKey, err = pemutil.Read(key); err != nil {
if rootKey, err = pemutil.Read(key, opts...); err != nil {
return err
}
case ra != "" && ra != apiv1.CloudCAS && ra != apiv1.StepCAS:
Expand Down

0 comments on commit c592ed4

Please sign in to comment.