Skip to content

Question: How to nest SSL sockets? #868

@ag-TJNII

Description

@ag-TJNII

I'm trying to set up a SSL socket over another SSL socket:

require 'net/http'

s = TCPSocket.open('127.0.0.1', 4433, nil, nil)
proxy_sock = OpenSSL::SSL::SSLSocket.new(s)
Net::Protocol.new.send(:ssl_socket_connect, proxy_sock, 1.0)

OpenSSL::SSL::SSLSocket.new(proxy_sock)
$ ruby tmp/minimal_example.rb
tmp/minimal_example.rb:7:in 'OpenSSL::SSL::SSLSocket#initialize': wrong argument type OpenSSL::SSL::SSLSocket (expected File) (TypeError)

OpenSSL::SSL::SSLSocket.new(proxy_sock)
                            ^^^^^^^^^^
        from tmp/minimal_example.rb:7:in 'Class#new'
        from tmp/minimal_example.rb:7:in '<main>'

The real-world use case is a HTTP proxy that has it's own SSL listener. The flow in this scenario is to:

  • Open a SSL socket to the proxy
  • Negotiate a connection to a external server through the proxy
  • Open a SSL socket to the remote server over the existing SSL proxy socket

Looking over the code I don't see any obvious "Here's how to do it" attributes/methods. What is the best way to accomplish this?

Ref: ruby/net-http#212

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions