fix: use tpm2 hash algorithm constants and allow non-SHA-256 PCRs
The conversion from TPM 2 hash algorithm to Go crypto algorithm will fail for uncommon algorithms like SM3256. This can be avoided by checking the constants directly, rather than converting them. It should also be fine to allow some non SHA-256 PCRs. Fixes: #7810 Signed-off-by: Thomas Way <thomas@6f.io> Signed-off-by: Noel Georgi <git@frezbo.dev>
This commit is contained in:
parent
69d8054c9e
commit
336aee0fdb
@ -7,7 +7,6 @@ package tpm2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -164,15 +163,10 @@ func validatePCRBanks(t transport.TPM) error {
|
||||
}
|
||||
|
||||
for _, s := range assignedPCRs.PCRSelections {
|
||||
h, err := s.Hash.Hash()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse hash algorithm: %v", err)
|
||||
if s.Hash != tpm2.TPMAlgSHA256 {
|
||||
continue
|
||||
}
|
||||
|
||||
switch h { //nolint:exhaustive
|
||||
case crypto.SHA1:
|
||||
continue
|
||||
case crypto.SHA256:
|
||||
// check if 24 banks are available
|
||||
if len(s.PCRSelect) != 24/8 {
|
||||
return fmt.Errorf("unexpected number of PCR banks: %d", len(s.PCRSelect))
|
||||
@ -182,13 +176,6 @@ func validatePCRBanks(t transport.TPM) error {
|
||||
if s.PCRSelect[0] != 0xff || s.PCRSelect[1] != 0xff || s.PCRSelect[2] != 0xff {
|
||||
return fmt.Errorf("unexpected PCR banks: %v", s.PCRSelect)
|
||||
}
|
||||
case crypto.SHA384:
|
||||
continue
|
||||
case crypto.SHA512:
|
||||
continue
|
||||
default:
|
||||
return fmt.Errorf("unsupported hash algorithm: %s", h.String())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user