Skip to content

SSLSocket can't be created from UNIXSocket #2992

Closed

Description

@ojab

Testcase:

require 'socket'
require 'openssl'

from, to = UNIXSocket.pair
ssl_to = OpenSSL::SSL::SSLSocket.new(to)
ssl_to.write('foo')

fails with

SSLSocket.java:858:in `getSocketChannel': java.lang.ClassCastException: jnr.unixsocket.UnixSocketChannel cannot be cast to java.nio.channels.SocketChannel
    from SSLSocket.java:726:in `checkClosed'
    from SSLSocket.java:687:in `do_syswrite'
    from SSLSocket.java:711:in `syswrite'
    from SSLSocket$INVOKER$i$1$0$syswrite.gen:-1:in `call'
    from CachingCallSite.java:313:in `cacheAndCall'
    from CachingCallSite.java:163:in `call'
    from InterpreterEngine.java:292:in `processCall'
    from StartupInterpreterEngine.java:78:in `interpret'
    from InterpreterEngine.java:84:in `interpret'
    from MixedModeIRMethod.java:199:in `INTERPRET_METHOD'
    from MixedModeIRMethod.java:185:in `call'
    from DynamicMethod.java:205:in `call'
    from CachingCallSite.java:313:in `cacheAndCall'
    from CachingCallSite.java:163:in `call'
    from InterpreterEngine.java:292:in `processCall'
    from StartupInterpreterEngine.java:78:in `interpret'
    from InterpreterEngine.java:84:in `interpret'
    from MixedModeIRMethod.java:199:in `INTERPRET_METHOD'
    from MixedModeIRMethod.java:185:in `call'
    from DynamicMethod.java:205:in `call'
    from CachingCallSite.java:313:in `cacheAndCall'
    from CachingCallSite.java:163:in `call'
    from /tmp/socket.rb:-1:in `invokeOther9:write'
    from /tmp/socket.rb:6:in `RUBY$script'
    from MethodHandle.java:625:in `invokeWithArguments'
    from Compiler.java:111:in `load'
    from Ruby.java:833:in `runScript'
    from Ruby.java:822:in `runScript'
    from Ruby.java:752:in `runNormally'
    from Ruby.java:574:in `runFromMain'
    from Main.java:401:in `doRunFromMain'
    from Main.java:296:in `internalRun'
    from Main.java:225:in `run'
    from Main.java:197:in `main'

on JRuby jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-26 78b009c Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64], no error on MRI (tested with 1.9 & 2.2).

Activity

  1. headius commented on May 28, 2015

    @headius
    Member

    I guess this should work, but is there a reason you want to do it? I can find no good reason why you'd want to use SSL over a UNIX domain socket.

  2. ojab commented on May 28, 2015

    @ojab
    Author

    I've run tests of one proprietary product [that runs without failures under MRI] under JRuby and just reporting incompatibilities.
    Commit message for that testcase says that UNIX sockets are more reliable than TCP ones and I guess it should be reworked, but that's another story.
    I doubt that there is any practical use cases for SSL over UNIX sockets.

  3. headius commented on May 29, 2015

    @headius
    Member

    Ok thanks. I'm ambivalent about fixing this because it seems like a very unusual and synthetic case unlikely to affect JRuby users. However I will defer to the folks doing the most work on jruby-openssl, @kares and @mkristian.

  4. headius commented on Jun 2, 2015

    @headius
    Member

    @kares @mkristian Since this is a jruby-openssl issue (it needs to support non-socket selectable streams like UNIXSocketChannel) I'm closing it here.

  5. added this to the Invalid or Duplicate milestone on Jun 2, 2015
  6. andrew-aladev commented on Dec 2, 2016

    @andrew-aladev

    @ojab What is a unix socket? This is the most reliable and fast connection with some application. You can connect to this application and it will create an insecure channel to another application. You want to make this channel secure, you are going to use SSLSocket and you failed with unknow channel impl: jnr.unixsocket.UnixSocketChannel.

  7. ojab commented on Dec 2, 2016

    @ojab
    Author

    SSL is used for protection against MiTM attacks, if someone has access to intercept your unix-socket -- I doubt that SSL would prevent traffic interception/modification.

  8. andrew-aladev commented on Dec 2, 2016

    @andrew-aladev

    @ojab, My english is not very good, sorry.

    I mean that unix socket could be used instead of tcp socket in order to increase the performance of my connection to local application. The security of my connection to this unix socket is my responsibility.

    So I am connecting to local application and I am sure that it is secure. But than my local application creates an insecure channel to another application. What does it mean for me? My local secure connection has changed and now it is a remote insecure connection.

    What will be a good example for such usage? Lets imagine that famous http proxy squid supports a binding to unix socket instead of *:3128. I am connecting with jruby to this proxy and I am using http connect method to connect to google.com:443. Now I want to use SSLSocket to establish a secure connection.

  9. ojab commented on Dec 2, 2016

    @ojab
    Author

    Ah, yes, that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions