Skip to content

Commit b32a4fa

Browse files
committed
Merge branch '0.14'
* 0.14: [release] update for next dev SNAPSHOT [release] prepare for 0.14.6 [compat] OpenSSL::ConfigError and DEFAULT_CONFIG_FILE (#304) [fix] OpenSSL::PKey::DH#set_pqg regression (#300) Convert IOException to Ruby exception correctly [refactor] add exception debugging within SSLSocket#waitSelect [fix] sync SSLContext#setup as it could be shared (#302) [refactor] freeze SSLContext when everything okay [refactor] organize i-var sets (set @context after setup) [test] regenerate OpenSSL CA based setup [release] update to 0.14.6.dev SNAPSHOT
2 parents c201ae3 + c1672c9 commit b32a4fa

File tree

7 files changed

+58
-35
lines changed

7 files changed

+58
-35
lines changed

History.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
## 0.14.6
2+
3+
* [compat] OpenSSL::ConfigError and DEFAULT_CONFIG_FILE (#304)
4+
* [fix] `OpenSSL::PKey::DH#set_pqg` regression (#300)
5+
* Convert `IOException` to Ruby exception correctly (#242)
6+
* [refactor] add exception debugging within SSLSocket#waitSelect
7+
* [fix] sync `SSLContext#setup` as it could be shared (#302)
8+
* [refactor] organize i-var sets (set `@context` after setup)
9+
110
## 0.14.5
211

3-
* [fix] OpenSSL::X509::Request#verify with DSA public key
12+
* [fix] `OpenSSL::X509::Request#verify` with DSA public key
413
(this was a regression introduced in JOSSL 0.14.4)
514

615
## 0.14.4

lib/jopenssl/_compat23.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def set_key(pub_key, priv_key)
1414

1515
def set_pqg(p, q, g)
1616
self.p = p
17-
if respond_to?(:q)
17+
if respond_to?(:q=)
1818
self.q = q
19-
else # TODO self.q = q
19+
else
2020
OpenSSL.warn "JRuby-OpenSSL does not support setting q param on #{inspect}" if q
2121
end
2222
self.g = g

lib/jopenssl/load.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
module OpenSSL
4545
autoload :Config, 'openssl/config' unless const_defined?(:Config, false)
46+
autoload :ConfigError, 'openssl/config' unless const_defined?(:ConfigError, false)
4647
autoload :PKCS12, 'openssl/pkcs12'
4748
end
4849

lib/openssl/config.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require 'stringio'
1515

1616
module OpenSSL
17+
class ConfigError < OpenSSLError; end
1718
##
1819
# = OpenSSL::Config
1920
#
@@ -27,6 +28,8 @@ module OpenSSL
2728
class Config
2829
include Enumerable
2930

31+
DEFAULT_CONFIG_FILE = nil # JRuby: compatibility (we do not read openssl.cnf)
32+
3033
class << self
3134

3235
##

src/main/java/org/jruby/ext/openssl/SSLContext.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public SSLContext(Ruby runtime, RubyClass type) {
315315
//private int sessionCacheMode; // 2 default on MRI
316316
private int sessionCacheSize; // 20480
317317

318-
private InternalContext internalContext;
318+
private volatile InternalContext internalContext;
319319

320320
@JRubyMethod(required = 0, optional = 1, visibility = Visibility.PRIVATE)
321321
public IRubyObject initialize(IRubyObject[] args) {
@@ -334,16 +334,11 @@ public IRubyObject initialize_copy(IRubyObject original) {
334334
final SSLContext initializeImpl() { return this; }
335335

336336
@JRubyMethod
337-
public IRubyObject setup(final ThreadContext context) {
337+
public synchronized IRubyObject setup(final ThreadContext context) {
338338
final Ruby runtime = context.runtime;
339339

340340
if ( isFrozen() ) return runtime.getNil();
341341

342-
synchronized(this) {
343-
if ( isFrozen() ) return runtime.getNil();
344-
this.freeze(context);
345-
}
346-
347342
final X509Store certStore = getCertStore();
348343

349344
// TODO: handle tmp_dh_callback :
@@ -513,6 +508,8 @@ public IRubyObject setup(final ThreadContext context) {
513508
throw newSSLError(runtime, e);
514509
}
515510

511+
this.freeze(context);
512+
516513
return runtime.getTrue();
517514
}
518515

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,26 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
162162
final Ruby runtime = context.runtime;
163163

164164
if (Arity.checkArgumentCount(runtime, args, 1, 2) == 1) {
165-
sslContext = new SSLContext(runtime).initializeImpl();
165+
this.sslContext = new SSLContext(runtime).initializeImpl();
166166
} else {
167167
if (!(args[1] instanceof SSLContext)) {
168168
throw runtime.newTypeError(args[1], "OpenSSL::SSL::SSLContext");
169169
}
170-
sslContext = (SSLContext) args[1];
170+
this.sslContext = (SSLContext) args[1];
171171
}
172172

173173
if (!(args[0] instanceof RubyIO)) {
174174
throw runtime.newTypeError("IO expected but got " + args[0].getMetaClass().getName());
175175
}
176-
setInstanceVariable("@context", this.sslContext); // only compat (we do not use @context)
177-
setInstanceVariable("@io", this.io = (RubyIO) args[0]);
176+
setInstanceVariable("@io", this.io = (RubyIO) args[0]); // RubyBasicSocket extends RubyIO
178177
set_io_nonblock_checked(context, runtime.getTrue());
179178
// This is a bit of a hack: SSLSocket should share code with
180179
// RubyBasicSocket, which always sets sync to true.
181180
// Instead we set it here for now.
182181
set_sync(context, runtime.getTrue()); // io.sync = true
183182
setInstanceVariable("@sync_close", runtime.getFalse()); // self.sync_close = false
184183
sslContext.setup(context);
184+
setInstanceVariable("@context", sslContext); // only compat (we do not use @context)
185185

186186
this.initializeTime = System.currentTimeMillis();
187187

@@ -471,8 +471,8 @@ else if ((operations & SelectionKey.OP_WRITE) != 0) {
471471
writeWouldBlock(runtime, exception, result);
472472
}
473473
}
474-
}
475-
catch (IOException ioe) {
474+
} catch (IOException ioe) {
475+
debugStackTrace(runtime, "SSLSocket.waitSelect", ioe);
476476
throw runtime.newRuntimeError("Error with selector: " + ioe.getMessage());
477477
}
478478
} else {
@@ -483,6 +483,7 @@ public void run() throws InterruptedException {
483483
result[0] = selector.select();
484484
}
485485
catch (IOException ioe) {
486+
debugStackTrace(runtime, "SSLSocket.waitSelect", ioe);
486487
throw runtime.newRuntimeError("Error with selector: " + ioe.getMessage());
487488
}
488489
}
@@ -505,32 +506,27 @@ public void wakeup() {
505506
//JRuby <= 9.1.2.0 that makes this not always the case, so we have to check
506507
return selector.selectedKeys().contains(key) ? Boolean.TRUE : Boolean.FALSE;
507508
}
508-
}
509-
catch (InterruptedException interrupt) { return Boolean.FALSE; }
510-
finally {
511-
// Note: I don't like ignoring these exceptions, but it's
512-
// unclear how likely they are to happen or what damage we
513-
// might do by ignoring them. Note that the pieces are separate
514-
// so that we can ensure one failing does not affect the others
515-
// running.
509+
} catch (InterruptedException interrupt) {
510+
debug(runtime, "SSLSocket.waitSelect", interrupt);
511+
return Boolean.FALSE;
512+
} finally {
513+
// Note: I don't like ignoring these exceptions, but it's unclear how likely they are to happen or what
514+
// damage we might do by ignoring them. Note that the pieces are separate so that we can ensure one failing
515+
// does not affect the others running.
516516

517517
// clean up the key in the selector
518518
try {
519519
if ( key != null ) key.cancel();
520520
if ( selector != null ) selector.selectNow();
521-
}
522-
catch (Exception e) { // ignore
523-
debugStackTrace(runtime, e);
521+
} catch (Exception e) { // ignore
522+
debugStackTrace(runtime, "SSLSocket.waitSelect (ignored)", e);
524523
}
525524

526525
// shut down and null out the selector
527526
try {
528-
if ( selector != null ) {
529-
runtime.getSelectorPool().put(selector);
530-
}
531-
}
532-
catch (Exception e) { // ignore
533-
debugStackTrace(runtime, e);
527+
if ( selector != null ) runtime.getSelectorPool().put(selector);
528+
} catch (Exception e) { // ignore
529+
debugStackTrace(runtime, "SSLSocket.waitSelect (ignored)", e);
534530
}
535531

536532
if (blocking) {
@@ -810,8 +806,11 @@ private void doShutdown() throws IOException {
810806
flushData(true);
811807
}
812808

813-
private IRubyObject sysreadImpl(final ThreadContext context,
814-
IRubyObject len, IRubyObject buff, final boolean blocking, final boolean exception) {
809+
/**
810+
* @return the (@link RubyString} buffer or :wait_readable / :wait_writeable {@link RubySymbol}
811+
*/
812+
private IRubyObject sysreadImpl(final ThreadContext context, final IRubyObject len, final IRubyObject buff,
813+
final boolean blocking, final boolean exception) {
815814
final Ruby runtime = context.runtime;
816815

817816
final int length = RubyNumeric.fix2int(len);

src/test/ruby/test_pkey.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ def test_pkey_pem_file_error
8383
end
8484
end
8585

86+
def test_pkey_dh
87+
dh = OpenSSL::PKey::DH.new
88+
assert_equal nil, dh.p
89+
assert_equal nil, dh.priv_key
90+
91+
# OpenSSL::PKey::PKeyError: dh#set_pqg= is incompatible with OpenSSL 3.0
92+
if defined? JRUBY_VERSION
93+
dh.set_pqg(1_000_000, nil, 10)
94+
assert_equal 1_000_000, dh.p
95+
assert_equal 10, dh.g
96+
end
97+
assert_equal nil, dh.q
98+
end
99+
86100
def test_to_java
87101
pkey = OpenSSL::PKey.read(KEY)
88102
assert_kind_of java.security.PublicKey, pkey.to_java

0 commit comments

Comments
 (0)