Skip to content

Commit 318545e

Browse files
committed
Make SignKM accept generic crypto.Signer
Accepting crypto.PrivateKey uneccessarily restricts this library to software crypto algorithms provided by the golang crypto packages. By allowing the more generic crypto.Signer interface alternative implementations, e.g., backed by HSMs, can be supported.
1 parent 5f38440 commit 318545e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cmd/core/bg-prov/cmd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"crypto"
56
"encoding/binary"
67
"fmt"
78
"os"
@@ -858,7 +859,7 @@ func (s *signKMCmd) Run(ctx *context) error {
858859
if err != nil {
859860
return err
860861
}
861-
bKMSigned, err := bg.SignKM(s.SignAlgo, privkey)
862+
bKMSigned, err := bg.SignKM(s.SignAlgo, privkey.(crypto.Signer))
862863
if err != nil {
863864
return err
864865
}

pkg/provisioning/bootguard/bootguard.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (b *BootGuard) StitchBPM(pubKey crypto.PublicKey, signature []byte) ([]byte
419419
}
420420

421421
// SignKM signs an unsigned KM with signAlgo and private key as input
422-
func (b *BootGuard) SignKM(signAlgo string, privkey crypto.PrivateKey) ([]byte, error) {
422+
func (b *BootGuard) SignKM(signAlgo string, signer crypto.Signer) ([]byte, error) {
423423
buf := new(bytes.Buffer)
424424
switch b.Version {
425425
case bgheader.Version10:
@@ -433,7 +433,7 @@ func (b *BootGuard) SignKM(signAlgo string, privkey crypto.PrivateKey) ([]byte,
433433
return nil, err
434434
}
435435
unsignedKM := buf.Bytes()[:b.VData.BGkm.KeyAndSignatureOffset()]
436-
if err := b.VData.BGkm.SetSignature(signAlgo, privkey.(crypto.Signer), unsignedKM); err != nil {
436+
if err := b.VData.BGkm.SetSignature(signAlgo, signer, unsignedKM); err != nil {
437437
return nil, err
438438
}
439439
case bgheader.Version20:
@@ -447,7 +447,7 @@ func (b *BootGuard) SignKM(signAlgo string, privkey crypto.PrivateKey) ([]byte,
447447
return nil, err
448448
}
449449
unsignedKM := buf.Bytes()[:b.VData.CBNTkm.KeyAndSignatureOffset()]
450-
if err = b.VData.CBNTkm.SetSignature(signAlgo, b.VData.CBNTkm.PubKeyHashAlg, privkey.(crypto.Signer), unsignedKM); err != nil {
450+
if err = b.VData.CBNTkm.SetSignature(signAlgo, b.VData.CBNTkm.PubKeyHashAlg, signer, unsignedKM); err != nil {
451451
return nil, err
452452
}
453453
default:

0 commit comments

Comments
 (0)