Class: Akami::WSSE::VerifySignature

Inherits:
Object
  • Object
show all
Includes:
C14nHelper, XPathHelper
Defined in:
lib/akami/wsse/verify_signature.rb

Defined Under Namespace

Classes: InvalidDigest, InvalidSignedValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from C14nHelper

#canonicalize

Methods included from XPathHelper

#at_xpath, #local_name_xpath, #xpath

Constructor Details

#initialize(response_body) ⇒ VerifySignature

Returns a new instance of VerifySignature.



14
15
16
17
# File 'lib/akami/wsse/verify_signature.rb', line 14

def initialize(response_body)
  @response_body = response_body
  @document = create_document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



12
13
14
# File 'lib/akami/wsse/verify_signature.rb', line 12

def document
  @document
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



12
13
14
# File 'lib/akami/wsse/verify_signature.rb', line 12

def response_body
  @response_body
end

Instance Method Details

#certificateObject



35
36
37
38
# File 'lib/akami/wsse/verify_signature.rb', line 35

def certificate
  certificate_value = element_for_xpath("//Security/BinarySecurityToken").text.strip
  OpenSSL::X509::Certificate.new Base64.decode64(certificate_value)
end

#generate_digest(element) ⇒ Object



19
20
21
22
23
# File 'lib/akami/wsse/verify_signature.rb', line 19

def generate_digest(element)
  element = element_for_xpath(element) if element.is_a? String
  xml = canonicalize(element)
  digest(xml).strip
end

#signature_valueObject



30
31
32
33
# File 'lib/akami/wsse/verify_signature.rb', line 30

def signature_value
  element = element_for_xpath("//Security/Signature/SignatureValue")
  element ? element.text : ""
end

#supplied_digest(element) ⇒ Object



25
26
27
28
# File 'lib/akami/wsse/verify_signature.rb', line 25

def supplied_digest(element)
  element = element_for_xpath(element) if element.is_a? String
  find_digest_value element.attributes["Id"]
end

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/akami/wsse/verify_signature.rb', line 40

def valid?
  verify
rescue InvalidDigest, InvalidSignedValue
  return false
end

#verify!Object



46
47
48
49
50
# File 'lib/akami/wsse/verify_signature.rb', line 46

def verify!
  verify
rescue InvalidDigest, InvalidSignedValue => e
  raise InvalidSignature, e.message
end