Skip to content

Commit 3fcb93c

Browse files
author
Ian Oliver
committed
Added error check to PCRSelection processing
1 parent 843deaa commit 3fcb93c

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

tarzan/tpm2/endpointquotetpm2new.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,24 @@ func NewQuote(c echo.Context) error {
5757
s := strings.Split(params["pcrSelection"].(string), ",")
5858
fmt.Printf("pcr selection string: %v\n", s)
5959

60-
// *** This is the old code which does not work
61-
// pcrselectionlist := []tpm2.TPMSPCRSelection{}
62-
// for _, r := range s {
63-
// v64, err := strconv.ParseUint(r, 10, 8)
64-
// fmt.Printf("creating pcrselection for %v,%v,%v\n", err, pcrbank, v64)
65-
// if err == nil {
66-
// pcrsel := tpm2.TPMSPCRSelection{Hash: pcrbank, PCRSelect: tpm2.PCClientCompatible.PCRs(uint(v64))}
67-
// pcrselectionlist = append(pcrselectionlist, pcrsel)
68-
// }
69-
// }
70-
// ***
60+
// TPM PCR Selection stuff fixed: https://github.com/google/go-tpm/issues/407
7161

7262
var indcies = make([]uint, len(s))
7363
for i, r := range s {
74-
v, _ := strconv.ParseUint(r, 10, 8)
64+
v, err := strconv.ParseUint(r, 10, 8)
65+
if err != nil {
66+
rtn := tpm2taErrorReturn{fmt.Sprintf("Unable to parse PCRSelection %v in selection %s", v, s)}
67+
return c.JSON(http.StatusUnprocessableEntity, rtn)
68+
}
7569
indcies[i] = uint(v)
76-
// TODO err
7770
}
71+
7872
pcrSelection := tpm2.TPMSPCRSelection{
7973
Hash: pcrbank,
8074
PCRSelect: tpm2.PCClientCompatible.PCRs(indcies...),
8175
}
8276

8377
pcrselectionlist := tpm2.TPMLPCRSelection{PCRSelections: []tpm2.TPMSPCRSelection{pcrSelection}}
84-
85-
// *** This is the old code which does not work
86-
// PCR selection (selecting PCR 7 for this example)
87-
// pcrSelection := tpm2.TPMLPCRSelection{
88-
// PCRSelections: pcrselectionlist,
89-
// }
90-
//***
91-
9278
fmt.Printf("PCRselectionlist is %v\n", pcrselectionlist)
9379

9480
// Here we parse the nonce

0 commit comments

Comments
 (0)