debug: add base64 encoded debug files

When troubleshooting it is helpful to put the generated files into an asn1 decoder. The files can be copy/pasted easily in b64 format.

This change creates b64 files when the debug flag is set to make this process easier.
This commit is contained in:
Greg T. Wallace 2024-06-04 18:59:36 -04:00
parent 01be6ca577
commit da84a7b085
3 changed files with 29 additions and 1 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
# key/cert files # key/cert files
*.p15 *.p15
*.pem *.pem
*.b64
# ignore test_data folder # ignore test_data folder
/_test_data /_test_data

View file

@ -2,6 +2,7 @@ package app
import ( import (
"context" "context"
"encoding/base64"
"fmt" "fmt"
"os" "os"
) )
@ -59,5 +60,31 @@ func (app *app) cmdCreate(_ context.Context, args []string) error {
} }
app.stdLogger.Printf("create: apc p15 key file %s written to disk", keyFileName) 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 {
keyCertFileNameDebug := keyCertFileName + ".noheader.b64"
err = os.WriteFile(keyCertFileNameDebug, []byte(base64.StdEncoding.EncodeToString(apcKeyCertFile[apcHeaderLen:])), 0777)
if err != nil {
return fmt.Errorf("create: failed to write apc p15 key+cert file (%s)", err)
}
app.debugLogger.Printf("create: apc p15 key+cert file %s written to disk", keyCertFileNameDebug)
keyCertFileNameHeaderDebug := keyCertFileName + ".header.b64"
err = os.WriteFile(keyCertFileNameHeaderDebug, []byte(base64.StdEncoding.EncodeToString(apcKeyCertFile[apcHeaderLen:])), 0777)
if err != nil {
return fmt.Errorf("create: failed to write apc p15 key+cert file (%s)", err)
}
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)), 0777)
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 return nil
} }

View file

@ -57,7 +57,7 @@ func (app *app) getConfig(args []string) error {
// apc-p15-tool -- root command // apc-p15-tool -- root command
rootFlags := ff.NewFlagSet("apc-p15-tool") rootFlags := ff.NewFlagSet("apc-p15-tool")
cfg.debugLogging = rootFlags.BoolLong("debug", "set this flag to enable additional debug logging messages") cfg.debugLogging = rootFlags.BoolLong("debug", "set this flag to enable additional debug logging messages and files")
rootCmd := &ff.Command{ rootCmd := &ff.Command{
Name: "apc-p15-tool", Name: "apc-p15-tool",