Skip to content

Commit

Permalink
Full namespace for XPath
Browse files Browse the repository at this point in the history
  • Loading branch information
morten committed Jan 28, 2011
1 parent 25d3d32 commit 9b2d559
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/xml_security.rb
Expand Up @@ -52,18 +52,18 @@ def validate_doc(base64_cert, logger)
# validate references

# remove signature node
sig_element = XPath.first(self, "//ds:Signature", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"})
sig_element = REXML::XPath.first(self, "//ds:Signature", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"})
sig_element.remove

#check digests
XPath.each(sig_element, "//ds:Reference", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"}) do | ref |
REXML::XPath.each(sig_element, "//ds:Reference", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"}) do | ref |

uri = ref.attributes.get_attribute("URI").value
hashed_element = XPath.first(self, "//[@ID='#{uri[1,uri.size]}']")
hashed_element = REXML::XPath.first(self, "//[@ID='#{uri[1,uri.size]}']")
canoner = XML::Util::XmlCanonicalizer.new(false, true)
canon_hashed_element = canoner.canonicalize(hashed_element)
hash = Base64.encode64(Digest::SHA1.digest(canon_hashed_element)).chomp
digest_value = XPath.first(ref, "//ds:DigestValue", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"}).text
digest_value = REXML::XPath.first(ref, "//ds:DigestValue", {"ds"=>"http://www.w3.org/2000/09/xmldsig#"}).text

valid_flag = hash == digest_value

Expand Down

0 comments on commit 9b2d559

Please sign in to comment.