From 063a09a521bcb1045e2177a5afd6d1f57cf57304 Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Tue, 15 Jun 2021 12:30:28 +0100 Subject: [PATCH 1/4] Allow reading pin from kms string --- cmd/step-pkcs11-init/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/step-pkcs11-init/main.go b/cmd/step-pkcs11-init/main.go index fd9dbc72..4f32107a 100644 --- a/cmd/step-pkcs11-init/main.go +++ b/cmd/step-pkcs11-init/main.go @@ -119,7 +119,12 @@ func main() { fatal(err) } - if u.Pin() == "" && c.Pin == "" { + kmsPin := u.Pin() + if c.Pin == "" && kmsPin != "" { + c.Pin = kmsPin + } + + if c.Pin == "" { pin, err := ui.PromptPassword("What is the PKCS#11 PIN?") if err != nil { fatal(err) From a63a1d648237d63aacd908f3c2e48b1a5017c20c Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Tue, 15 Jun 2021 18:13:08 +0100 Subject: [PATCH 2/4] Don't double read from u.Pin() --- cmd/step-pkcs11-init/main.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cmd/step-pkcs11-init/main.go b/cmd/step-pkcs11-init/main.go index 4f32107a..c0ac997e 100644 --- a/cmd/step-pkcs11-init/main.go +++ b/cmd/step-pkcs11-init/main.go @@ -119,19 +119,6 @@ func main() { fatal(err) } - kmsPin := u.Pin() - if c.Pin == "" && kmsPin != "" { - c.Pin = kmsPin - } - - if c.Pin == "" { - pin, err := ui.PromptPassword("What is the PKCS#11 PIN?") - if err != nil { - fatal(err) - } - c.Pin = string(pin) - } - k, err := kms.New(context.Background(), apiv1.Options{ Type: string(apiv1.PKCS11), URI: c.KMS, From c6bb7aa199db137f70716e94c8a68488e01eec04 Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Tue, 15 Jun 2021 18:18:29 +0100 Subject: [PATCH 3/4] Add back UI check, but don't read file --- cmd/step-pkcs11-init/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/step-pkcs11-init/main.go b/cmd/step-pkcs11-init/main.go index c0ac997e..0f3c8fa6 100644 --- a/cmd/step-pkcs11-init/main.go +++ b/cmd/step-pkcs11-init/main.go @@ -119,6 +119,14 @@ func main() { fatal(err) } + if c.Pin == "" && u.Get("pin-value") == "" && u.Get("pin-source") == "" { + pin, err := ui.PromptPassword("What is the PKCS#11 PIN?") + if err != nil { + fatal(err) + } + c.Pin = string(pin) + } + k, err := kms.New(context.Background(), apiv1.Options{ Type: string(apiv1.PKCS11), URI: c.KMS, From 1fb44068018e9ace78934f27b2587320a8a517e2 Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Tue, 15 Jun 2021 18:19:42 +0100 Subject: [PATCH 4/4] minimize diff --- cmd/step-pkcs11-init/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/step-pkcs11-init/main.go b/cmd/step-pkcs11-init/main.go index 0f3c8fa6..be30b1ad 100644 --- a/cmd/step-pkcs11-init/main.go +++ b/cmd/step-pkcs11-init/main.go @@ -119,7 +119,7 @@ func main() { fatal(err) } - if c.Pin == "" && u.Get("pin-value") == "" && u.Get("pin-source") == "" { + if u.Get("pin-value") == "" && u.Get("pin-source") == "" && c.Pin == "" { pin, err := ui.PromptPassword("What is the PKCS#11 PIN?") if err != nil { fatal(err)