Module: Daytona::Common::WebSocketDialer

Defined in:
lib/daytona/common/websocket_dialer.rb

Overview

Establishes WebSocket connections with the peer certificate fully verified before any request bytes are written.

websocket-client-simple builds its own SSLContext and never calls OpenSSL::SSL::SSLContext#set_params, so it does not pick up Ruby's own defaults (verify_mode: VERIFY_PEER, verify_hostname: true). It applies verify_mode only when the caller passes it, and offers no way to enable hostname verification at all. Because the context is frozen by SSLSocket.new and the handshake is written before connect returns, there is no caller-side hook to correct this - so the dial itself has to be owned here.

Chain verification alone is not sufficient: without hostname verification a peer holding any valid certificate can terminate the connection and receive the request headers.

Defined Under Namespace

Classes: VerifyingClient

Class Method Summary collapse

Class Method Details

.connect(url, options = {}) {|client| ... } ⇒ VerifyingClient

Opens a verified WebSocket connection.

Mirrors WebSocket::Client::Simple.connect: the block, if given, receives the client before the connection is established so handlers can be registered, and the client is returned.

Parameters:

  • The ws:// or wss:// URL to dial.

  • (defaults to: {})

    Passed through to the client; :headers, :ssl_version and :cert_store are honoured.

Yields:

  • (client)

Returns:

  • The connected client.

Raises:

  • If the peer certificate fails chain or hostname verification.



40
41
42
43
44
45
# File 'lib/daytona/common/websocket_dialer.rb', line 40

def self.connect(url, options = {})
  client = VerifyingClient.new
  yield client if block_given?
  client.connect(url, options)
  client
end