From b44b49cd19c3a1d80fc3a7147ece2edb6a25ec7c Mon Sep 17 00:00:00 2001 From: "Greg T. Wallace" Date: Tue, 4 Jun 2024 18:59:36 -0400 Subject: [PATCH] create: add additional flag to signal creation of additional key.p15 --- pkg/app/cmd_create.go | 26 ++++++++++++++++---------- pkg/app/config.go | 2 ++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/app/cmd_create.go b/pkg/app/cmd_create.go index c6b6750..ad31003 100644 --- a/pkg/app/cmd_create.go +++ b/pkg/app/cmd_create.go @@ -47,19 +47,13 @@ func (app *app) cmdCreate(_ context.Context, args []string) error { keyFileName = *app.config.create.outKeyFilePath } - // write files + // write file(s) err = os.WriteFile(keyCertFileName, apcKeyCertFile, 0600) if err != nil { return fmt.Errorf("create: failed to write apc p15 key+cert file (%s)", err) } app.stdLogger.Printf("create: apc p15 key+cert file %s written to disk", keyCertFileName) - err = os.WriteFile(keyFileName, keyFile, 0600) - if err != nil { - return fmt.Errorf("create: failed to write apc p15 key file (%s)", err) - } - app.stdLogger.Printf("create: apc p15 key file %s written to disk", keyFileName) - // if debug, write additional debug files (b64 format to make copy/paste into asn1 decoder // easy to do e.g., https://lapo.it/asn1js) if app.config.debugLogging != nil && *app.config.debugLogging { @@ -77,13 +71,25 @@ func (app *app) cmdCreate(_ context.Context, args []string) error { } app.debugLogger.Printf("create: apc p15 key+cert file header %s written to disk", keyCertFileNameHeaderDebug) - keyFileNameDebug := keyFileName + ".b64" - err = os.WriteFile(keyFileNameDebug, []byte(base64.StdEncoding.EncodeToString(keyFile)), 0600) + } + + // make key p15 ? + if app.config.create.makeKeyP15 != nil && *app.config.create.makeKeyP15 { + err = os.WriteFile(keyFileName, keyFile, 0600) if err != nil { return fmt.Errorf("create: failed to write apc p15 key file (%s)", err) } - app.debugLogger.Printf("create: apc p15 key file %s written to disk", keyFileNameDebug) + app.stdLogger.Printf("create: apc p15 key file %s written to disk", keyFileName) + // debug file ? + if app.config.debugLogging != nil && *app.config.debugLogging { + keyFileNameDebug := keyFileName + ".b64" + err = os.WriteFile(keyFileNameDebug, []byte(base64.StdEncoding.EncodeToString(keyFile)), 0600) + if err != nil { + return fmt.Errorf("create: failed to write apc p15 key file (%s)", err) + } + app.debugLogger.Printf("create: apc p15 key file %s written to disk", keyFileNameDebug) + } } return nil diff --git a/pkg/app/config.go b/pkg/app/config.go index e8ff1fc..a3b18c1 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -29,6 +29,7 @@ type config struct { create struct { keyCertPemCfg outFilePath *string + makeKeyP15 *bool outKeyFilePath *string } install struct { @@ -73,6 +74,7 @@ func (app *app) getConfig(args []string) error { cfg.create.keyPem = createFlags.StringLong("keypem", "", "string of the rsa-1024 or rsa-2048 key in pem format") cfg.create.certPem = createFlags.StringLong("certpem", "", "string of the certificate in pem format") cfg.create.outFilePath = createFlags.StringLong("outfile", createDefaultOutFilePath, "path and filename to write the key+cert p15 file to") + cfg.create.makeKeyP15 = createFlags.BoolLong("keyp15", "create a second p15 file with just the private key") cfg.create.outKeyFilePath = createFlags.StringLong("outkeyfile", createDefaultOutKeyFilePath, "path and filename to write the key p15 file to") createCmd := &ff.Command{