@@ -326,6 +326,9 @@ def validate_signature(base64_cert, soft = true)
326326 '//ds:CanonicalizationMethod' ,
327327 { "ds" => DSIG }
328328 )
329+
330+ canon_algorithm = process_transforms ( ref , canon_algorithm )
331+
329332 canon_hashed_element = hashed_element . canonicalize ( canon_algorithm , inclusive_namespaces )
330333
331334 digest_algorithm = algorithm ( REXML ::XPath . first (
@@ -360,6 +363,33 @@ def validate_signature(base64_cert, soft = true)
360363
361364 private
362365
366+ def process_transforms ( ref , canon_algorithm )
367+ transforms = REXML ::XPath . match (
368+ ref ,
369+ "//ds:Transforms/ds:Transform" ,
370+ { "ds" => DSIG }
371+ )
372+
373+ transforms . each do |transform_element |
374+ if transform_element . attributes && transform_element . attributes [ "Algorithm" ]
375+ algorithm = transform_element . attributes [ "Algorithm" ]
376+ case algorithm
377+ when "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" ,
378+ "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
379+ canon_algorithm = Nokogiri ::XML ::XML_C14N_1_0
380+ when "http://www.w3.org/2006/12/xml-c14n11" ,
381+ "http://www.w3.org/2006/12/xml-c14n11#WithComments"
382+ canon_algorithm = Nokogiri ::XML ::XML_C14N_1_1
383+ when "http://www.w3.org/2001/10/xml-exc-c14n#" ,
384+ "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
385+ canon_algorithm = Nokogiri ::XML ::XML_C14N_EXCLUSIVE_1_0
386+ end
387+ end
388+ end
389+
390+ canon_algorithm
391+ end
392+
363393 def digests_match? ( hash , digest_value )
364394 hash == digest_value
365395 end
0 commit comments