Skip to content

Commit 3674005

Browse files
committed
working NewPCRs
1 parent d6ff50c commit 3674005

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

tarzan/tpm2/endpointstpm2new.go

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,40 @@ func openTPM(dev string) (transport.TPMCloser, error) {
2424
return tpm, err
2525
}
2626

27+
var npcrbanks = []tpm2.TPMIAlgHash{tpm2.TPMAlgSHA1, tpm2.TPMAlgSHA256, tpm2.TPMAlgSHA384, tpm2.TPMAlgSHA512}
28+
2729
func NewPCRs(c echo.Context) error {
30+
31+
fmt.Println("NEW tpm2 pcrs called")
32+
33+
tpm, err := openTPM("/dev/tpmrm0")
34+
if err != nil {
35+
rtn := tpm2taErrorReturn{fmt.Sprintf("Could not open tpm with error %v", err.Error())}
36+
return c.JSON(http.StatusUnprocessableEntity, rtn)
37+
}
38+
fmt.Printf("TPM device open by linuxtransport is %v\n", tpm)
39+
40+
for _, b := range npcrbanks {
41+
for i := 0; i <= 23; i++ {
42+
fmt.Printf("Reading back %v, pcr %v -->\n", b, i)
43+
44+
s2 := tpm2.TPMSPCRSelection{Hash: b, PCRSelect: tpm2.PCClientCompatible.PCRs(uint(i))}
45+
46+
pcrselections := []tpm2.TPMSPCRSelection{s2}
47+
selection := tpm2.TPMLPCRSelection{PCRSelections: pcrselections}
48+
fmt.Printf("PCR selection is %v\n", selection)
49+
50+
pcrreadresponse, err := tpm2.PCRRead{PCRSelectionIn: selection}.Execute(tpm)
51+
fmt.Printf("PCR pcrreadresponse is %w, %v\n", err, pcrreadresponse)
52+
}
53+
}
54+
55+
return c.JSON(http.StatusOK, npcrbanks)
56+
}
57+
58+
// IGNORE THIS CODE; IT WORKS SO I AM NOT TOUCHING IT
59+
60+
func xNewPCRs(c echo.Context) error {
2861
fmt.Println("NEW tpm2 pcrs called")
2962

3063
tpm, err := openTPM("/dev/tpmrm0")
@@ -34,11 +67,10 @@ func NewPCRs(c echo.Context) error {
3467
}
3568
fmt.Printf("TPM device open by linuxtranport is %v\n", tpm)
3669

37-
//DebugPCR := uint(16)
38-
s1 := tpm2.TPMSPCRSelection{Hash: tpm2.TPMAlgSHA1, PCRSelect: tpm2.PCClientCompatible.PCRs(0, 1, 2, 3)}
39-
//s2 := tpm2.TPMSPCRSelection{Hash: 0x000B, PCRSelect: []uint8{4, 5, 11, 16, 23}}
70+
s1 := tpm2.TPMSPCRSelection{Hash: tpm2.TPMAlgSHA1, PCRSelect: tpm2.PCClientCompatible.PCRs(0)}
71+
s2 := tpm2.TPMSPCRSelection{Hash: tpm2.TPMAlgSHA256, PCRSelect: tpm2.PCClientCompatible.PCRs(0)}
4072

41-
pcrselections := []tpm2.TPMSPCRSelection{s1}
73+
pcrselections := []tpm2.TPMSPCRSelection{s1, s2}
4274
selection := tpm2.TPMLPCRSelection{PCRSelections: pcrselections}
4375
fmt.Printf("PCR selection is %v\n", selection)
4476

@@ -47,5 +79,5 @@ func NewPCRs(c echo.Context) error {
4779

4880
//tpm2.PCRSelections{[]tpm2.PCRSelection{Hash: "sha256", PCRSelect: []byte{0, 1, 2, 3}}}
4981

50-
return c.JSON(http.StatusOK, "fred")
82+
return c.JSON(http.StatusOK, pcrreadresponse)
5183
}

0 commit comments

Comments
 (0)