1+ if RUBY_VERSION < '1.9'
2+ require 'uuid'
3+ else
4+ require 'securerandom'
5+ end
6+
17module OneLogin
28 module RubySaml
39
410 # SAML2 Auxiliary class
5- #
11+ #
612 class Utils
13+ @@uuid_generator = UUID . new if RUBY_VERSION < '1.9'
714
815 DSIG = "http://www.w3.org/2000/09/xmldsig#"
916 XENC = "http://www.w3.org/2001/04/xmlenc#"
@@ -30,7 +37,7 @@ def self.format_cert(cert)
3037 # @return [String] The formatted private key
3138 #
3239 def self . format_private_key ( key )
33- # don't try to format an encoded private key or if is empty
40+ # don't try to format an encoded private key or if is empty
3441 return key if key . nil? || key . empty? || key . match ( /\x0d / )
3542
3643 # is this an rsa key?
@@ -114,7 +121,7 @@ def self.decrypt_data(encrypted_node, private_key)
114121 { 'xenc' => XENC }
115122 )
116123 algorithm = encrypt_method . attributes [ 'Algorithm' ]
117- retrieve_plaintext ( node , symmetric_key , algorithm )
124+ retrieve_plaintext ( node , symmetric_key , algorithm )
118125 end
119126
120127 # Obtains the symmetric key from the EncryptedData element
@@ -140,7 +147,7 @@ def self.retrieve_symmetric_key(encrypt_data, private_key)
140147 { "ds" => DSIG , "xenc" => XENC }
141148 )
142149 algorithm = encrypt_method . attributes [ 'Algorithm' ]
143- retrieve_plaintext ( cipher_text , private_key , algorithm )
150+ retrieve_plaintext ( cipher_text , private_key , algorithm )
144151 end
145152
146153 # Obtains the deciphered text
@@ -158,7 +165,7 @@ def self.retrieve_plaintext(cipher_text, symmetric_key, algorithm)
158165 when 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' then oaep = symmetric_key
159166 end
160167
161- if cipher
168+ if cipher
162169 iv_len = cipher . iv_len
163170 data = cipher_text [ iv_len ..-1 ]
164171 cipher . padding , cipher . key , cipher . iv = 0 , symmetric_key , cipher_text [ 0 ..iv_len -1 ]
@@ -173,6 +180,9 @@ def self.retrieve_plaintext(cipher_text, symmetric_key, algorithm)
173180 end
174181 end
175182
183+ def self . uuid
184+ RUBY_VERSION < '1.9' ? "_#{ @@uuid_generator . generate } " : "_#{ SecureRandom . uuid } "
185+ end
176186 end
177187 end
178188end
0 commit comments