Sha256: 32e011e59b207e1070608b618766c7a71f2db890a0eec7d7b5b261b31964335a

Contents?: true

Size: 1.59 KB

Versions: 30

Compression:

Stored size: 1.59 KB

Contents

require 'socket'
require 'openssl'
require 'net/ssh/proxy/errors'
require 'net/ssh/proxy/http'

module Net; module SSH; module Proxy

  # A specialization of the HTTP proxy which encrypts the whole connection
  # using OpenSSL. This has the advantage that proxy authentication
  # information is not sent in plaintext.
  class HTTPS < HTTP

    # Create a new socket factory that tunnels via the given host and
    # port. The +options+ parameter is a hash of additional settings that
    # can be used to tweak this proxy connection. In addition to the options
    # taken by Net::SSH::Proxy::HTTP it supports:
    #
    # * :ssl_context => the SSL configuration to use for the connection
    def initialize(proxy_host, proxy_port=80, options={})
      @ssl_context = options.delete(:ssl_context) ||
                       OpenSSL::SSL::SSLContext.new
      super(proxy_host, proxy_port, options)
    end

    protected

      # Shim to make OpenSSL::SSL::SSLSocket behave like a regular TCPSocket
      # for all intents and purposes of Net::SSH::BufferedIo
      module SSLSocketCompatibility
        def self.extended(object) #:nodoc:
          object.define_singleton_method(:recv, object.method(:sysread))
          object.sync_close = true
        end

        def send(data, _opts)
          syswrite(data)
        end
      end

      def establish_connection(connect_timeout)
        plain_socket = super(connect_timeout)
        OpenSSL::SSL::SSLSocket.new(plain_socket, @ssl_context).tap do |socket|
          socket.extend(SSLSocketCompatibility)
          socket.connect
        end
      end
  end

end; end; end

Version data entries

30 entries across 27 versions & 3 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
net-ssh-5.0.0.beta1 lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/net-ssh-4.2.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
net-ssh-4.2.0 lib/net/ssh/proxy/https.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
vagrant-unbundled-1.9.7.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
net-ssh-4.2.0.rc2 lib/net/ssh/proxy/https.rb
net-ssh-4.2.0.rc1 lib/net/ssh/proxy/https.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-4.1.0/lib/net/ssh/proxy/https.rb
net-ssh-4.1.0 lib/net/ssh/proxy/https.rb