@@ -278,12 +278,6 @@ def validate_signature(base64_cert, soft = true)
278278 noko_sig_element = document . at_xpath ( '//ds:Signature' , 'ds' => DSIG )
279279 noko_signed_info_element = noko_sig_element . at_xpath ( './ds:SignedInfo' , 'ds' => DSIG )
280280
281- # Handle when no URI
282- # noko_signed_info_reference_element_uri_attr = noko_signed_info_element.at_xpath('./ds:Reference', 'ds' => DSIG).attributes["URI"]
283- # if (noko_signed_info_reference_element_uri_attr.value.empty?)
284- # noko_signed_info_reference_element_uri_attr.value = "##{document.root.attribute('ID')}"
285- # end
286-
287281 canon_string = noko_signed_info_element . canonicalize ( canon_algorithm )
288282 noko_sig_element . remove
289283
@@ -294,8 +288,8 @@ def validate_signature(base64_cert, soft = true)
294288 ref = REXML ::XPath . first ( sig_element , "//ds:Reference" , { "ds" => DSIG } )
295289 uri = ref . attributes . get_attribute ( "URI" ) . value
296290
297- hashed_element = uri . empty? ? document : document . at_xpath ( "//*[@ID=$uri ]" , nil , { 'uri ' => uri [ 1 ..- 1 ] } )
298- # hashed_element = document.at_xpath("//*[@ID=$uri]", nil, { 'uri' => uri[1..-1] })
291+ hashed_element = document . at_xpath ( "//*[@ID=$id ]" , nil , { 'id ' => extract_signed_element_id } )
292+
299293 canon_algorithm = canon_algorithm REXML ::XPath . first (
300294 ref ,
301295 '//ds:CanonicalizationMethod' ,
@@ -350,7 +344,7 @@ def extract_signed_element_id
350344 return nil if reference_element . nil?
351345
352346 sei = reference_element . attribute ( "URI" ) . value [ 1 ..-1 ]
353- sei . nil? ? self . root . attribute ( "ID" ) : sei
347+ sei . nil? ? reference_element . parent . parent . parent . attribute ( "ID" ) . value : sei
354348 end
355349
356350 def extract_inclusive_namespaces
0 commit comments