GSMLG.Socket.SSL (GSMLG.Socket v0.1.0)

This module allows usage of SSL sockets and promotion of TCP sockets to SSL sockets.

options

Options

When creating a socket you can pass a series of options to use for it.

  • :cert can either be an encoded certificate or [path: "path/to/certificate"]
  • :key can either be an encoded certificate, [path: "path/to/key"], [rsa: "rsa encoded"] or [dsa: "dsa encoded"] or [ec: "ec encoded"]
  • :authorities can iehter be an encoded authorities or [path: "path/to/authorities"]
  • :dh can either be an encoded dh or [path: "path/to/dh"]
  • :verify can either be false to disable peer certificate verification, or a keyword list containing a :function and an optional :data
  • :password the password to use to decrypt certificates
  • :renegotiation if it's set to :secure renegotiation will be secured
  • :ciphers is a list of ciphers to allow
  • :advertised_protocols is a list of strings representing the advertised protocols for NPN
  • :preferred_protocols is a list of strings representing the preferred next protocols for NPN

You can also pass TCP options.

smart-garbage-collection

Smart garbage collection

Normally sockets in Erlang are closed when the controlling process exits, with smart garbage collection the controlling process will be the GSMLG.Socket.Manager and it will be closed when there are no more references to it.

Link to this section Summary

Functions

Accept a connection from a listening SSL socket or start an SSL connection on the given client socket.

Accept a connection from a listening SSL socket with the given options or start an SSL connection on the given client socket with the given options.

Accept a connection from a listening SSL socket or start an SSL connection on the given client socket, raising if an error occurs.

Accept a connection from a listening SSL socket with the given options or start an SSL connection on the given client socket with the given options, raising if an error occurs.

Convert SSL options to :ssl.setopts compatible arguments.

Get the certificate of the peer.

Get the certificate of the peer, raising if an error occurs.

Get the list of supported ciphers.

Connect to the given address and port tuple or SSL connect the given socket.

Connect to the given address and port tuple with the given options or SSL connect the given socket with the given options or connect to the given address and port.

Connect to the given address and port with the given options.

Connect to the given address and port tuple or SSL connect the given socket, raising if an error occurs.

Connect to the given address and port tuple with the given options or SSL connect the given socket with the given options or connect to the given address and port, raising if an error occurs.

Connect to the given address and port with the given options, raising if an error occurs.

Return a proper error string for the given code or nil if it can't be converted.

Execute the handshake; useful if you want to delay the handshake to make it in another process.

Execute the handshake, raising if an error occurs; useful if you want to delay the handshake to make it in another process.

Get information about the SSL connection.

Get information about the SSL connection, raising if an error occurs.

Create an SSL socket listening on an OS chosen port, use local to know the port it was bound on.

Create an SSL socket listening on an OS chosen port using the given options or listening on the given port.

Create an SSL socket listening on the given port and using the given options.

Create an SSL socket listening on an OS chosen port, use local to know the port it was bound on, raising in case of error.

Create an SSL socket listening on an OS chosen port using the given options or listening on the given port, raising in case of error.

Create an SSL socket listening on the given port and using the given options, raising in case of error.

Get the negotiated protocol.

Set options of the socket.

Set options of the socket, raising if an error occurs.

Set the process which will receive the messages.

Set the process which will receive the messages, raising if an error occurs.

Renegotiate the secure connection.

Renegotiate the secure connection, raising if an error occurs.

Get the list of supported SSL/TLS versions.

Link to this section Types

@opaque t()

Link to this section Functions

@spec accept(GSMLG.Socket.t() | t()) :: {:ok, t()} | {:error, term()}

Accept a connection from a listening SSL socket or start an SSL connection on the given client socket.

Link to this function

accept(socket, options)

@spec accept(GSMLG.Socket.t(), Keyword.t()) :: {:ok, t()} | {:error, term()}

Accept a connection from a listening SSL socket with the given options or start an SSL connection on the given client socket with the given options.

Link to this function

accept!(socket)

@spec accept!(GSMLG.Socket.t() | t()) :: t() | no_return()

Accept a connection from a listening SSL socket or start an SSL connection on the given client socket, raising if an error occurs.

Link to this function

accept!(socket, options)

@spec accept!(GSMLG.Socket.t(), t() | Keyword.t()) :: t() | no_return()

Accept a connection from a listening SSL socket with the given options or start an SSL connection on the given client socket with the given options, raising if an error occurs.

Link to this function

arguments(options)

@spec arguments(Keyword.t()) :: list()

Convert SSL options to :ssl.setopts compatible arguments.

Link to this function

certificate(socket)

@spec certificate(t()) :: {:ok, String.t()} | {:error, term()}

Get the certificate of the peer.

Link to this function

certificate!(socket)

@spec certificate!(t()) :: String.t() | no_return()

Get the certificate of the peer, raising if an error occurs.

@spec ciphers() :: [:ssl.erl_cipher_suite()]

Get the list of supported ciphers.

Link to this function

connect(socket)

@spec connect(GSMLG.Socket.t() | {GSMLG.Socket.t(), :inet.port_number()}) ::
  {:ok, t()} | {:error, term()}

Connect to the given address and port tuple or SSL connect the given socket.

Link to this function

connect(wrap, options)

@spec connect(
  {GSMLG.Socket.Address.t(), :inet.port_number()}
  | GSMLG.Socket.t()
  | GSMLG.Socket.Address.t(),
  Keyword.t() | :inet.port_number()
) :: {:ok, t()} | {:error, term()}

Connect to the given address and port tuple with the given options or SSL connect the given socket with the given options or connect to the given address and port.

Link to this function

connect(address, port, options)

@spec connect(GSMLG.Socket.Address.t(), :inet.port_number(), Keyword.t()) ::
  {:ok, t()} | {:error, term()}

Connect to the given address and port with the given options.

Link to this function

connect!(socket_or_descriptor)

@spec connect!(GSMLG.Socket.t() | {GSMLG.Socket.t(), :inet.port_number()}) ::
  t() | no_return()

Connect to the given address and port tuple or SSL connect the given socket, raising if an error occurs.

Link to this function

connect!(descriptor, options)

Connect to the given address and port tuple with the given options or SSL connect the given socket with the given options or connect to the given address and port, raising if an error occurs.

Link to this function

connect!(address, port, options)

@spec connect!(GSMLG.Socket.Address.t(), :inet.port_number(), Keyword.t()) ::
  t() | no_return()

Connect to the given address and port with the given options, raising if an error occurs.

@spec error(term()) :: String.t()

Return a proper error string for the given code or nil if it can't be converted.

Link to this function

handshake(socket, options \\ [])

@spec handshake(t(), Keyword.t()) :: :ok | {:error, term()}

Execute the handshake; useful if you want to delay the handshake to make it in another process.

Link to this function

handshake!(socket)

@spec handshake!(t()) :: :ok | no_return()

Execute the handshake, raising if an error occurs; useful if you want to delay the handshake to make it in another process.

Link to this function

handshake!(socket, options)

@spec handshake!(t(), Keyword.t()) :: :ok | no_return()
@spec info(t()) :: {:ok, list()} | {:error, term()}

Get information about the SSL connection.

@spec info!(t()) :: list() | no_return()

Get information about the SSL connection, raising if an error occurs.

@spec listen() :: {:ok, t()} | {:error, term()}

Create an SSL socket listening on an OS chosen port, use local to know the port it was bound on.

@spec listen(:inet.port_number() | Keyword.t()) :: {:ok, t()} | {:error, term()}

Create an SSL socket listening on an OS chosen port using the given options or listening on the given port.

Link to this function

listen(port, options)

@spec listen(:inet.port_number(), Keyword.t()) :: {:ok, t()} | {:error, term()}

Create an SSL socket listening on the given port and using the given options.

@spec listen!() :: t() | no_return()

Create an SSL socket listening on an OS chosen port, use local to know the port it was bound on, raising in case of error.

Link to this function

listen!(port_or_options)

@spec listen!(:inet.port_number() | Keyword.t()) :: t() | no_return()

Create an SSL socket listening on an OS chosen port using the given options or listening on the given port, raising in case of error.

Link to this function

listen!(port, options)

@spec listen!(:inet.port_number(), Keyword.t()) :: t() | no_return()

Create an SSL socket listening on the given port and using the given options, raising in case of error.

Link to this function

negotiated_protocol(socket)

@spec negotiated_protocol(t()) :: String.t() | nil

Get the negotiated protocol.

Link to this function

options(socket, options)

@spec options(t() | :ssl.sslsocket(), Keyword.t()) ::
  :ok | {:error, GSMLG.Socket.Error.t()}

Set options of the socket.

Link to this function

options!(socket, options)

@spec options!(t() | t() | port(), Keyword.t()) :: :ok | no_return()

Set options of the socket, raising if an error occurs.

Link to this function

process(socket, pid)

@spec process(t() | port(), pid()) :: :ok | {:error, :closed | :not_owner | Error.t()}

Set the process which will receive the messages.

Link to this function

process!(socket, pid)

@spec process!(t() | port(), pid()) :: :ok | no_return()

Set the process which will receive the messages, raising if an error occurs.

Link to this function

renegotiate(socket)

@spec renegotiate(t()) :: :ok | {:error, term()}

Renegotiate the secure connection.

Link to this function

renegotiate!(socket)

@spec renegotiate!(t()) :: :ok | no_return()

Renegotiate the secure connection, raising if an error occurs.

@spec versions() :: [tuple()]

Get the list of supported SSL/TLS versions.