Class: WSS4R::Security::Xml::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/wss4r/security/xml/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, prefix_list = nil) ⇒ Reference

Returns a new instance of Reference.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wss4r/security/xml/reference.rb', line 8

def initialize(element, prefix_list = nil)
         @ref_element = nil
         @transforms = Array.new()
         @prefix_list = prefix_list
         @uri = element.attribute("URI").to_s()[1..-1] #remove leading #
	
         elements = XPath.match(element, "Transforms/Transform", {"ds:" => Namespaces::DS})
         #element.each_element("ds:Transforms/ds:Transform"){|e|
         elements.each{|e|
           @transforms.push(e.attribute("Algorithm"))
         }
         elements = XPath.match(element, "ds:DigestMethod", {"ds" => Namespaces::DS})
         #element.each_element("ds:DigestMethod"){|e|
         elements.each{|e|
           @digest_algorithm = e.attribute("Algorithm")
         }
         elements = XPath.match(element, "ds:DigestValue", {"ds" => Namespaces::DS})
         #element.each_element("ds:DigestValue"){|e|
         elements.each{|e|
           @digest_value = e.text().strip()
         }
         @ref_element = XPath.first(element.document, "//*[@wsu:Id='"+@uri+"']")
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/wss4r/security/xml/reference.rb', line 6

def uri
  @uri
end

Instance Method Details

#verifyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wss4r/security/xml/reference.rb', line 32

def verify()
         trans_element = nil
         @transforms.each{|transform_algorithm|
           transformer = TransformerFactory::get_instance(transform_algorithm)
           transformer.prefix_list=(@prefix_list)
           trans_element = transformer.canonicalize_element(@ref_element)
         }
         if (@transforms.size() == 0)
           transformer = TransformerFactory::get_instance("http://www.w3.org/2001/10/xml-exc-c14n#")
           transformer.prefix_list=(@prefix_list)
           trans_element = transformer.canonicalize_element(@ref_element)
         end
         digester = DigestFactory::get_instance(@digest_algorithm.value())
         digest = digester.digest_b64(trans_element)
         return true if (digest == @digest_value)
         false
end