@@ -44,11 +44,11 @@ func createCommand() cli.Command {
4444[**--kms**=<uri>] [**--csr**] [**--profile**=<profile>]
4545[**--template**=<file>] [**--set**=<key=value>] [**--set-file**=<file>]
4646[**--not-before**=<duration>] [**--not-after**=<duration>]
47- [**--password-file**=<file>] [**--ca**=<issuer-cert>]
47+ [**--password-file**=<file>] [**--ca**=<issuer-cert>]
4848[**--ca-key**=<issuer-key>] [**--ca-password-file**=<file>]
49- [**--san**=<SAN>] [**--bundle**] [**--key**=<file>]
49+ [**--ca-kms**=<uri>] [**-- san**=<SAN>] [**--bundle**] [**--key**=<file>]
5050[**--kty**=<type>] [**--curve**=<curve>] [**--size**=<size>]
51- [**--no-password**] [**--insecure**]` ,
51+ [**--skip-csr-signature**] [**-- no-password**] [**--insecure**]` ,
5252 Description : `**step certificate create** generates a certificate or a
5353certificate signing request (CSR) that can be signed later using 'step
5454certificate sign' (or some other tool) to produce a certificate.
@@ -345,11 +345,34 @@ $ step kms create \
345345 'pkcs11:id=4001;object=intermediate-key'
346346$ step certificate create \
347347 --profile intermediate-ca \
348- --kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
348+ --ca- kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password'
349349 --ca root_ca.crt --ca-key 'pkcs11:id=4000' \
350+ --kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
350351 --key 'pkcs11:id=4001' \
351352 'My KMS Intermediate' intermediate_ca.crt
352353'''
354+
355+ Create an intermediate certificate for an RSA decryption key in Google Cloud KMS, signed by a root stored on disk, using <step-kms-plugin>:
356+ '''
357+ $ step certificate create \
358+ --profile intermediate-ca \
359+ --ca root_ca.crt --ca-key root_ca_key \
360+ --kms cloudkms: \
361+ --key 'projects/myProjectID/locations/global/keyRings/myKeyRing/cryptoKeys/myKey/cryptoKeyVersions/1' \
362+ --skip-csr-signature \
363+ 'My RSA Intermediate' intermediate_rsa_ca.crt
364+ '''
365+
366+ Create an intermediate certificate for an RSA signing key in Google Cloud KMS, signed by a root stored in an HSM, using <step-kms-plugin>:
367+ '''
368+ $ step certificate create \
369+ --profile intermediate-ca \
370+ --ca-kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
371+ --ca root_ca.crt --ca-key 'pkcs11:id=4000' \
372+ --kms cloudkms: \
373+ --key 'projects/myProjectID/locations/global/keyRings/myKeyRing/cryptoKeys/myKey/cryptoKeyVersions/1' \
374+ 'My RSA Intermediate' intermediate_rsa_ca.crt
375+ '''
353376` ,
354377 Flags : []cli.Flag {
355378 flags .KMSUri ,
@@ -446,6 +469,14 @@ the **--ca** flag.`,
446469 Name : "insecure" ,
447470 Hidden : true ,
448471 },
472+ cli.StringFlag {
473+ Name : "ca-kms" ,
474+ Usage : "The <uri> to configure the KMS used for signing the certificate" ,
475+ },
476+ cli.BoolFlag {
477+ Name : "skip-csr-signature" ,
478+ Usage : "Skip creating and signing a CSR" ,
479+ },
449480 },
450481 }
451482}
@@ -485,17 +516,22 @@ func createAction(ctx *cli.Context) error {
485516 }
486517
487518 var (
488- sans = ctx .StringSlice ("san" )
489- profile = ctx .String ("profile" )
490- templateFile = ctx .String ("template" )
491- bundle = ctx .Bool ("bundle" )
492- subtle = ctx .Bool ("subtle" )
519+ sans = ctx .StringSlice ("san" )
520+ profile = ctx .String ("profile" )
521+ templateFile = ctx .String ("template" )
522+ bundle = ctx .Bool ("bundle" )
523+ subtle = ctx .Bool ("subtle" )
524+ skipCSRSignature = ctx .Bool ("skip-csr-signature" )
493525 )
494526
495527 if ctx .IsSet ("profile" ) && templateFile != "" {
496528 return errs .IncompatibleFlagWithFlag (ctx , "profile" , "template" )
497529 }
498530
531+ if ctx .Bool ("csr" ) && skipCSRSignature {
532+ return errs .IncompatibleFlagWithFlag (ctx , "csr" , "skip-csr-signature" )
533+ }
534+
499535 // Read template if passed
500536 var template string
501537 if templateFile != "" {
@@ -631,20 +667,31 @@ func createAction(ctx *cli.Context) error {
631667 defaultValidity = defaultTemplatevalidity
632668 }
633669
634- // Create X.509 certificate used as base for the certificate
635- cr , err := x509util .CreateCertificateRequest (subject , sans , signer )
636- if err != nil {
637- return err
638- }
639-
640670 // Create X.509 certificate
641671 templateData := x509util .CreateTemplateData (subject , sans )
642672 templateData .SetUserData (userData )
643- certificate , err := x509util .NewCertificate (cr , x509util .WithTemplate (template , templateData ))
644- if err != nil {
645- return err
673+
674+ var certTemplate = & x509.Certificate {}
675+ if skipCSRSignature {
676+ certTemplate .PublicKey = pub
677+ certificate , err := x509util .NewCertificateFromX509 (certTemplate , x509util .WithTemplate (template , templateData ))
678+ if err != nil {
679+ return err
680+ }
681+ certTemplate = certificate .GetCertificate ()
682+ } else {
683+ // Create X.509 certificate used as base for the certificate
684+ cr , err := x509util .CreateCertificateRequest (subject , sans , priv )
685+ if err != nil {
686+ return err
687+ }
688+ certificate , err := x509util .NewCertificate (cr , x509util .WithTemplate (template , templateData ))
689+ if err != nil {
690+ return err
691+ }
692+ certTemplate = certificate .GetCertificate ()
646693 }
647- certTemplate := certificate . GetCertificate ()
694+
648695 if parent == nil {
649696 parent = certTemplate
650697 }
@@ -766,9 +813,9 @@ func parseSigner(ctx *cli.Context, defaultSigner crypto.Signer) (*x509.Certifica
766813 var (
767814 caCert = ctx .String ("ca" )
768815 caKey = ctx .String ("ca-key" )
816+ caKMS = ctx .String ("ca-kms" )
769817 profile = ctx .String ("profile" )
770818 template = ctx .String ("template" )
771- kms = ctx .String ("kms" )
772819 )
773820
774821 // Check required flags when profile is used.
@@ -819,7 +866,7 @@ func parseSigner(ctx *cli.Context, defaultSigner crypto.Signer) (*x509.Certifica
819866 opts = append (opts , pemutil .WithPasswordFile (passFile ))
820867 }
821868
822- signer , err := cryptoutil .CreateSigner (kms , caKey , opts ... )
869+ signer , err := cryptoutil .CreateSigner (caKMS , caKey , opts ... )
823870 if err != nil {
824871 return nil , nil , err
825872 }
0 commit comments