Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 47c9f427784d
Choose a base ref
...
head repository: jruby/jruby-openssl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ec9da7e9c596
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 18, 2017

  1. Copy the full SHA
    1091e80 View commit details
  2. Copy the full SHA
    fdd5a56 View commit details
  3. Copy the full SHA
    ec9da7e View commit details
Showing with 53 additions and 9 deletions.
  1. +13 −4 src/main/java/org/jruby/ext/openssl/SSLSocket.java
  2. +40 −5 src/test/ruby/ssl/test_socket.rb
17 changes: 13 additions & 4 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
import java.nio.ByteBuffer;
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@@ -40,7 +41,6 @@
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.util.Set;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
@@ -266,9 +266,16 @@ private IRubyObject connectImpl(final ThreadContext context, final boolean block
forceClose();
throw newSSLError(context.runtime, e);
}
catch (NotYetConnectedException e) {
throw newErrnoEPIPEError(context.runtime, "SSL_connect");
}
return this;
}

private static RaiseException newErrnoEPIPEError(final Ruby runtime, final String detail) {
return Utils.newError(runtime, runtime.getErrno().getClass("EPIPE"), detail);
}

@JRubyMethod
public IRubyObject accept(final ThreadContext context) {
return acceptImpl(context, true, true);
@@ -905,8 +912,10 @@ private void close(boolean force) {
try {
doShutdown();
}
catch (IOException e) {
// ignore?
catch (IOException e) { // ignore?
debug(getRuntime(), "SSLSocket.close doShutdown failed", e);
}
catch (NotYetConnectedException e) {
debug(getRuntime(), "SSLSocket.close doShutdown failed", e);
}
}
@@ -1122,7 +1131,7 @@ private SocketChannelImpl socketChannelImpl() {
throw new IllegalStateException("unknow channel impl: " + channel + " of type " + channel.getClass().getName());
}

private static interface SocketChannelImpl {
private interface SocketChannelImpl {

boolean isOpen() ;

45 changes: 40 additions & 5 deletions src/test/ruby/ssl/test_socket.rb
Original file line number Diff line number Diff line change
@@ -102,6 +102,40 @@ def test_read_nonblock_no_exception
end
end if RUBY_VERSION > '2.2'

def test_connect_non_connected; require 'socket'
socket = OpenSSL::SSL::SSLSocket.new(Socket.new(:INET, :STREAM))
begin
socket.connect_nonblock
rescue => e
assert_equal Errno::EPIPE, e.class
puts e.inspect if $VERBOSE
ensure
socket.close
end
end if RUBY_VERSION > '2.2'

def test_connect_nonblock
ssl_server = server
thread = Thread.new do
ssl_server.accept.tap { ssl_server.close }
end

host = "127.0.0.1"
ctx = OpenSSL::SSL::SSLContext.new()
ctx.ciphers = "ADH"
client = TCPSocket.new host, server_port(ssl_server)
client = OpenSSL::SSL::SSLSocket.new(client, ctx)
begin
client.connect_nonblock
rescue OpenSSL::SSL::SSLErrorWaitReadable => e
# #<OpenSSL::SSL::SSLErrorWaitReadable: read would block>
puts e.inspect if $VERBOSE
ensure
thread.kill if thread.alive?
client.close unless client.closed?
end
end if RUBY_VERSION > '2.2'

private

def server
@@ -125,13 +159,16 @@ def client(port)
ssl
end

def server_port(ssl_server = server)
ssl_server.to_io.local_address.ip_port
end

def ssl_pair
ssl_server = server
thread = Thread.new do
ssl_server.accept.tap { ssl_server.close }
end
port = ssl_server.to_io.local_address.ip_port
ssl_client = client(port)
ssl_client = client server_port(ssl_server)
ssl_socket = thread.value
if block_given?
begin
@@ -144,9 +181,7 @@ def ssl_pair
return ssl_client, ssl_socket
end
ensure
if thread && thread.alive?
thread.kill; thread.join
end
thread.tap { thread.kill; thread.join } if thread && thread.alive?
end

end