mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-01-22 00:04:09 +00:00
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:
parent
01be6ca577
commit
da84a7b085
3 changed files with 29 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
# key/cert files
|
||||
*.p15
|
||||
*.pem
|
||||
*.b64
|
||||
|
||||
# ignore test_data folder
|
||||
/_test_data
|
||||
|
|
|
@ -2,6 +2,7 @@ package app
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"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)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func (app *app) getConfig(args []string) error {
|
|||
// apc-p15-tool -- root command
|
||||
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{
|
||||
Name: "apc-p15-tool",
|
||||
|
|
Loading…
Reference in a new issue