Module: Ronin::Support::Web::WebSocket::Mixin

Included in:
Mixin
Defined in:
lib/ronin/support/web/websocket/mixin.rb

Overview

Adds helper methods for working with WebSockets.

Instance Method Summary collapse

Instance Method Details

#websocket_accept(url, ssl: {}, **kwargs) {|client| ... } ⇒ nil

Opens a WebSocket server, accepts a single connection, yields it to the given block, then closes both the connection and the server.

Parameters:

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

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

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (client)

    The given block will be passed the newly connected WebSocket client. After the block has finished, the WebSocket client will be closed.

Yield Parameters:

Returns:

  • (nil)

See Also:



324
325
326
# File 'lib/ronin/support/web/websocket/mixin.rb', line 324

def websocket_accept(url, ssl: {}, **kwargs,&block)
  WebSocket.accept(url, ssl: ssl, **kwargs,&block)
end

#websocket_connect(url, ssl: {}, **kwargs) {|websocket| ... } ⇒ Client

Connects to a websocket.

Examples:

Connecting to a WebSocket server:

websocket_connect('ws://websocket-echo.com')
# => #<Ronin::Support::Web::WebSocket::Client: ...>

Creating a temporary WebSocket connection:

websocket_connect('ws://websocket-echo.com') do |websocket|
  # ...
end

Parameters:

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

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

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Yields:

  • (websocket)

    If a block is given, then it will be passed the WebSocket connection. Once the block has returned, the WebSocket connection will be closed.

Yield Parameters:

  • websocket (Client)

    The WebSocket connection.

Returns:

  • (Client)

    The WebSocket connection.

See Also:



138
139
140
# File 'lib/ronin/support/web/websocket/mixin.rb', line 138

def websocket_connect(url, ssl: {}, **kwargs, &block)
  WebSocket.connect(url, ssl: ssl, **kwargs, &block)
end

#websocket_connect_and_send(data, url, type: :text, ssl: {}, **kwargs) {|websocket| ... } ⇒ Client

Connects to the WebSocket and sends the data.

Parameters:

  • data (String)

    The data to send to the WebSocket.

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

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

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Yields:

  • (websocket)

    If a block is given, then it will be passed the WebSocket connection. Once the block has returned, the WebSocket connection will be closed.

Yield Parameters:

  • websocket (Client)

    The WebSocket connection.

Returns:

  • (Client)

    The WebSocket connection.

See Also:



178
179
180
# File 'lib/ronin/support/web/websocket/mixin.rb', line 178

def websocket_connect_and_send(data,url, type: :text, ssl: {}, **kwargs,&block)
  WebSocket.connect_and_send(data,url, type: type, ssl: ssl, **kwargs,&block)
end

#websocket_open?(url, ssl: {}, **kwargs) ⇒ Boolean?

Tests whether the WebSocket is open.

Parameters:

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

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

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Returns:

  • (Boolean, nil)

    Specifies whether the WebSocket is open. If the connection was not accepted, nil will be returned.

See Also:



95
96
97
# File 'lib/ronin/support/web/websocket/mixin.rb', line 95

def websocket_open?(url, ssl: {}, **kwargs)
  WebSocket.open?(url, ssl: ssl, **kwargs)
end

#websocket_send(data, url, type: :text, ssl: {}, **kwargs) ⇒ true

Connects to the WebSocket, sends the data, and closes the connection.

Parameters:

  • data (String)

    The data to send to the WebSocket.

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

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

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Returns:

  • (true)

See Also:



210
211
212
# File 'lib/ronin/support/web/websocket/mixin.rb', line 210

def websocket_send(data,url, type: :text, ssl: {}, **kwargs)
  WebSocket.send(data,url, type: type, ssl: ssl, **kwargs)
end

#websocket_server(url, ssl: {}, **kwargs) {|server| ... } ⇒ Server

Starts a WebSocket server.

Parameters:

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

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

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (server)

    If a block is given, then it will be passed the WebSocket server. Once the block has returned, the WebSocket server will be closed.

Yield Parameters:

  • server (Server)

    The WebSocket server.

Returns:

  • (Server)

    The WebSocket server.

See Also:



256
257
258
# File 'lib/ronin/support/web/websocket/mixin.rb', line 256

def websocket_server(url, ssl: {}, **kwargs, &block)
  WebSocket.server(url, ssl: ssl, **kwargs, &block)
end

#websocket_server_loop(url, ssl: {}, **kwargs) {|client| ... } ⇒ nil

Creates a new WebSocket server listening on a given host and port, accepting clients in a loop.

Parameters:

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

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

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (client)

    The given block will be passed the newly connected WebSocket client. After the block has finished, the WebSocket client will be closed.

Yield Parameters:

Returns:

  • (nil)

See Also:



290
291
292
# File 'lib/ronin/support/web/websocket/mixin.rb', line 290

def websocket_server_loop(url, ssl: {}, **kwargs,&block)
  WebSocket.server_loop(url, ssl: ssl, **kwargs,&block)
end

#ws_accept(host, port = 80, ssl: {}, **kwargs) {|client| ... } ⇒ nil

Opens a WebSocket server, accepts a single connection, yields it to the given block, then closes both the connection and the server.

Parameters:

  • host (String, nil)

    The optional host that the WebSocket server will listen on.

  • port (Integer, nil) (defaults to: 80)

    The optional port that the WebSocket server will listen on.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (client)

    The given block will be passed the newly connected WebSocket client. After the block has finished, the WebSocket client will be closed.

Yield Parameters:

Returns:

  • (nil)

See Also:



762
763
764
765
766
# File 'lib/ronin/support/web/websocket/mixin.rb', line 762

def ws_accept(host,port=80, ssl: {}, **kwargs,&block)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.accept(uri, ssl: ssl, **kwargs,&block)
end

#ws_connect(host, port = 80, ssl: {}, **kwargs) {|websocket| ... } ⇒ Client

Connects to a WebSocket.

Examples:

Connecting to a WebSocket server:

ws_connect('ws://websocket-echo.com')
# => #<Ronin::Support::Web::WebSocket::Client: ...>

Creating a temporary WebSocket connection:

ws_connect('ws://websocket-echo.com') do |websocket|
  # ...
end

Parameters:

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 80)

    The WebSocket port.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Yields:

  • (websocket)

    If a block is given, then it will be passed the WebSocket connection. Once the block has returned, the WebSocket connection will be closed.

Yield Parameters:

  • websocket (Client)

    The WebSocket connection.

Returns:

  • (Client)

    The WebSocket connection.

See Also:



402
403
404
405
406
# File 'lib/ronin/support/web/websocket/mixin.rb', line 402

def ws_connect(host,port=80, ssl: {}, **kwargs,&block)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.connect(uri, ssl: ssl, **kwargs, &block)
end

#ws_connect_and_send(data, host, port = 80, type: :text, ssl: {}, **kwargs) {|websocket| ... } ⇒ Client

Connects to the WebSocket and sends the data.

Parameters:

  • data (String)

    The data to send to the WebSocket.

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 80)

    The WebSocket port.

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Yields:

  • (websocket)

    If a block is given, then it will be passed the WebSocket connection. Once the block has returned, the WebSocket connection will be closed.

Yield Parameters:

  • websocket (Client)

    The WebSocket connection.

Returns:

  • (Client)

    The WebSocket connection.

See Also:



447
448
449
450
451
# File 'lib/ronin/support/web/websocket/mixin.rb', line 447

def ws_connect_and_send(data,host,port=80, type: :text, ssl: {}, **kwargs,&block)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.connect_and_send(data,uri, type: type, ssl: ssl, **kwargs,&block)
end

#ws_open?(host, port = 80, ssl: {}, **kwargs) ⇒ Boolean?

Tests whether the WebSocket is open.

Parameters:

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 80)

    The WebSocket port.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Returns:

  • (Boolean, nil)

    Specifies whether the WebSocket is open. If the connection was not accepted, nil will be returned.

See Also:



354
355
356
357
358
# File 'lib/ronin/support/web/websocket/mixin.rb', line 354

def ws_open?(host,port=80, ssl: {}, **kwargs)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.open?(uri, ssl: ssl, **kwargs)
end

#ws_send(data, host, port = 80, type: :text, ssl: {}, **kwargs) ⇒ true

Connects to the WebSocket, sends the data, and closes the connection.

Parameters:

  • data (String)

    The data to send to the WebSocket.

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 80)

    The WebSocket port.

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Returns:

  • (true)

See Also:



484
485
486
487
488
# File 'lib/ronin/support/web/websocket/mixin.rb', line 484

def ws_send(data,host,port=80, type: :text, ssl: {}, **kwargs)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.send(data,uri, type: type, ssl: ssl, **kwargs)
end

#ws_server(host, port = 80, ssl: {}, **kwargs) {|server| ... } ⇒ Server

Starts a WebSocket server.

Parameters:

  • host (String, nil)

    The optional host that the WebSocket server will listen on.

  • port (Integer, nil) (defaults to: 80)

    The optional port that the WebSocket server will listen on.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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

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

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (server)

    If a block is given, then it will be passed the WebSocket server. Once the block has returned, the WebSocket server will be closed.

Yield Parameters:

  • server (Server)

    The WebSocket server.

Returns:

  • (Server)

    The WebSocket server.

See Also:

  • WebSocker.server


684
685
686
687
688
# File 'lib/ronin/support/web/websocket/mixin.rb', line 684

def ws_server(host,port=80, ssl: {}, **kwargs,&block)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.server(uri, ssl: ssl, **kwargs,&block)
end

#ws_server_loop(host, port = 80, ssl: {}, **kwargs) {|client| ... } ⇒ nil

Creates a new WebSocket server listening on a given host and port, accepting clients in a loop.

Parameters:

  • host (String, nil)

    The optional host that the WebSocket server will listen on.

  • port (Integer, nil) (defaults to: 80)

    The optional port that the WebSocket server will listen on.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (client)

    The given block will be passed the newly connected WebSocket client. After the block has finished, the WebSocket client will be closed.

Yield Parameters:

Returns:

  • (nil)

See Also:



723
724
725
726
727
# File 'lib/ronin/support/web/websocket/mixin.rb', line 723

def ws_server_loop(host,port=80, ssl: {}, **kwargs,&block)
  uri = URI::WS.build(host: host, port: port)

  WebSocket.server_loop(uri, ssl: ssl, **kwargs,&block)
end

#wss_accept(host, port = 443, ssl: {}, **kwargs) {|client| ... } ⇒ nil

Opens a SSL/TLS WebSocket server, accepts a single connection, yields it to the given block, then closes both the connection and the server.

Parameters:

  • host (String, nil)

    The optional host that the WebSocket server will listen on.

  • port (Integer, nil) (defaults to: 443)

    The optional port that the WebSocket server will listen on.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (client)

    The given block will be passed the newly connected WebSocket client. After the block has finished, the WebSocket client will be closed.

Yield Parameters:

Returns:

  • (nil)

See Also:



879
880
881
882
883
# File 'lib/ronin/support/web/websocket/mixin.rb', line 879

def wss_accept(host,port=443, ssl: {}, **kwargs,&block)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.accept(uri, ssl: ssl, **kwargs,&block)
end

#wss_connect(host, port = 443, ssl: {}, **kwargs) {|websocket| ... } ⇒ Client

Connects to a SSL/TLS WebSocket.

Examples:

Connecting to a WebSocket server:

wss_connect('websocket-echo.com')
# => #<Ronin::Support::Web::WebSocket::Client: ...>

Creating a temporary WebSocket connection:

wss_connect('websocket-echo.com') do |websocket|
  # ...
end

Parameters:

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 443)

    The WebSocket port.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Yields:

  • (websocket)

    If a block is given, then it will be passed the WebSocket connection. Once the block has returned, the WebSocket connection will be closed.

Yield Parameters:

  • websocket (Client)

    The WebSocket connection.

Returns:

  • (Client)

    The WebSocket connection.

See Also:



564
565
566
567
568
# File 'lib/ronin/support/web/websocket/mixin.rb', line 564

def wss_connect(host,port=443, ssl: {}, **kwargs,&block)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.connect(uri, ssl: ssl, **kwargs, &block)
end

#wss_connect_and_send(data, host, port = 443, type: :text, ssl: {}, **kwargs) {|websocket| ... } ⇒ Client

Connects to the SSL/TLS WebSocket and sends the data.

Parameters:

  • data (String)

    The data to send to the WebSocket.

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 443)

    The WebSocket port.

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Yields:

  • (websocket)

    If a block is given, then it will be passed the WebSocket connection. Once the block has returned, the WebSocket connection will be closed.

Yield Parameters:

  • websocket (Client)

    The WebSocket connection.

Returns:

  • (Client)

    The WebSocket connection.

See Also:



609
610
611
612
613
# File 'lib/ronin/support/web/websocket/mixin.rb', line 609

def wss_connect_and_send(data,host,port=443, type: :text, ssl: {}, **kwargs,&block)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.connect_and_send(data,uri, type: type, ssl: ssl, **kwargs, &block)
end

#wss_open?(host, port = 443, ssl: {}, **kwargs) ⇒ Boolean?

Tests whether the SSL/TLS WebSocket is open.

Parameters:

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 443)

    The WebSocket port.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Returns:

  • (Boolean, nil)

    Specifies whether the WebSocket is open. If the connection was not accepted, nil will be returned.

See Also:



516
517
518
519
520
# File 'lib/ronin/support/web/websocket/mixin.rb', line 516

def wss_open?(host,port=443, ssl: {}, **kwargs)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.open?(uri, ssl: ssl, **kwargs)
end

#wss_send(data, host, port = 443, type: :text, ssl: {}, **kwargs) ⇒ true

Connects to the SSL/TLS WebSocket, sends the data, and closes the connection.

Parameters:

  • data (String)

    The data to send to the WebSocket.

  • host (String)

    The WebSocket host.

  • port (Integer) (defaults to: 443)

    The WebSocket port.

  • type (:text, :binary, :ping, :pong, :close) (defaults to: :text)

    The data frame type.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Client#initialize.

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.

Returns:

  • (true)

See Also:



646
647
648
649
650
# File 'lib/ronin/support/web/websocket/mixin.rb', line 646

def wss_send(data,host,port=443, type: :text, ssl: {}, **kwargs)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.send(data,uri, type: type, ssl: ssl, **kwargs)
end

#wss_server(host, port = 443, ssl: {}, **kwargs) {|server| ... } ⇒ Server

Starts a SSL/TLS WebSocket server.

Parameters:

  • host (String, nil)

    The optional host that the WebSocket server will listen on.

  • port (Integer, nil) (defaults to: 443)

    The optional port that the WebSocket server will listen on.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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

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

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (server)

    If a block is given, then it will be passed the WebSocket server. Once the block has returned, the WebSocket server will be closed.

Yield Parameters:

  • server (Server)

    The WebSocket server.

Returns:

  • (Server)

    The WebSocket server.

See Also:



800
801
802
803
804
# File 'lib/ronin/support/web/websocket/mixin.rb', line 800

def wss_server(host,port=443, ssl: {}, **kwargs,&block)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.server(uri, ssl: ssl, **kwargs,&block)
end

#wss_server_loop(host, port = 443, ssl: {}, **kwargs) {|client| ... } ⇒ nil

Creates a new SSL/TLS WebSocket server listening on a given host and port, accepting clients in a loop.

Parameters:

  • host (String, nil)

    The optional host that the WebSocket server will listen on.

  • port (Integer, nil) (defaults to: 443)

    The optional port that the WebSocket server will listen on.

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

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

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Server#initialize.

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.

  • :backlog (Integer) — default: 5

    The maximum backlog of pending connections.

Yields:

  • (client)

    The given block will be passed the newly connected WebSocket client. After the block has finished, the WebSocket client will be closed.

Yield Parameters:

Returns:

  • (nil)

See Also:



839
840
841
842
843
# File 'lib/ronin/support/web/websocket/mixin.rb', line 839

def wss_server_loop(host,port=443, ssl: {}, **kwargs,&block)
  uri = URI::WSS.build(host: host, port: port)

  WebSocket.server_loop(uri, ssl: ssl, **kwargs,&block)
end