Class: Ronin::Support::Web::WebSocket::Client

Inherits:
Socket
  • Object
show all
Includes:
URLMethods
Defined in:
lib/ronin/support/web/websocket/client.rb

Overview

Represents a WebSocket client.

Instance Attribute Summary

Attributes included from URLMethods

#host, #path, #port, #url

Attributes inherited from Socket

#handshake, #socket

Instance Method Summary collapse

Methods included from URLMethods

#ssl?

Methods inherited from Socket

#close, #closed?, #handshake_finished?, #handshake_valid?, #recv, #recv_frame, #send, #send_frame

Constructor Details

#initialize(url, ssl: {}, **kwargs) ⇒ Client

Initializes the WebSocket client.

Parameters:

  • url (String, URI::WS, URI::WSS)

    The ws:// or wss:// URL.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for.

  • ssl (Hash{Symbol => Object}) (defaults to: {})

    Additional keyword arguments for Ronin::Support::Network::SSL.connect.

Options Hash (ssl:):

  • :version (1, 1.1, 1.2, String, Symbol, nil)

    The SSL version to use.

  • :verify (Symbol, Boolean)

    Specifies whether to verify the SSL certificate. May be one of the following:

    • :none
    • :peer
    • :fail_if_no_peer_cert
    • :client_once
  • :key (Crypto::Key::RSA, OpenSSL::PKey::RSA, nil)

    The RSA key to use for the SSL context.

  • :key_file (String)

    The path to the SSL .key file.

  • :cert (Crypto::Cert, OpenSSL::X509::Certificate, nil)

    The X509 certificate to use for the SSL context.

  • :cert_file (String)

    The path to the SSL .crt file.

  • :ca_bundle (String)

    Path to the CA certificate file or directory.

Options Hash (**kwargs):

  • :bind_host (String, nil)

    The optional host to bind the server socket to.

  • :bind_port (Integer, nil)

    The optioanl port to bind the server socket to. If not specified, it will default to the port of the URL.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ronin/support/web/websocket/client.rb', line 86

def initialize(url, ssl: {}, **kwargs)
  super(url)

  @socket = case @url.scheme
            when 'ws'
              Support::Network::TCP.connect(
                @host, @port, **kwargs
              )
            when 'wss'
              Support::Network::SSL.connect(
                @host, @port, **kwargs, **ssl
              )
            else
              raise(ArgumentError,"unsupported websocket scheme: #{url}")
            end

  send_handshake!

  set_frame_classes(
    ::WebSocket::Frame::Incoming::Client,
    ::WebSocket::Frame::Outgoing::Client
  )
end