@@ -28,10 +28,10 @@ func TestCELEncodingDecoding(t *testing.T) {
28
28
cel := & CEL {}
29
29
30
30
cosEvent := CosTlv {ImageDigestType , []byte ("sha256:781d8dfdd92118436bd914442c8339e653b83f6bf3c1a7a98efcfb7c4fed7483" )}
31
- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent )
31
+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent )
32
32
33
33
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 )
35
35
36
36
var buf bytes.Buffer
37
37
if err := cel .EncodeCEL (& buf ); err != nil {
@@ -92,19 +92,19 @@ func TestCELMeasureAndReplay(t *testing.T) {
92
92
rand .Read (someEvent2 )
93
93
cosEvent2 := CosTlv {ImageDigestType , someEvent2 }
94
94
95
- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent )
95
+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent )
96
96
appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
97
97
98
- appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , measuredHashes , cosEvent2 )
98
+ appendPcrEventOrFatal (t , cel , tpm , test .DebugPCR , cosEvent2 )
99
99
appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
100
100
101
- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent2 )
101
+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent2 )
102
102
appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent2 )
103
103
104
- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent )
104
+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent )
105
105
appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
106
106
107
- appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , measuredHashes , cosEvent )
107
+ appendPcrEventOrFatal (t , cel , tpm , test .ApplicationPCR , cosEvent )
108
108
appendRtmrEventOrFatal (t , celRTMR , fakeRTMR , CosRTMR , cosEvent )
109
109
110
110
replay (t , cel , tpm , measuredHashes ,
@@ -127,11 +127,11 @@ func TestCELReplayFailTamperedDigest(t *testing.T) {
127
127
rand .Read (someEvent2 )
128
128
cosEvent2 := CosTlv {ImageDigestType , someEvent2 }
129
129
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 )
135
135
136
136
modifiedRecord := cel .Records [3 ]
137
137
for hash := range modifiedRecord .Digests {
@@ -162,15 +162,51 @@ func TestCELReplayFailMissingPCRsInBank(t *testing.T) {
162
162
someEvent2 := make ([]byte , 10 )
163
163
rand .Read (someEvent2 )
164
164
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 })
167
167
168
168
replay (t , cel , tpm , measuredHashes ,
169
169
[]int {test .DebugPCR }, false /*shouldSucceed*/ )
170
170
replay (t , cel , tpm , measuredHashes ,
171
171
[]int {test .ApplicationPCR }, false /*shouldSucceed*/ )
172
172
}
173
173
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
+
174
210
func replay (t * testing.T , cel * CEL , tpm io.ReadWriteCloser , measuredHashes []crypto.Hash , pcrs []int , shouldSucceed bool ) {
175
211
for _ , hash := range measuredHashes {
176
212
tpm2Hash , err := tpm2 .HashToAlgorithm (hash )
@@ -217,8 +253,8 @@ func replayRTMR(t *testing.T, cel *CEL, rtmr *fakertmr.RtmrSubsystem, rtmrs []in
217
253
}
218
254
}
219
255
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 {
222
258
t .Fatalf ("failed to append PCR event: %v" , err )
223
259
}
224
260
}
0 commit comments