@@ -23,14 +23,14 @@ def document=(document)
2323 @document = Nokogiri ::XML ( document )
2424 end
2525
26- ExclusiveXMLCanonicalizationAlgorithm = ' http://www.w3.org/2001/10/xml-exc-c14n#' . freeze
27- RSASHA1SignatureAlgorithm = ' http://www.w3.org/2000/09/xmldsig#rsa-sha1' . freeze
28- SHA1DigestAlgorithm = ' http://www.w3.org/2000/09/xmldsig#sha1' . freeze
26+ ExclusiveXMLCanonicalizationAlgorithm = " http://www.w3.org/2001/10/xml-exc-c14n#" . freeze
27+ RSASHA1SignatureAlgorithm = " http://www.w3.org/2000/09/xmldsig#rsa-sha1" . freeze
28+ SHA1DigestAlgorithm = " http://www.w3.org/2000/09/xmldsig#sha1" . freeze
2929
30- X509v3ValueType = ' http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3' . freeze
31- Base64EncodingType = ' http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary' . freeze
30+ X509v3ValueType = " http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" . freeze
31+ Base64EncodingType = " http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" . freeze
3232
33- SignatureNamespace = ' http://www.w3.org/2000/09/xmldsig#' . freeze
33+ SignatureNamespace = " http://www.w3.org/2000/09/xmldsig#" . freeze
3434
3535 def initialize ( certs = Certs . new )
3636 @certs = certs
@@ -57,28 +57,28 @@ def security_token_id
5757 def body_attributes
5858 {
5959 "xmlns:wsu" => Akami ::WSSE ::WSU_NAMESPACE ,
60- "wsu:Id" => body_id ,
60+ "wsu:Id" => body_id
6161 }
6262 end
6363
6464 def to_token
6565 return { } unless have_document?
6666
6767 sig = signed_info . merge ( key_info ) . merge ( signature_value )
68- sig . merge! :order! => [ ]
69- [ "SignedInfo" , "SignatureValue" , "KeyInfo" ] . each do |key |
68+ sig [ :order! ] = [ ]
69+ [ "SignedInfo" , "SignatureValue" , "KeyInfo" ] . each do |key |
7070 sig [ :order! ] << key if sig [ key ]
7171 end
7272
7373 token = {
7474 "Signature" => sig ,
75- :attributes! => { "Signature" => { "xmlns" => SignatureNamespace } } ,
75+ :attributes! => { "Signature" => { "xmlns" => SignatureNamespace } }
7676 }
7777
7878 Akami ::HashHelper . deep_merge! ( token , binary_security_token ) if certs . cert
7979
80- token . merge! :order! => [ ]
81- [ "wsse:BinarySecurityToken" , "Signature" ] . each do |key |
80+ token [ :order! ] = [ ]
81+ [ "wsse:BinarySecurityToken" , "Signature" ] . each do |key |
8282 token [ :order! ] << key if token [ key ]
8383 end
8484
@@ -89,13 +89,13 @@ def to_token
8989
9090 def binary_security_token
9191 {
92- "wsse:BinarySecurityToken" => Base64 . encode64 ( certs . cert . to_der ) . gsub ( "\n " , '' ) ,
93- :attributes! => { "wsse:BinarySecurityToken" => {
92+ "wsse:BinarySecurityToken" => Base64 . encode64 ( certs . cert . to_der ) . delete ( "\n " ) ,
93+ :attributes! => { "wsse:BinarySecurityToken" => {
9494 "wsu:Id" => security_token_id ,
95- ' EncodingType' => Base64EncodingType ,
96- ' ValueType' => X509v3ValueType ,
97- "xmlns:wsu" => Akami ::WSSE ::WSU_NAMESPACE ,
98- } }
95+ " EncodingType" => Base64EncodingType ,
96+ " ValueType" => X509v3ValueType ,
97+ "xmlns:wsu" => Akami ::WSSE ::WSU_NAMESPACE
98+ } }
9999 }
100100 end
101101
@@ -104,18 +104,18 @@ def key_info
104104 "KeyInfo" => {
105105 "wsse:SecurityTokenReference" => {
106106 "wsse:Reference/" => nil ,
107- :attributes! => { "wsse:Reference/" => {
107+ :attributes! => { "wsse:Reference/" => {
108108 "ValueType" => X509v3ValueType ,
109- "URI" => "##{ security_token_id } " ,
110- } }
109+ "URI" => "##{ security_token_id } "
110+ } }
111111 } ,
112- :attributes! => { "wsse:SecurityTokenReference" => { "xmlns:wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" } } ,
113- } ,
112+ :attributes! => { "wsse:SecurityTokenReference" => { "xmlns:wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" } }
113+ }
114114 }
115115 end
116116
117117 def signature_value
118- { "SignatureValue" => the_signature }
118+ { "SignatureValue" => the_signature }
119119 rescue MissingCertificate
120120 { }
121121 end
@@ -126,25 +126,25 @@ def signed_info
126126 "CanonicalizationMethod/" => nil ,
127127 "SignatureMethod/" => nil ,
128128 "Reference" => [
129- #signed_info_transforms.merge(signed_info_digest_method).merge({ "DigestValue" => timestamp_digest }),
130- signed_info_transforms . merge ( signed_info_digest_method ) . merge ( { "DigestValue" => body_digest } ) ,
129+ # signed_info_transforms.merge(signed_info_digest_method).merge({ "DigestValue" => timestamp_digest }),
130+ signed_info_transforms . merge ( signed_info_digest_method ) . merge ( { "DigestValue" => body_digest } )
131131 ] ,
132132 :attributes! => {
133- "CanonicalizationMethod/" => { "Algorithm" => ExclusiveXMLCanonicalizationAlgorithm } ,
134- "SignatureMethod/" => { "Algorithm" => RSASHA1SignatureAlgorithm } ,
135- "Reference" => { "URI" => [ "##{ body_id } " ] } ,
133+ "CanonicalizationMethod/" => { "Algorithm" => ExclusiveXMLCanonicalizationAlgorithm } ,
134+ "SignatureMethod/" => { "Algorithm" => RSASHA1SignatureAlgorithm } ,
135+ "Reference" => { "URI" => [ "##{ body_id } " ] }
136136 } ,
137- :order! => [ "CanonicalizationMethod/" , "SignatureMethod/" , "Reference" ] ,
138- } ,
137+ :order! => [ "CanonicalizationMethod/" , "SignatureMethod/" , "Reference" ]
138+ }
139139 }
140140 end
141141
142142 def the_signature
143143 raise MissingCertificate , "Expected a private_key for signing" unless certs . private_key
144144 signed_info = at_xpath ( @document , "//Envelope/Header/Security/Signature/SignedInfo" )
145145 signed_info = signed_info ? canonicalize ( signed_info ) : ""
146- signature = certs . private_key . sign ( OpenSSL ::Digest :: SHA1 . new , signed_info )
147- Base64 . encode64 ( signature ) . gsub ( "\n " , '' ) # TODO: DRY calls to Base64.encode64(...).gsub("\n", '')
146+ signature = certs . private_key . sign ( OpenSSL ::Digest . new ( "SHA1" ) , signed_info )
147+ Base64 . encode64 ( signature ) . delete ( "\n " ) # TODO: DRY calls to Base64.encode64(...).gsub("\n", '')
148148 end
149149
150150 def body_digest
@@ -153,15 +153,15 @@ def body_digest
153153 end
154154
155155 def signed_info_digest_method
156- { "DigestMethod/" => nil , :attributes! => { "DigestMethod/" => { "Algorithm" => SHA1DigestAlgorithm } } }
156+ { "DigestMethod/" => nil , :attributes! => { "DigestMethod/" => { "Algorithm" => SHA1DigestAlgorithm } } }
157157 end
158158
159159 def signed_info_transforms
160- { "Transforms" => { "Transform/" => nil , :attributes! => { "Transform/" => { "Algorithm" => ExclusiveXMLCanonicalizationAlgorithm } } } }
160+ { "Transforms" => { "Transform/" => nil , :attributes! => { "Transform/" => { "Algorithm" => ExclusiveXMLCanonicalizationAlgorithm } } } }
161161 end
162162
163163 def uid
164- OpenSSL ::Digest ::SHA1 . hexdigest ( [ Time . now , rand ] . collect ( & :to_s ) . join ( '/' ) )
164+ OpenSSL ::Digest ::SHA1 . hexdigest ( [ Time . now , rand ] . join ( "/" ) )
165165 end
166166 end
167167 end
0 commit comments