webhookd/pkg/truststore/p12_truststore.go
Nicolas Carlier f2054d2dc4 feat(signature): signature refactoring
- add ed5519 HTTP signature support
- refactor truststore package
- add P12 trust store support

close #72
2022-12-29 17:14:28 +00:00

32 lines
609 B
Go

package truststore
import (
"crypto"
"io/ioutil"
"github.com/ncarlier/webhookd/pkg/logger"
"golang.org/x/crypto/pkcs12"
)
func newP12TrustStore(filename string) (TrustStore, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
_, cert, err := pkcs12.Decode(data, "test")
if err != nil {
return nil, err
}
result := &InMemoryTrustStore{
Keys: make(map[string]crypto.PublicKey),
}
keyID := string(cert.Subject.CommonName)
result.Keys[keyID] = cert.PublicKey
logger.Debug.Printf("certificate \"%s\" loaded into the trustore", keyID)
return result, nil
}