mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-01-22 16:14:09 +00:00
01be6ca577
The NMC Security Wizard can also produce .p15 files that contain just a private key. Add this ability to this tool. When the `create` function is used, both files will be outputted.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package app
|
|
|
|
import (
|
|
"apc-p15-tool/pkg/pkcs15"
|
|
"fmt"
|
|
)
|
|
|
|
// pemToAPCP15s reads the specified pem files and returns the apc p15 files (both a
|
|
// p15 file with just the private key, and also a p15 file with both the private key
|
|
// and certificate). The key+cert file includes the required APC header, prepended.
|
|
func (app *app) pemToAPCP15s(keyPem, certPem []byte, parentCmdName string) (apcKeyCertFile, keyFile []byte, err error) {
|
|
app.stdLogger.Printf("%s: making apc p15 file from pem", parentCmdName)
|
|
|
|
// make p15 struct
|
|
p15, err := pkcs15.ParsePEMToPKCS15(keyPem, certPem)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("%s: failed to parse pem files (%w)", parentCmdName, err)
|
|
}
|
|
|
|
app.stdLogger.Printf("%s: successfully loaded pem files", parentCmdName)
|
|
|
|
// make file bytes
|
|
keyCertFile, keyFile, err := p15.ToP15Files()
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("%s: failed to make p15 file (%w)", parentCmdName, err)
|
|
}
|
|
|
|
// make header for file bytes
|
|
apcHeader, err := makeFileHeader(keyCertFile)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("%s: failed to make p15 file header (%w)", parentCmdName, err)
|
|
}
|
|
|
|
// combine header with file
|
|
apcKeyCertFile = append(apcHeader, keyCertFile...)
|
|
|
|
app.stdLogger.Printf("%s: apc p15 file data succesfully generated", parentCmdName)
|
|
|
|
return apcKeyCertFile, keyFile, nil
|
|
}
|