1
+ if RUBY_VERSION < '1.9'
2
+ require 'uuid'
3
+ else
4
+ require 'securerandom'
5
+ end
6
+
1
7
module OneLogin
2
8
module RubySaml
3
9
4
10
# SAML2 Auxiliary class
5
- #
11
+ #
6
12
class Utils
13
+ @@uuid_generator = UUID . new if RUBY_VERSION < '1.9'
7
14
8
15
DSIG = "http://www.w3.org/2000/09/xmldsig#"
9
16
XENC = "http://www.w3.org/2001/04/xmlenc#"
@@ -30,7 +37,7 @@ def self.format_cert(cert)
30
37
# @return [String] The formatted private key
31
38
#
32
39
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
34
41
return key if key . nil? || key . empty? || key . match ( /\x0d / )
35
42
36
43
# is this an rsa key?
@@ -114,7 +121,7 @@ def self.decrypt_data(encrypted_node, private_key)
114
121
{ 'xenc' => XENC }
115
122
)
116
123
algorithm = encrypt_method . attributes [ 'Algorithm' ]
117
- retrieve_plaintext ( node , symmetric_key , algorithm )
124
+ retrieve_plaintext ( node , symmetric_key , algorithm )
118
125
end
119
126
120
127
# Obtains the symmetric key from the EncryptedData element
@@ -140,7 +147,7 @@ def self.retrieve_symmetric_key(encrypt_data, private_key)
140
147
{ "ds" => DSIG , "xenc" => XENC }
141
148
)
142
149
algorithm = encrypt_method . attributes [ 'Algorithm' ]
143
- retrieve_plaintext ( cipher_text , private_key , algorithm )
150
+ retrieve_plaintext ( cipher_text , private_key , algorithm )
144
151
end
145
152
146
153
# Obtains the deciphered text
@@ -158,7 +165,7 @@ def self.retrieve_plaintext(cipher_text, symmetric_key, algorithm)
158
165
when 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' then oaep = symmetric_key
159
166
end
160
167
161
- if cipher
168
+ if cipher
162
169
iv_len = cipher . iv_len
163
170
data = cipher_text [ iv_len ..-1 ]
164
171
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)
173
180
end
174
181
end
175
182
183
+ def self . uuid
184
+ RUBY_VERSION < '1.9' ? "_#{ @@uuid_generator . generate } " : "_#{ SecureRandom . uuid } "
185
+ end
176
186
end
177
187
end
178
188
end
0 commit comments