Class: Akami::WSSE::Signature

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

Defined Under Namespace

Classes: MissingCertificate

Constant Summary collapse

ExclusiveXMLCanonicalizationAlgorithm =
'http://www.w3.org/2001/10/xml-exc-c14n#'.freeze
RSASHA1SignatureAlgorithm =
'http://www.w3.org/2000/09/xmldsig#rsa-sha1'.freeze
SHA1DigestAlgorithm =
'http://www.w3.org/2000/09/xmldsig#sha1'.freeze
X509v3ValueType =
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3'.freeze
Base64EncodingType =
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'.freeze
SignatureNamespace =
'http://www.w3.org/2000/09/xmldsig#'.freeze

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(certs = Certs.new) ⇒ Signature

Returns a new instance of Signature.



33
34
35
# File 'lib/akami/wsse/signature.rb', line 33

def initialize(certs = Certs.new)
  @certs = certs
end

Instance Attribute Details

#certsObject

For a Savon::WSSE::Certs object. To hold the certs we need to sign.



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

def certs
  @certs
end

Instance Method Details

#body_attributesObject



55
56
57
58
59
60
# File 'lib/akami/wsse/signature.rb', line 55

def body_attributes
  {
    "xmlns:wsu" => Akami::WSSE::WSU_NAMESPACE,
    "wsu:Id" => body_id,
  }
end

#body_idObject



47
48
49
# File 'lib/akami/wsse/signature.rb', line 47

def body_id
  @body_id ||= "Body-#{uid}".freeze
end

#documentObject

Without a document, the document cannot be signed. Generate the document once, and then set document and recall #to_token



16
17
18
# File 'lib/akami/wsse/signature.rb', line 16

def document
  @document ? @document.to_s : nil
end

#document=(document) ⇒ Object



20
21
22
# File 'lib/akami/wsse/signature.rb', line 20

def document=(document)
  @document = Nokogiri::XML(document)
end

#have_document?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/akami/wsse/signature.rb', line 37

def have_document?
  !!document
end

#nowObject

Cache “now” so that digests match… TODO: figure out how we might want to expire this cache…



43
44
45
# File 'lib/akami/wsse/signature.rb', line 43

def now
  @now ||= Time.now
end

#security_token_idObject



51
52
53
# File 'lib/akami/wsse/signature.rb', line 51

def security_token_id
  @security_token_id ||= "SecurityToken-#{uid}".freeze
end

#to_tokenObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/akami/wsse/signature.rb', line 62

def to_token
  return {} unless have_document?

  sig = signed_info.merge(key_info).merge(signature_value)
  sig.merge! :order! => []
  [ "SignedInfo", "SignatureValue", "KeyInfo" ].each do |key|
    sig[:order!] << key if sig[key]
  end

  token = {
    "Signature" => sig,
    :attributes! => { "Signature" => { "xmlns" => SignatureNamespace } },
  }

  token.deep_merge!(binary_security_token) if certs.cert

  token.merge! :order! => []
  [ "wsse:BinarySecurityToken", "Signature" ].each do |key|
    token[:order!] << key if token[key]
  end

  token
end