@@ -80,6 +80,12 @@ class VerificationInput < DelegateClass(Verification::V1::Input)
80
80
81
81
def initialize ( *)
82
82
super
83
+
84
+ unless bundle . is_a? ( Bundle ::V1 ::Bundle )
85
+ raise ArgumentError ,
86
+ "bundle must be a #{ Bundle ::V1 ::Bundle } , is #{ bundle . class } "
87
+ end
88
+
83
89
@trusted_root = TrustedRoot . new ( artifact_trust_root )
84
90
@sbundle = SBundle . new ( bundle )
85
91
if sbundle . message_signature? && !artifact
@@ -138,13 +144,19 @@ def expected_tlog_entry(hashed_input)
138
144
expected_hashed_rekord_tlog_entry ( hashed_input )
139
145
when :dsse_envelope
140
146
rekor_entry = verification_material . tlog_entries . first
141
- case JSON . parse ( rekor_entry . canonicalized_body ) . values_at ( "kind" , "apiVersion" )
147
+ canonicalized_body = begin
148
+ JSON . parse ( rekor_entry . canonicalized_body )
149
+ rescue JSON ::ParserError
150
+ raise Error ::InvalidBundle , "expected canonicalized_body to be JSON"
151
+ end
152
+
153
+ case kind_version = canonicalized_body . values_at ( "kind" , "apiVersion" )
142
154
when %w[ dsse 0.0.1 ]
143
155
expected_dsse_0_0_1_tlog_entry
144
156
when %w[ intoto 0.0.2 ]
145
157
expected_intoto_0_0_2_tlog_entry
146
158
else
147
- raise Error ::InvalidRekorEntry , "Unhandled rekor entry kind/version: #{ t . inspect } "
159
+ raise Error ::InvalidRekorEntry , "Unhandled rekor entry kind/version: #{ kind_version . inspect } "
148
160
end
149
161
else
150
162
raise Error ::InvalidBundle , "expected either message_signature or dsse_envelope"
@@ -154,6 +166,8 @@ def expected_tlog_entry(hashed_input)
154
166
private
155
167
156
168
def validate_version!
169
+ raise Error ::InvalidBundle , "bundle requires verification material" unless verification_material
170
+
157
171
case bundle_type
158
172
when BundleType ::BUNDLE_0_1
159
173
unless verification_material . tlog_entries . all? ( &:inclusion_promise )
@@ -169,7 +183,7 @@ def validate_version!
169
183
raise Error ::InvalidBundle ,
170
184
"must contain an inclusion proof"
171
185
end
172
- unless verification_material . tlog_entries . all? { |t | t . inclusion_proof . checkpoint . envelope }
186
+ unless verification_material . tlog_entries . all? { |t | t . inclusion_proof . checkpoint & .envelope }
173
187
raise Error ::InvalidBundle ,
174
188
"inclusion proof must contain a checkpoint"
175
189
end
@@ -192,9 +206,9 @@ def validate_version!
192
206
when :certificate
193
207
@leaf_certificate = Internal ::X509 ::Certificate . read ( verification_material . certificate . raw_bytes )
194
208
else
195
- raise Error ::InvalidBundle , "Unsupported bundle content: #{ content } "
209
+ raise Error ::InvalidBundle , "Unsupported bundle content: #{ content . inspect } "
196
210
end
197
- raise Error ::InvalidBundle , "Expected leaf certificate" unless @leaf_certificate . leaf?
211
+ raise Error ::InvalidBundle , "expected certificate to be leaf " unless @leaf_certificate . leaf?
198
212
end
199
213
200
214
def expected_hashed_rekord_tlog_entry ( hashed_input )
0 commit comments