@@ -28,10 +28,10 @@ func TestCELEncodingDecoding(t *testing.T) {
2828 cel := & CEL {}
2929
3030 cosEvent := CosTlv {ImageDigestType , []byte ("sha256:781d8dfdd92118436bd914442c8339e653b83f6bf3c1a7a98efcfb7c4fed7483" )}
31- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent )
31+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent )
3232
3333 cosEvent2 := CosTlv {ImageRefType , []byte ("docker.io/bazel/experimental/test:latest" )}
34- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent2 )
34+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent2 )
3535
3636 var buf bytes.Buffer
3737 if err := cel .EncodeCEL (& buf ); err != nil {
@@ -92,19 +92,19 @@ func TestCELMeasureAndReplay(t *testing.T) {
9292 rand .Read (someEvent2 )
9393 cosEvent2 := CosTlv {ImageDigestType , someEvent2 }
9494
95- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent )
95+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent )
9696 appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
9797
98- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent2 )
98+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent2 )
9999 appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
100100
101- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent2 )
101+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent2 )
102102 appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent2 )
103103
104- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent )
104+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent )
105105 appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
106106
107- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent )
107+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent )
108108 appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
109109
110110 replay (t , cel , tpm , measuredHashes ,
@@ -127,11 +127,11 @@ func TestCELReplayFailTamperedDigest(t *testing.T) {
127127 rand .Read (someEvent2 )
128128 cosEvent2 := CosTlv {ImageDigestType , someEvent2 }
129129
130- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent )
131- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent2 )
132- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent2 )
133- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent )
134- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent )
130+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent )
131+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent2 )
132+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent2 )
133+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent )
134+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent )
135135
136136 modifiedRecord := cel .Records [3 ]
137137 for hash := range modifiedRecord .Digests {
@@ -162,15 +162,51 @@ func TestCELReplayFailMissingPCRsInBank(t *testing.T) {
162162 someEvent2 := make ([]byte , 10 )
163163 rand .Read (someEvent2 )
164164
165- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , CosTlv {ImageRefType , someEvent })
166- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , CosTlv {ImageDigestType , someEvent2 })
165+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , CosTlv {ImageRefType , someEvent })
166+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , CosTlv {ImageDigestType , someEvent2 })
167167
168168 replay (t , cel , tpm , measuredHashes ,
169169 []int {test .DebugPCR }, false /*shouldSucceed*/ )
170170 replay (t , cel , tpm , measuredHashes ,
171171 []int {test .ApplicationPCR }, false /*shouldSucceed*/ )
172172}
173173
174+ func TestCELMeasureToAllPCRBanks (t * testing.T ) {
175+ tpm := test .GetTPM (t )
176+ defer client .CheckedClose (t , tpm )
177+
178+ pcrs , err := client .ReadAllPCRs (tpm )
179+ if err != nil {
180+ t .Fatal (err )
181+ }
182+ for _ , bank := range pcrs {
183+ // make sure debug pcr is empty before the append
184+ if ! isZeroBytes (bank .Pcrs [uint32 (test .DebugPCR )]) {
185+ t .Fatalf ("PCR %d in bank %s is not empty before appending event" , test .DebugPCR , bank .Hash .String ())
186+ }
187+ }
188+
189+ cel := & CEL {}
190+ someEvent := make ([]byte , 10 )
191+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , CosTlv {ImageRefType , someEvent })
192+
193+ pcrs , err = client .ReadAllPCRs (tpm )
194+ if err != nil {
195+ t .Fatal (err )
196+ }
197+ for _ , bank := range pcrs {
198+ // make sure debug pcr is NOT empty after the append
199+ if isZeroBytes (bank .Pcrs [uint32 (test .DebugPCR )]) {
200+ t .Fatalf ("PCR %d in bank %s is empty after appending event" , test .DebugPCR , bank .Hash .String ())
201+ }
202+ }
203+ }
204+
205+ func isZeroBytes (bs []byte ) bool {
206+ allZeros := make ([]byte , len (bs ))
207+ return bytes .Equal (allZeros , bs )
208+ }
209+
174210func replay (t * testing.T , cel * CEL , tpm io.ReadWriteCloser , measuredHashes []crypto.Hash , pcrs []int , shouldSucceed bool ) {
175211 for _ , hash := range measuredHashes {
176212 tpm2Hash , err := tpm2 .HashToAlgorithm (hash )
@@ -217,8 +253,8 @@ func replayRTMR(t *testing.T, cel *CEL, rtmr *fakertmr.RtmrSubsystem, rtmrs []in
217253 }
218254}
219255
220- func appendPcrEventOrFatal (t * testing.T , cel * CEL , tpm io.ReadWriteCloser , pcr int , hashAlgos []crypto. Hash , event Content ) {
221- if err := cel .AppendEventPCR (tpm , pcr , hashAlgos , event ); err != nil {
256+ func appendPcrEventOrFatal (t * testing.T , cel * CEL , tpm io.ReadWriteCloser , pcr int , event Content ) {
257+ if err := cel .AppendEventPCR (tpm , pcr , event ); err != nil {
222258 t .Fatalf ("failed to append PCR event: %v" , err )
223259 }
224260}
0 commit comments