Class: Akami::WSSE::Signature
- Inherits:
-
Object
- Object
- Akami::WSSE::Signature
- 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
-
#certs ⇒ Object
For a
Savon::WSSE::Certsobject. -
#created_at ⇒ Object
Wheater to sign the timestamp or not ant their time.
-
#expires_at ⇒ Object
Wheater to sign the timestamp or not ant their time.
-
#timestamp ⇒ Object
Wheater to sign the timestamp or not ant their time.
Instance Method Summary collapse
- #body_attributes ⇒ Object
- #body_id ⇒ Object
-
#document ⇒ Object
Without a document, the document cannot be signed.
- #document=(document) ⇒ Object
- #have_document? ⇒ Boolean
-
#initialize(certs = Certs.new, options = {}) ⇒ Signature
constructor
A new instance of Signature.
-
#now ⇒ Object
Cache "now" so that digests match...
- #security_token_id ⇒ Object
- #timestamp_attributes ⇒ Object
- #timestamp_id ⇒ Object
- #to_token ⇒ Object
- #wsu_timestamp_hash ⇒ Object
Methods included from C14nHelper
Methods included from XPathHelper
#at_xpath, #local_name_xpath, #xpath
Constructor Details
#initialize(certs = Certs.new, options = {}) ⇒ Signature
Returns a new instance of Signature.
38 39 40 41 42 43 |
# File 'lib/akami/wsse/signature.rb', line 38 def initialize(certs = Certs.new, = {}) @certs = certs @timestamp = [:timestamp] || false @created_at = [:created_at] @expires_at = [:expires_at] end |
Instance Attribute Details
#certs ⇒ Object
For a Savon::WSSE::Certs object. To hold the certs we need to sign.
13 14 15 |
# File 'lib/akami/wsse/signature.rb', line 13 def certs @certs end |
#created_at ⇒ Object
Wheater to sign the timestamp or not ant their time
16 17 18 |
# File 'lib/akami/wsse/signature.rb', line 16 def created_at @created_at end |
#expires_at ⇒ Object
Wheater to sign the timestamp or not ant their time
16 17 18 |
# File 'lib/akami/wsse/signature.rb', line 16 def expires_at @expires_at end |
#timestamp ⇒ Object
Wheater to sign the timestamp or not ant their time
16 17 18 |
# File 'lib/akami/wsse/signature.rb', line 16 def @timestamp end |
Instance Method Details
#body_attributes ⇒ Object
83 84 85 86 87 88 |
# File 'lib/akami/wsse/signature.rb', line 83 def body_attributes { "xmlns:wsu" => Akami::WSSE::WSU_NAMESPACE, "wsu:Id" => body_id } end |
#body_id ⇒ Object
55 56 57 |
# File 'lib/akami/wsse/signature.rb', line 55 def body_id @body_id ||= "Body-#{uid}".freeze end |
#document ⇒ Object
Without a document, the document cannot be signed. Generate the document once, and then set document and recall #to_token
20 21 22 23 |
# File 'lib/akami/wsse/signature.rb', line 20 def document return nil if @document.nil? @document.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML) end |
#document=(document) ⇒ Object
25 26 27 |
# File 'lib/akami/wsse/signature.rb', line 25 def document=(document) @document = Nokogiri::XML(document) end |
#have_document? ⇒ Boolean
45 46 47 |
# File 'lib/akami/wsse/signature.rb', line 45 def have_document? !!document end |
#now ⇒ Object
Cache "now" so that digests match... TODO: figure out how we might want to expire this cache...
51 52 53 |
# File 'lib/akami/wsse/signature.rb', line 51 def now @now ||= Time.now end |
#security_token_id ⇒ Object
79 80 81 |
# File 'lib/akami/wsse/signature.rb', line 79 def security_token_id @security_token_id ||= "SecurityToken-#{uid}".freeze end |
#timestamp_attributes ⇒ Object
90 91 92 93 94 95 |
# File 'lib/akami/wsse/signature.rb', line 90 def { "xmlns:wsu" => Akami::WSSE::WSU_NAMESPACE, "wsu:Id" => } end |
#timestamp_id ⇒ Object
59 60 61 |
# File 'lib/akami/wsse/signature.rb', line 59 def @timestamp_id ||= "TS-#{uid}".freeze end |
#to_token ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/akami/wsse/signature.rb', line 97 def to_token return {} unless have_document? sig = signed_info.merge(key_info).merge(signature_value) sig[:order!] = [] ["SignedInfo", "SignatureValue", "KeyInfo"].each do |key| sig[:order!] << key if sig[key] end token = { "Signature" => sig, :attributes! => {"Signature" => {"xmlns" => SignatureNamespace}} } Akami::HashHelper.deep_merge!(token, binary_security_token) if certs.cert token[:order!] = [] ["wsse:BinarySecurityToken", "Signature"].each do |key| token[:order!] << key if token[key] end token end |
#wsu_timestamp_hash ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/akami/wsse/signature.rb', line 63 def return {} unless { "wsu:Timestamp" => { "wsu:Created" => (@created_at ||= Time.now).utc.xmlschema, "wsu:Expires" => (@expires_at ||= created_at + 60).utc.xmlschema }, :attributes! => { "wsu:Timestamp" => { "wsu:Id" => , "xmlns:wsu" => WSU_NAMESPACE } } } end |