Skip to content

Commit

Permalink
Merge pull request SAML-Toolkits#498 from onelogin/process_transform
Browse files Browse the repository at this point in the history
Implementing Process Transform. Related with
  • Loading branch information
pitbulk authored Nov 25, 2019
2 parents a7e45c2 + cb003ad commit 449dd6b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/xml_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ def validate_signature(base64_cert, soft = true)
'//ds:CanonicalizationMethod',
{ "ds" => DSIG }
)

canon_algorithm = process_transforms(ref, canon_algorithm)

canon_hashed_element = hashed_element.canonicalize(canon_algorithm, inclusive_namespaces)

digest_algorithm = algorithm(REXML::XPath.first(
Expand Down Expand Up @@ -360,6 +363,33 @@ def validate_signature(base64_cert, soft = true)

private

def process_transforms(ref, canon_algorithm)
transforms = REXML::XPath.match(
ref,
"//ds:Transforms/ds:Transform",
{ "ds" => DSIG }
)

transforms.each do |transform_element|
if transform_element.attributes && transform_element.attributes["Algorithm"]
algorithm = transform_element.attributes["Algorithm"]
case algorithm
when "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
canon_algorithm = Nokogiri::XML::XML_C14N_1_0
when "http://www.w3.org/2006/12/xml-c14n11",
"http://www.w3.org/2006/12/xml-c14n11#WithComments"
canon_algorithm = Nokogiri::XML::XML_C14N_1_1
when "http://www.w3.org/2001/10/xml-exc-c14n#",
"http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
canon_algorithm = Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0
end
end
end

canon_algorithm
end

def digests_match?(hash, digest_value)
hash == digest_value
end
Expand Down

0 comments on commit 449dd6b

Please sign in to comment.