mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-01-22 08:14:08 +00:00
write the functioning p15 file
This commit is contained in:
parent
dd6c6bd442
commit
fc75922d18
2 changed files with 18 additions and 2 deletions
|
@ -2,7 +2,6 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"apc-p15-tool/pkg/pkcs15"
|
"apc-p15-tool/pkg/pkcs15"
|
||||||
"encoding/base64"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -59,7 +58,21 @@ func Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.logger.Debug(hex.EncodeToString(p15File))
|
// app.logger.Debug(hex.EncodeToString(p15File))
|
||||||
app.logger.Debug(base64.RawStdEncoding.EncodeToString(p15File))
|
// app.logger.Debug(base64.RawStdEncoding.EncodeToString(p15File))
|
||||||
|
|
||||||
|
apcHeader, err := makeFileHeader(p15File)
|
||||||
|
if err != nil {
|
||||||
|
app.logger.Fatalf("failed to make p15 file header (%s)", err)
|
||||||
|
// FATAL
|
||||||
|
}
|
||||||
|
|
||||||
|
apcFile := append(apcHeader, p15File...)
|
||||||
|
|
||||||
|
err = os.WriteFile("./apctool.p15", apcFile, 0777)
|
||||||
|
if err != nil {
|
||||||
|
app.logger.Fatalf("failed to write apc p15 file (%s)", err)
|
||||||
|
// FATAL
|
||||||
|
}
|
||||||
|
|
||||||
// TEMP TEMP TEMP
|
// TEMP TEMP TEMP
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ func (p15 *pkcs15KeyCert) encryptedKeyEnvelope() ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
wrappedCEK = append(wrappedCEK, cekPadding...)
|
wrappedCEK = append(wrappedCEK, cekPadding...)
|
||||||
|
|
||||||
// double encrypt CEK
|
// double encrypt CEK
|
||||||
|
@ -102,7 +103,9 @@ func (p15 *pkcs15KeyCert) encryptedKeyEnvelope() ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// envelope content (that will be encrypted)
|
||||||
content := p15.privateKeyObject()
|
content := p15.privateKeyObject()
|
||||||
|
|
||||||
// pad content, see: https://datatracker.ietf.org/doc/html/rfc3852 6.3
|
// pad content, see: https://datatracker.ietf.org/doc/html/rfc3852 6.3
|
||||||
contentPadLen := uint8(contentDesCipher.BlockSize() - (len(content) % contentDesCipher.BlockSize()))
|
contentPadLen := uint8(contentDesCipher.BlockSize() - (len(content) % contentDesCipher.BlockSize()))
|
||||||
// ALWAYS pad, if content is exact, add full block of padding
|
// ALWAYS pad, if content is exact, add full block of padding
|
||||||
|
|
Loading…
Reference in a new issue