jruby-openssl 0.9.7-java → 0.9.8-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +68 -23
- data/Rakefile +12 -1
- data/lib/jopenssl.jar +0 -0
- data/lib/jopenssl/load.rb +22 -17
- data/lib/jopenssl/version.rb +1 -1
- data/lib/jopenssl18/openssl/ssl-internal.rb +1 -44
- data/lib/jopenssl19/openssl/config.rb +164 -5
- data/lib/jopenssl19/openssl/ssl-internal.rb +15 -51
- data/lib/jopenssl21/openssl/bn.rb +0 -1
- data/lib/jopenssl21/openssl/buffering.rb +1 -449
- data/lib/jopenssl21/openssl/cipher.rb +1 -28
- data/lib/jopenssl21/openssl/config.rb +1 -313
- data/lib/jopenssl21/openssl/digest.rb +1 -49
- data/lib/jopenssl21/openssl/ssl.rb +1 -205
- data/lib/jopenssl22/openssl.rb +22 -0
- data/lib/jopenssl22/openssl/bn.rb +39 -0
- data/lib/jopenssl22/openssl/buffering.rb +456 -0
- data/lib/jopenssl22/openssl/cipher.rb +28 -0
- data/lib/jopenssl22/openssl/config.rb +313 -0
- data/lib/jopenssl22/openssl/digest.rb +54 -0
- data/lib/jopenssl22/openssl/ssl.rb +193 -0
- data/lib/jopenssl22/openssl/x509.rb +139 -0
- data/lib/openssl/bn.rb +8 -6
- data/lib/openssl/buffering.rb +8 -6
- data/lib/openssl/cipher.rb +8 -6
- data/lib/openssl/config.rb +8 -6
- data/lib/openssl/digest.rb +8 -6
- data/lib/openssl/pkcs12.rb +3 -3
- data/lib/openssl/pkcs7.rb +6 -4
- data/lib/openssl/ssl-internal.rb +7 -5
- data/lib/openssl/ssl.rb +8 -6
- data/lib/openssl/x509-internal.rb +7 -5
- data/lib/openssl/x509.rb +8 -6
- metadata +23 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49741f0e23b3ad70304a6bdb63c2d23dde49f33a
|
4
|
+
data.tar.gz: 2036499982fa3531223893a4f9bf00ac01e6b2ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b8479f66c2858c0355dccaac0186c0ce881a51e5742de90d31659883b15e091d58caed87ddb937a1e3de6be8dfd53768eb39032c943fa1bc57fcf92c1089b78
|
7
|
+
data.tar.gz: e65b8995e632f4965f133f9f0f95bb73996116154cfda8342ac3e07d6073306e01494a1c93b404b61201595bbe1cd951b43ae844a06f3c03ed7fe4bfa7630792
|
data/History.md
CHANGED
@@ -1,7 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
## 0.9.8
|
2
|
+
|
3
|
+
* refactor `PKCS5.pbkdf2_hmac_sha1` to use BC APIs
|
4
|
+
thus less dependent on provider internals (jruby/jruby#3025)
|
5
|
+
* HMAC - use our SimpleKey impl so that there's less[] copy
|
6
|
+
... also allows for an empty key to work like MRI (jruby/jruby#2854)
|
7
|
+
* fixing oaep encryption to use correct algorithm (#54)
|
8
|
+
* [experimental] support NOT loading any (BC) jars on our own ... (#10)
|
9
|
+
* disable DHE (by default) on Java <= 7 ... on Java 8 we (still) force 1024/2048
|
10
|
+
(see jruby/jruby#2872 and #45)
|
11
|
+
* handle parsing of "incomplete" X.509 certificates like MRI does (#42)
|
12
|
+
* implement a CRL/certificate caching (for now off by default) in Lookup
|
13
|
+
... set *-J-Djruby.openssl.x509.lookup.cache=true* to enable
|
14
|
+
* improve Store helper concurrency (with less synchronization)
|
15
|
+
* reviewed OpenSSL's .rb parts to match those present in MRI 1.9.3 / 2.2.2
|
16
|
+
* initial support for `OpenSSL::SSL::Session` (id, time, timeout work)
|
17
|
+
* session_cache_mode as present in OpenSSL makes no sense with Java APIs
|
18
|
+
* use the set SSLContext#session_cache_size on the underlying javax.net API
|
19
|
+
* tidy up SSLSocket's internals + add stack-trace debugging on accept/connect
|
20
|
+
* add SSLSocket ssl_version property like MRI has (#38)
|
21
|
+
* avoid unnecessary `_initialize` naming - it's confusing to see in JVM tools
|
22
|
+
* use SecurityHelper to get a X.509 certificate factory
|
23
|
+
we'll know prefer BC's X.509 factory over the built-in (Sun provider) one
|
24
|
+
|
25
|
+
## 0.9.7
|
26
|
+
|
27
|
+
* put in some more ossl to jsse mappings for SSL/TLS
|
28
|
+
(SSL_DHE_xxx, TLS_ECDH_xxx, TLS_ECDHE_xxx)
|
29
|
+
* exclude SSLv2 in reported METHODS (all fine to close jruby/jruby#1874)
|
30
|
+
* support passing ssl_version as an argument to initialize SSLContext.new ...
|
31
|
+
* now that we've matched w MRI's SSLContext::METHODS don't report custom ones
|
32
|
+
* more ssl_version= compatibility fixes that match MRI (jruby/jruby#1736)
|
33
|
+
* support setting ssl_version = "TLSv1_1" (or "TLSv1_2") just like MRI
|
34
|
+
* [regression] make sure version is set when reading encoded certificate
|
35
|
+
+ signature algorithm should be read as well when decoding certificate (#39)
|
36
|
+
* better accept handshake errors instead of "General SSLEngine problem (#37)
|
37
|
+
* trying to decode DER application specific objects (based on patch from #36)
|
38
|
+
* we've not been compatible with MRI's DES (EDE) - partly due DES(3) ECB
|
39
|
+
fixing jruby/jruby#2617 as well as jruby/jruby#931
|
40
|
+
* exclude reporting algorithms with CFB-1 cipher mode as supported (due #35)
|
41
|
+
* do not change CFB1 to CFB ... it's something different (although broken on BC)
|
42
|
+
* attempt to deal with update/final buffering incompatibility with MRI
|
43
|
+
* fix HMAC digest incorrect when data contains invalid characters (#33)
|
44
|
+
* add Gemfile and specify ruby-maven as dependency
|
45
|
+
* use SafePropertyAccessor to access properties instead of directly (#28)
|
46
|
+
* make sure SSLSocket's cipher and hostname are nil by default (avoids NPE)
|
47
|
+
* update to (packed) BC version 1.50 + start declaring 1.51 as semi-supported
|
48
|
+
|
49
|
+
## 0.9.6
|
5
50
|
|
6
51
|
* ClassCastException still happen deep within BC - turn them into SignatureExeption
|
7
52
|
* make sure empty object can be serialize via to_pem
|
@@ -53,7 +98,7 @@
|
|
53
98
|
* avoid using JRuby IO APIs (will likely not work in 9k)
|
54
99
|
* make 'jopenssl/load' also work on jruby-1.6.8 mode 1.9
|
55
100
|
|
56
|
-
|
101
|
+
## 0.9.5
|
57
102
|
|
58
103
|
MASSIVE internal "rewrite" to avoid depending on a registered (BC) security
|
59
104
|
provider. This releases restores compatibility with BC version 1.47 while being
|
@@ -70,11 +115,11 @@ compatible with newer bouncy-castle jars as well (1.48, 1.49 and 1.50).
|
|
70
115
|
* fix bug https://github.com/jruby/jruby/issues/1156
|
71
116
|
* openssl: add handling for base 0 to new and to_s
|
72
117
|
|
73
|
-
|
118
|
+
## 0.9.4
|
74
119
|
|
75
120
|
* Fix compatibility wiht Bouncy Castle 1.49.
|
76
121
|
|
77
|
-
|
122
|
+
## 0.9.3
|
78
123
|
|
79
124
|
* Allow options passed to nonblock methods (not impl'ed yet)
|
80
125
|
* Make ClassIndex into an enum, to prevent issues like jruby/jruby#1004
|
@@ -83,7 +128,7 @@ compatible with newer bouncy-castle jars as well (1.48, 1.49 and 1.50).
|
|
83
128
|
== ...
|
84
129
|
|
85
130
|
|
86
|
-
|
131
|
+
## 0.7.7
|
87
132
|
|
88
133
|
This release includes bug fixes.
|
89
134
|
|
@@ -93,14 +138,14 @@ This release includes bug fixes.
|
|
93
138
|
* JRUBY-6515: sending UTF-8 data over SSL can hang with openssl
|
94
139
|
* Update tests to sync with CRuby ruby_1_9_3
|
95
140
|
|
96
|
-
|
141
|
+
## 0.7.6
|
97
142
|
|
98
143
|
This release includes initial implementation of PKCS12 by Owen Ou.
|
99
144
|
|
100
145
|
* JRUBY-5066: Implement OpenSSL::PKCS12 (only for simple case)
|
101
146
|
* JRUBY-6385: Assertion failure with -J-ea
|
102
147
|
|
103
|
-
|
148
|
+
## 0.7.5
|
104
149
|
|
105
150
|
This release improved 1.9 mode support with help of
|
106
151
|
Duncan Mak <duncan@earthaid.net>. Now jruby-ossl gem includes both 1.8 and 1.9
|
@@ -114,14 +159,14 @@ libraries and part of features should work fine on 1.9 mode, too.
|
|
114
159
|
* JRUBY-5362: Improved 1.9 support
|
115
160
|
* JRUBY-4992: Warn if loaded by non JRuby interpreter
|
116
161
|
|
117
|
-
|
162
|
+
## 0.7.4
|
118
163
|
|
119
164
|
* JRUBY-5519: Avoid String encoding dependency in DER loading. PEM loading
|
120
165
|
failed on JRuby 1.6.x. Fixed.
|
121
166
|
* JRUBY-5510: Add debug information to released jar
|
122
167
|
* JRUBY-5478: Update bouncycastle jars to the latest version. (1.46)
|
123
168
|
|
124
|
-
|
169
|
+
## 0.7.3
|
125
170
|
|
126
171
|
* JRUBY-5200: Net::IMAP + SSL(imaps) login could hang. Fixed.
|
127
172
|
* JRUBY-5253: Allow to load the certificate file which includes private
|
@@ -131,7 +176,7 @@ libraries and part of features should work fine on 1.9 mode, too.
|
|
131
176
|
* JRUBY-5316: Improvements for J9's IBMJCE support. Now all testcases
|
132
177
|
pass on J9 JDK 6.
|
133
178
|
|
134
|
-
|
179
|
+
## 0.7.2
|
135
180
|
|
136
181
|
* JRUBY-5126: Ignore Cipher#reset and Cipher#iv= when it's a stream
|
137
182
|
cipher (Net::SSH compatibility)
|
@@ -147,7 +192,7 @@ libraries and part of features should work fine on 1.9 mode, too.
|
|
147
192
|
* JRUBY-5018: SSLSocket holds selectors, keys, preventing quick
|
148
193
|
cleanup of resources when dereferenced
|
149
194
|
|
150
|
-
|
195
|
+
## 0.7.1
|
151
196
|
|
152
197
|
NOTE: Now BouncyCastle jars has moved out to its own gem "bouncy-castle-java"
|
153
198
|
http://rubygems.org/gems/bouncy-castle-java. You don't need to care about it
|
@@ -161,7 +206,7 @@ because "jruby-openssl" gem depends on it from now on.
|
|
161
206
|
(JRuby-OpenSSL fake)" -> "jruby-ossl 0.7.1"
|
162
207
|
* JRUBY-4975: Moving BouncyCastle jars out to its own gem.
|
163
208
|
|
164
|
-
|
209
|
+
## 0.7
|
165
210
|
|
166
211
|
* Follow MRI 1.8.7 openssl API changes
|
167
212
|
* Fixes so that jruby-openssl can run on appengine
|
@@ -217,7 +262,7 @@ because "jruby-openssl" gem depends on it from now on.
|
|
217
262
|
- JRUBY-4574: jruby-openssl deprecation warning cleanup
|
218
263
|
- JRUBY-4591: jruby-1.4 support
|
219
264
|
|
220
|
-
|
265
|
+
## 0.6
|
221
266
|
|
222
267
|
* This is a recommended upgrade to jruby-openssl. A security problem
|
223
268
|
involving peer certificate verification was found where failed
|
@@ -244,7 +289,7 @@ because "jruby-openssl" gem depends on it from now on.
|
|
244
289
|
* Public keys are lazily instantiated when the
|
245
290
|
X509::Certificate#public_key method is called (Dave Garcia)
|
246
291
|
|
247
|
-
|
292
|
+
## 0.5.2
|
248
293
|
|
249
294
|
Multiple bugs fixed:
|
250
295
|
|
@@ -254,13 +299,13 @@ Multiple bugs fixed:
|
|
254
299
|
* JRUBY-3767 OpenSSL ssl implementation doesn't support client auth
|
255
300
|
* JRUBY-3673 jRuby-OpenSSL does not properly load certificate authority file
|
256
301
|
|
257
|
-
|
302
|
+
## 0.5.1
|
258
303
|
|
259
304
|
* Multiple fixes by Brice Figureau to get net/ssh working. Requires JRuby 1.3.1
|
260
305
|
to be 100%
|
261
306
|
* Fix by Frederic Jean for a character-decoding issue for some certificates
|
262
307
|
|
263
|
-
|
308
|
+
## 0.5
|
264
309
|
|
265
310
|
* Fixed JRUBY-3614: Unsupported HMAC algorithm (HMACSHA-256)
|
266
311
|
* Fixed JRUBY-3570: ActiveMerchant's AuthorizeNet Gateway throws OpenSSL Cert
|
@@ -271,7 +316,7 @@ Multiple bugs fixed:
|
|
271
316
|
digest
|
272
317
|
* Misc code cleanup
|
273
318
|
|
274
|
-
|
319
|
+
## 0.2
|
275
320
|
|
276
321
|
* Enable remaining tests; fix a nil string issue in SSLSocket.sysread
|
277
322
|
(JRUBY-1888)
|
@@ -281,11 +326,11 @@ Multiple bugs fixed:
|
|
281
326
|
* Fix cipher initialization (JRUBY-1100)
|
282
327
|
* Now, only compatible with JRuby 1.1
|
283
328
|
|
284
|
-
|
329
|
+
## 0.1.1
|
285
330
|
|
286
331
|
* Fixed blocker issue preventing HTTPS/SSL from working (JRUBY-1222)
|
287
332
|
|
288
|
-
|
333
|
+
## 0.1
|
289
334
|
|
290
335
|
* PLEASE NOTE: This release is not compatible with JRuby releases earlier than
|
291
336
|
1.0.3 or 1.1b2. If you must use JRuby 1.0.2 or earlier, please install the
|
@@ -294,6 +339,6 @@ Multiple bugs fixed:
|
|
294
339
|
* Simultaneous support for JRuby trunk and 1.0 branch
|
295
340
|
* Start of support for OpenSSL::BN
|
296
341
|
|
297
|
-
|
342
|
+
## 0.0.5 and prior
|
298
343
|
|
299
344
|
* Initial versions with maintenance updates
|
data/Rakefile
CHANGED
@@ -17,4 +17,15 @@ namespace :jar do
|
|
17
17
|
task :all => :maven do
|
18
18
|
maven.package '-Dmaven.test.skip'
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
21
|
+
|
22
|
+
file('lib/jopenssl.jar') { Rake::Task['jar'].invoke }
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
Rake::TestTask.new do |task|
|
26
|
+
task.libs << 'lib'
|
27
|
+
task.test_files = FileList['src/test/ruby/**/test*.rb']
|
28
|
+
task.verbose = true
|
29
|
+
task.loader = :direct
|
30
|
+
end
|
31
|
+
task :test => 'lib/jopenssl.jar'
|
data/lib/jopenssl.jar
CHANGED
Binary file
|
data/lib/jopenssl/load.rb
CHANGED
@@ -3,30 +3,35 @@ warn 'Loading jruby-openssl in a non-JRuby interpreter' unless defined? JRUBY_VE
|
|
3
3
|
require 'java'
|
4
4
|
require 'jopenssl/version'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
# NOTE: assuming user does pull in BC .jars from somewhere else on the CP
|
7
|
+
unless ENV_JAVA['jruby.openssl.load.jars'].eql?('false')
|
8
|
+
version = Jopenssl::Version::BOUNCY_CASTLE_VERSION
|
9
|
+
bc_jars = nil
|
10
|
+
begin
|
11
|
+
# if we have jar-dependencies we let it track the jars
|
12
|
+
require_jar( 'org.bouncycastle', 'bcpkix-jdk15on', version )
|
13
|
+
require_jar( 'org.bouncycastle', 'bcprov-jdk15on', version )
|
14
|
+
bc_jars = true
|
15
|
+
rescue LoadError
|
16
|
+
end if defined?(Jars) && ( ! Jars.skip? ) rescue nil
|
17
|
+
unless bc_jars
|
18
|
+
load "org/bouncycastle/bcpkix-jdk15on/#{version}/bcpkix-jdk15on-#{version}.jar"
|
19
|
+
load "org/bouncycastle/bcprov-jdk15on/#{version}/bcprov-jdk15on-#{version}.jar"
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
require 'jruby'
|
21
24
|
require 'jopenssl.jar'
|
22
25
|
org.jruby.ext.openssl.OpenSSL.load(JRuby.runtime)
|
23
26
|
|
24
|
-
if RUBY_VERSION
|
25
|
-
load
|
26
|
-
elsif RUBY_VERSION
|
27
|
-
load
|
27
|
+
if RUBY_VERSION > '2.2'
|
28
|
+
load 'jopenssl22/openssl.rb'
|
29
|
+
elsif RUBY_VERSION > '2.1'
|
30
|
+
load 'jopenssl21/openssl.rb'
|
31
|
+
elsif RUBY_VERSION > '1.9'
|
32
|
+
load 'jopenssl19/openssl.rb'
|
28
33
|
else
|
29
|
-
load
|
34
|
+
load 'jopenssl18/openssl.rb'
|
30
35
|
end
|
31
36
|
|
32
37
|
require 'openssl/pkcs12'
|
data/lib/jopenssl/version.rb
CHANGED
@@ -15,48 +15,10 @@
|
|
15
15
|
=end
|
16
16
|
|
17
17
|
require "openssl/buffering"
|
18
|
-
require
|
18
|
+
require 'fcntl' # used by OpenSSL::SSL::Nonblock (if loaded)
|
19
19
|
|
20
20
|
module OpenSSL
|
21
21
|
module SSL
|
22
|
-
module SocketForwarder
|
23
|
-
def addr
|
24
|
-
to_io.addr
|
25
|
-
end
|
26
|
-
|
27
|
-
def peeraddr
|
28
|
-
to_io.peeraddr
|
29
|
-
end
|
30
|
-
|
31
|
-
def setsockopt(level, optname, optval)
|
32
|
-
to_io.setsockopt(level, optname, optval)
|
33
|
-
end
|
34
|
-
|
35
|
-
def getsockopt(level, optname)
|
36
|
-
to_io.getsockopt(level, optname)
|
37
|
-
end
|
38
|
-
|
39
|
-
def fcntl(*args)
|
40
|
-
to_io.fcntl(*args)
|
41
|
-
end
|
42
|
-
|
43
|
-
def closed?
|
44
|
-
to_io.closed?
|
45
|
-
end
|
46
|
-
|
47
|
-
def do_not_reverse_lookup=(flag)
|
48
|
-
to_io.do_not_reverse_lookup = flag
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module Nonblock
|
53
|
-
def initialize(*args)
|
54
|
-
flag = File::NONBLOCK
|
55
|
-
flag |= @io.fcntl(Fcntl::F_GETFL) if defined?(Fcntl::F_GETFL)
|
56
|
-
@io.fcntl(Fcntl::F_SETFL, flag)
|
57
|
-
super
|
58
|
-
end
|
59
|
-
end
|
60
22
|
|
61
23
|
def verify_certificate_identity(cert, hostname)
|
62
24
|
should_verify_common_name = true
|
@@ -101,11 +63,6 @@ module OpenSSL
|
|
101
63
|
return true
|
102
64
|
end
|
103
65
|
|
104
|
-
def session
|
105
|
-
SSL::Session.new(self)
|
106
|
-
rescue SSL::Session::SessionError
|
107
|
-
nil
|
108
|
-
end
|
109
66
|
end
|
110
67
|
|
111
68
|
class SSLServer
|
@@ -13,20 +13,41 @@
|
|
13
13
|
require 'stringio'
|
14
14
|
|
15
15
|
module OpenSSL
|
16
|
+
##
|
17
|
+
# = OpenSSL::Config
|
18
|
+
#
|
19
|
+
# Configuration for the openssl library.
|
20
|
+
#
|
21
|
+
# Many system's installation of openssl library will depend on your system
|
22
|
+
# configuration. See the value of OpenSSL::Config::DEFAULT_CONFIG_FILE for
|
23
|
+
# the location of the file for your host.
|
24
|
+
#
|
25
|
+
# See also http://www.openssl.org/docs/apps/config.html
|
16
26
|
class Config
|
17
27
|
include Enumerable
|
18
28
|
|
19
29
|
class << self
|
20
|
-
|
30
|
+
|
31
|
+
##
|
32
|
+
# Parses a given +string+ as a blob that contains configuration for openssl.
|
33
|
+
#
|
34
|
+
# If the source of the IO is a file, then consider using #parse_config.
|
35
|
+
def parse(string)
|
21
36
|
c = new()
|
22
|
-
parse_config(StringIO.new(
|
37
|
+
parse_config(StringIO.new(string)).each do |section, hash|
|
23
38
|
c[section] = hash
|
24
39
|
end
|
25
40
|
c
|
26
41
|
end
|
27
42
|
|
43
|
+
##
|
44
|
+
# load is an alias to ::new
|
28
45
|
alias load new
|
29
46
|
|
47
|
+
##
|
48
|
+
# Parses the configuration data read from +io+, see also #parse.
|
49
|
+
#
|
50
|
+
# Raises a ConfigError on invalid configuration data.
|
30
51
|
def parse_config(io)
|
31
52
|
begin
|
32
53
|
parse_config_lines(io)
|
@@ -209,6 +230,18 @@ module OpenSSL
|
|
209
230
|
end
|
210
231
|
end
|
211
232
|
|
233
|
+
##
|
234
|
+
# Creates an instance of OpenSSL's configuration class.
|
235
|
+
#
|
236
|
+
# This can be used in contexts like OpenSSL::X509::ExtensionFactory.config=
|
237
|
+
#
|
238
|
+
# If the optional +filename+ parameter is provided, then it is read in and
|
239
|
+
# parsed via #parse_config.
|
240
|
+
#
|
241
|
+
# This can raise IO exceptions based on the access, or availability of the
|
242
|
+
# file. A ConfigError exception may be raised depending on the validity of
|
243
|
+
# the data being configured.
|
244
|
+
#
|
212
245
|
def initialize(filename = nil)
|
213
246
|
@data = {}
|
214
247
|
if filename
|
@@ -220,6 +253,23 @@ module OpenSSL
|
|
220
253
|
end
|
221
254
|
end
|
222
255
|
|
256
|
+
##
|
257
|
+
# Gets the value of +key+ from the given +section+
|
258
|
+
#
|
259
|
+
# Given the following configurating file being loaded:
|
260
|
+
#
|
261
|
+
# config = OpenSSL::Config.load('foo.cnf')
|
262
|
+
# #=> #<OpenSSL::Config sections=["default"]>
|
263
|
+
# puts config.to_s
|
264
|
+
# #=> [ default ]
|
265
|
+
# # foo=bar
|
266
|
+
#
|
267
|
+
# You can get a specific value from the config if you know the +section+
|
268
|
+
# and +key+ like so:
|
269
|
+
#
|
270
|
+
# config.get_value('default','foo')
|
271
|
+
# #=> "bar"
|
272
|
+
#
|
223
273
|
def get_value(section, key)
|
224
274
|
if section.nil?
|
225
275
|
raise TypeError.new('nil not allowed')
|
@@ -228,7 +278,12 @@ module OpenSSL
|
|
228
278
|
get_key_string(section, key)
|
229
279
|
end
|
230
280
|
|
231
|
-
|
281
|
+
##
|
282
|
+
#
|
283
|
+
# *Deprecated*
|
284
|
+
#
|
285
|
+
# Use #get_value instead
|
286
|
+
def value(arg1, arg2 = nil) # :nodoc:
|
232
287
|
warn('Config#value is deprecated; use Config#get_value')
|
233
288
|
if arg2.nil?
|
234
289
|
section, key = 'default', arg1
|
@@ -240,20 +295,84 @@ module OpenSSL
|
|
240
295
|
get_key_string(section, key)
|
241
296
|
end
|
242
297
|
|
298
|
+
##
|
299
|
+
# Set the target +key+ with a given +value+ under a specific +section+.
|
300
|
+
#
|
301
|
+
# Given the following configurating file being loaded:
|
302
|
+
#
|
303
|
+
# config = OpenSSL::Config.load('foo.cnf')
|
304
|
+
# #=> #<OpenSSL::Config sections=["default"]>
|
305
|
+
# puts config.to_s
|
306
|
+
# #=> [ default ]
|
307
|
+
# # foo=bar
|
308
|
+
#
|
309
|
+
# You can set the value of +foo+ under the +default+ section to a new
|
310
|
+
# value:
|
311
|
+
#
|
312
|
+
# config.add_value('default', 'foo', 'buzz')
|
313
|
+
# #=> "buzz"
|
314
|
+
# puts config.to_s
|
315
|
+
# #=> [ default ]
|
316
|
+
# # foo=buzz
|
317
|
+
#
|
243
318
|
def add_value(section, key, value)
|
244
319
|
check_modify
|
245
320
|
(@data[section] ||= {})[key] = value
|
246
321
|
end
|
247
322
|
|
323
|
+
##
|
324
|
+
# Get a specific +section+ from the current configuration
|
325
|
+
#
|
326
|
+
# Given the following configurating file being loaded:
|
327
|
+
#
|
328
|
+
# config = OpenSSL::Config.load('foo.cnf')
|
329
|
+
# #=> #<OpenSSL::Config sections=["default"]>
|
330
|
+
# puts config.to_s
|
331
|
+
# #=> [ default ]
|
332
|
+
# # foo=bar
|
333
|
+
#
|
334
|
+
# You can get a hash of the specific section like so:
|
335
|
+
#
|
336
|
+
# config['default']
|
337
|
+
# #=> {"foo"=>"bar"}
|
338
|
+
#
|
248
339
|
def [](section)
|
249
340
|
@data[section] || {}
|
250
341
|
end
|
251
342
|
|
252
|
-
|
343
|
+
##
|
344
|
+
# Deprecated
|
345
|
+
#
|
346
|
+
# Use #[] instead
|
347
|
+
def section(name) # :nodoc:
|
253
348
|
warn('Config#section is deprecated; use Config#[]')
|
254
349
|
@data[name] || {}
|
255
350
|
end
|
256
351
|
|
352
|
+
##
|
353
|
+
# Sets a specific +section+ name with a Hash +pairs+
|
354
|
+
#
|
355
|
+
# Given the following configuration being created:
|
356
|
+
#
|
357
|
+
# config = OpenSSL::Config.new
|
358
|
+
# #=> #<OpenSSL::Config sections=[]>
|
359
|
+
# config['default'] = {"foo"=>"bar","baz"=>"buz"}
|
360
|
+
# #=> {"foo"=>"bar", "baz"=>"buz"}
|
361
|
+
# puts config.to_s
|
362
|
+
# #=> [ default ]
|
363
|
+
# # foo=bar
|
364
|
+
# # baz=buz
|
365
|
+
#
|
366
|
+
# It's important to note that this will essentially merge any of the keys
|
367
|
+
# in +pairs+ with the existing +section+. For example:
|
368
|
+
#
|
369
|
+
# config['default']
|
370
|
+
# #=> {"foo"=>"bar", "baz"=>"buz"}
|
371
|
+
# config['default'] = {"foo" => "changed"}
|
372
|
+
# #=> {"foo"=>"changed"}
|
373
|
+
# config['default']
|
374
|
+
# #=> {"foo"=>"changed", "baz"=>"buz"}
|
375
|
+
#
|
257
376
|
def []=(section, pairs)
|
258
377
|
check_modify
|
259
378
|
@data[section] ||= {}
|
@@ -262,10 +381,38 @@ module OpenSSL
|
|
262
381
|
end
|
263
382
|
end
|
264
383
|
|
384
|
+
##
|
385
|
+
# Get the names of all sections in the current configuration
|
265
386
|
def sections
|
266
387
|
@data.keys
|
267
388
|
end
|
268
389
|
|
390
|
+
##
|
391
|
+
# Get the parsable form of the current configuration
|
392
|
+
#
|
393
|
+
# Given the following configuration being created:
|
394
|
+
#
|
395
|
+
# config = OpenSSL::Config.new
|
396
|
+
# #=> #<OpenSSL::Config sections=[]>
|
397
|
+
# config['default'] = {"foo"=>"bar","baz"=>"buz"}
|
398
|
+
# #=> {"foo"=>"bar", "baz"=>"buz"}
|
399
|
+
# puts config.to_s
|
400
|
+
# #=> [ default ]
|
401
|
+
# # foo=bar
|
402
|
+
# # baz=buz
|
403
|
+
#
|
404
|
+
# You can parse get the serialized configuration using #to_s and then parse
|
405
|
+
# it later:
|
406
|
+
#
|
407
|
+
# serialized_config = config.to_s
|
408
|
+
# # much later...
|
409
|
+
# new_config = OpenSSL::Config.parse(serialized_config)
|
410
|
+
# #=> #<OpenSSL::Config sections=["default"]>
|
411
|
+
# puts new_config
|
412
|
+
# #=> [ default ]
|
413
|
+
# foo=bar
|
414
|
+
# baz=buz
|
415
|
+
#
|
269
416
|
def to_s
|
270
417
|
ary = []
|
271
418
|
@data.keys.sort.each do |section|
|
@@ -278,6 +425,15 @@ module OpenSSL
|
|
278
425
|
ary.join
|
279
426
|
end
|
280
427
|
|
428
|
+
##
|
429
|
+
# For a block.
|
430
|
+
#
|
431
|
+
# Receive the section and its pairs for the current configuration.
|
432
|
+
#
|
433
|
+
# config.each do |section, key, value|
|
434
|
+
# # ...
|
435
|
+
# end
|
436
|
+
#
|
281
437
|
def each
|
282
438
|
@data.each do |section, hash|
|
283
439
|
hash.each do |key, value|
|
@@ -286,13 +442,16 @@ module OpenSSL
|
|
286
442
|
end
|
287
443
|
end
|
288
444
|
|
445
|
+
##
|
446
|
+
# String representation of this configuration object, including the class
|
447
|
+
# name and its sections.
|
289
448
|
def inspect
|
290
449
|
"#<#{self.class.name} sections=#{sections.inspect}>"
|
291
450
|
end
|
292
451
|
|
293
452
|
protected
|
294
453
|
|
295
|
-
def data
|
454
|
+
def data # :nodoc:
|
296
455
|
@data
|
297
456
|
end
|
298
457
|
|