mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
JRuby - Add Puma::MiniSSL::Engine#init? and #teardown methods, run all SSL tests (#2317)
Update MiniSSL.java and minissl.rb for JRuby Add Puma::MiniSSL::Engine#init? and #teardown methods
This commit is contained in:
parent
2710a6a071
commit
fa6e916fc0
4 changed files with 53 additions and 10 deletions
|
@ -1,5 +1,7 @@
|
||||||
### Master
|
### Master
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
|
* JRuby - Add Puma::MiniSSL::Engine#init? and #teardown methods, run all SSL tests (#2317)
|
||||||
|
* Improve shutdown reliability (#2312)
|
||||||
* Resolve issue with threadpool waiting counter decrement when thread is killed
|
* Resolve issue with threadpool waiting counter decrement when thread is killed
|
||||||
* Constrain rake-compiler version to 0.9.4 to fix `ClassNotFound` exception when using MiniSSL with Java8.
|
* Constrain rake-compiler version to 0.9.4 to fix `ClassNotFound` exception when using MiniSSL with Java8.
|
||||||
* Ensure that TCP_CORK is usable
|
* Ensure that TCP_CORK is usable
|
||||||
|
|
|
@ -120,6 +120,8 @@ public class MiniSSL extends RubyObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SSLEngine engine;
|
private SSLEngine engine;
|
||||||
|
private boolean closed;
|
||||||
|
private boolean handshake;
|
||||||
private MiniSSLBuffer inboundNetData;
|
private MiniSSLBuffer inboundNetData;
|
||||||
private MiniSSLBuffer outboundAppData;
|
private MiniSSLBuffer outboundAppData;
|
||||||
private MiniSSLBuffer outboundNetData;
|
private MiniSSLBuffer outboundNetData;
|
||||||
|
@ -157,6 +159,8 @@ public class MiniSSL extends RubyObject {
|
||||||
SSLContext sslCtx = SSLContext.getInstance("TLS");
|
SSLContext sslCtx = SSLContext.getInstance("TLS");
|
||||||
|
|
||||||
sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||||
|
closed = false;
|
||||||
|
handshake = false;
|
||||||
engine = sslCtx.createSSLEngine();
|
engine = sslCtx.createSSLEngine();
|
||||||
|
|
||||||
String[] protocols;
|
String[] protocols;
|
||||||
|
@ -240,14 +244,21 @@ public class MiniSSL extends RubyObject {
|
||||||
// need to wait for more data to come in before we retry
|
// need to wait for more data to come in before we retry
|
||||||
retryOp = false;
|
retryOp = false;
|
||||||
break;
|
break;
|
||||||
default:
|
case CLOSED:
|
||||||
// other cases are OK and CLOSED. We're done here.
|
closed = true;
|
||||||
retryOp = false;
|
retryOp = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// other case is OK. We're done here.
|
||||||
|
retryOp = false;
|
||||||
|
}
|
||||||
|
if (res.getHandshakeStatus() == HandshakeStatus.FINISHED) {
|
||||||
|
handshake = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// after each op, run any delegated tasks if needed
|
// after each op, run any delegated tasks if needed
|
||||||
if(engine.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
|
if(res.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
|
||||||
Runnable runnable;
|
Runnable runnable;
|
||||||
while ((runnable = engine.getDelegatedTask()) != null) {
|
while ((runnable = engine.getDelegatedTask()) != null) {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
|
@ -271,13 +282,14 @@ public class MiniSSL extends RubyObject {
|
||||||
|
|
||||||
HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
|
HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
SSLEngineResult res = null;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
switch (handshakeStatus) {
|
switch (handshakeStatus) {
|
||||||
case NEED_WRAP:
|
case NEED_WRAP:
|
||||||
doOp(SSLOperation.WRAP, inboundAppData, outboundNetData);
|
res = doOp(SSLOperation.WRAP, inboundAppData, outboundNetData);
|
||||||
break;
|
break;
|
||||||
case NEED_UNWRAP:
|
case NEED_UNWRAP:
|
||||||
SSLEngineResult res = doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
|
res = doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
|
||||||
if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
|
if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
|
||||||
// need more data before we can shake more hands
|
// need more data before we can shake more hands
|
||||||
done = true;
|
done = true;
|
||||||
|
@ -286,7 +298,9 @@ public class MiniSSL extends RubyObject {
|
||||||
default:
|
default:
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
handshakeStatus = engine.getHandshakeStatus();
|
if (!done) {
|
||||||
|
handshakeStatus = res.getHandshakeStatus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inboundNetData.hasRemaining()) {
|
if (inboundNetData.hasRemaining()) {
|
||||||
|
@ -360,4 +374,21 @@ public class MiniSSL extends RubyObject {
|
||||||
return getRuntime().getNil();
|
return getRuntime().getNil();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JRubyMethod(name = "init?")
|
||||||
|
public IRubyObject isInit(ThreadContext context) {
|
||||||
|
return handshake ? getRuntime().getFalse() : getRuntime().getTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@JRubyMethod
|
||||||
|
public IRubyObject shutdown() {
|
||||||
|
if (closed || engine.isInboundDone() && engine.isOutboundDone()) {
|
||||||
|
if (engine.isOutboundDone()) {
|
||||||
|
engine.closeOutbound();
|
||||||
|
}
|
||||||
|
return getRuntime().getTrue();
|
||||||
|
} else {
|
||||||
|
return getRuntime().getFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,6 +197,9 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
if IS_JRUBY
|
if IS_JRUBY
|
||||||
|
OPENSSL_NO_SSL3 = false
|
||||||
|
OPENSSL_NO_TLS1 = false
|
||||||
|
|
||||||
class SSLError < StandardError
|
class SSLError < StandardError
|
||||||
# Define this for jruby even though it isn't used.
|
# Define this for jruby even though it isn't used.
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,10 +23,17 @@ DISABLE_SSL = begin
|
||||||
Puma::MiniSSL.check
|
Puma::MiniSSL.check
|
||||||
# net/http (loaded in helper) does not necessarily load OpenSSL
|
# net/http (loaded in helper) does not necessarily load OpenSSL
|
||||||
require "openssl" unless Object.const_defined? :OpenSSL
|
require "openssl" unless Object.const_defined? :OpenSSL
|
||||||
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
if Puma::IS_JRUBY
|
||||||
" Puma::MiniSSL OpenSSL",
|
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
||||||
"OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION.ljust 32}#{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
" OpenSSL",
|
||||||
" OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION.ljust 32}#{OpenSSL::OPENSSL_VERSION}", ""
|
"OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
||||||
|
" OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}", ""
|
||||||
|
else
|
||||||
|
puts "", RUBY_DESCRIPTION, "RUBYOPT: #{ENV['RUBYOPT']}",
|
||||||
|
" Puma::MiniSSL OpenSSL",
|
||||||
|
"OPENSSL_LIBRARY_VERSION: #{Puma::MiniSSL::OPENSSL_LIBRARY_VERSION.ljust 32}#{OpenSSL::OPENSSL_LIBRARY_VERSION}",
|
||||||
|
" OPENSSL_VERSION: #{Puma::MiniSSL::OPENSSL_VERSION.ljust 32}#{OpenSSL::OPENSSL_VERSION}", ""
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue