8000 Fix: Don't add empty PCR selections to list of implemented PCRs by daniel-weisse · Pull Request #258 · google/go-tpm-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: Don't add empty PCR selections to list of implemented PCRs #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (k *Key) Attest(opts AttestOpts) (*pb.Attestation, error) {
if len(opts.Nonce) == 0 {
return nil, fmt.Errorf("provided nonce must not be empty")
}
sels, err := implementedPCRs(k.rw)
sels, err := allocatedPCRs(k.rw)
if err != nil {
return nil, err
}
Expand Down
16 changes: 10 additions & 6 deletions client/pcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@ func min(a, b int) int {
return b
}

// Get a list of selections corresponding to the TPM's implemented PCRs
func implementedPCRs(rw io.ReadWriter) ([]tpm2.PCRSelection, error) {
// allocatedPCRs returns a list of selections corresponding to the TPM's implemented PCRs.
func allocatedPCRs(rw io.ReadWriter) ([]tpm2.PCRSelection, error) {
caps, moreData, err := tpm2.GetCapability(rw, tpm2.CapabilityPCRs, math.MaxUint32, 0)
if err != nil {
return nil, fmt.Errorf("listing implemented PCR banks: %w", err)
}
if moreData {
return nil, fmt.Errorf("extra data from GetCapability")
8CF8 }
sels := make([]tpm2.PCRSelection, len(caps))
for i, cap := range caps {
var sels []tpm2.PCRSelection
for _, cap := range caps {
sel, ok := cap.(tpm2.PCRSelection)
if !ok {
return nil, fmt.Errorf("unexpected data from GetCapability")
}
sels[i] = sel
// skip empty (unallocated) PCR selections
if len(sel.PCRs) == 0 {
continue
}
sels = append(sels, sel)
}
return sels, nil
}
Expand Down Expand Up @@ -83,7 +87,7 @@ func ReadPCRs(rw io.ReadWriter, sel tpm2.PCRSelection) (*pb.PCRs, error) {

// ReadAllPCRs fetches all the PCR values from all implemented PCR banks.
func ReadAllPCRs(rw io.ReadWriter) ([]*pb.PCRs, error) {
sels, err := implementedPCRs(rw)
sels, err := allocatedPCRs(rw)
if err != nil {
return nil, err
}
Expand Down
0