app: restructure and start building p15 output

This commit is contained in:
Greg T. Wallace 2024-01-25 20:16:37 -05:00
parent 6610c92058
commit e2e4f2037c
24 changed files with 622 additions and 168 deletions
pkg/pkcs15

35
pkg/pkcs15/keyid.go Normal file
View file

@ -0,0 +1,35 @@
package pkcs15
import (
"apc-p15-tool/pkg/tools/asn1obj"
"crypto/sha1"
"math/big"
)
// keyId returns the keyId for the overall key object
func (p15 *pkcs15KeyCert) keyId() []byte {
// Create Object to hash
hashObj := asn1obj.Sequence([][]byte{
asn1obj.Sequence([][]byte{
// Key is RSA
asn1obj.ObjectIdentifier(asn1obj.OIDrsaEncryptionPKCS1),
asn1obj.Null(),
}),
// BIT STRING of rsa key public key
asn1obj.BitString(
asn1obj.Sequence([][]byte{
asn1obj.Integer(p15.key.N),
asn1obj.Integer((big.NewInt(int64(p15.key.E)))),
}),
),
})
// SHA-1 Hash
hasher := sha1.New()
_, err := hasher.Write(hashObj)
if err != nil {
panic(err)
}
return hasher.Sum(nil)
}