Module eco.ssl
SSL/TLS support.
This module provides TLS-enabled stream connections on top of eco.socket TCP sockets.
Functions
| listen (ipaddr, port[, options]) | Create a TLS server listener. |
| connect (ipaddr, port[, options]) | Create a TLS client connection. |
Class ssl_client
| ssl_client:send (data[, timeout]) | Send data. |
| ssl_client:write () | Alias of ssl_client:send. |
| ssl_client:sendfile (path, len[, offset[, timeout]]) | Send file content. |
| ssl_client:recv () | Alias of ssl_client:read. |
| ssl_client:read () | See read |
| ssl_client:readfull () | See readfull |
| ssl_client:readuntil () | See readuntil |
| ssl_client:close () | Close the TLS connection. |
Class ssl_server
| ssl_server:close () | Close the server and free its TLS context. |
| ssl_server:accept () | Accept a TLS client. |
Functions
- listen (ipaddr, port[, options])
-
Create a TLS server listener.
Internally this calls eco.socket.listen_tcp and wraps accepted sockets with TLS using a server context.
optionsfields used by TLS:ca: Path to CA certificate file.cert: Path to server certificate file.key: Path to server private key file.insecure: When true, disables/relaxes peer verification (backend dependent).
Other fields are passed to eco.socket.listen_tcp.
Parameters:
Returns:
-
ssl_server
Or
- nil On failure.
- string Error message.
- connect (ipaddr, port[, options])
-
Create a TLS client connection.
Internally this calls eco.socket.connect_tcp and performs a TLS handshake.
optionsfields used by TLS:ca: Path to CA certificate file.cert: Path to client certificate file (optional, for mTLS).key: Path to client private key file (optional, for mTLS).insecure: When true, disables/relaxes peer verification (backend dependent).server_name: SNI server name.ctx: An existing ssl context object to reuse.
Other fields are passed to eco.socket.connect_tcp.
If
options.ctxis provided, it is reused and will NOT be freed when the returned client is closed.Parameters:
Returns:
-
ssl_client
Or
- nil On failure.
- string Error message.
Class ssl_client
Instances are returned by connect or ssl_server:accept.
- ssl_client:send (data[, timeout])
-
Send data.
Parameters:
- data string Data to send.
- timeout number Timeout in seconds (optional)
Returns:
-
int
Bytes sent.
Or
- nil On failure.
- string Error message.
- ssl_client:write ()
- Alias of ssl_client:send.
- ssl_client:sendfile (path, len[, offset[, timeout]])
-
Send file content.
This is a convenience helper that reads from a file and sends exactly
lenbytes (unless EOF/error occurs).Parameters:
- path string File path.
- len int Bytes to send.
- offset int Start offset in file. (optional)
- timeout number Timeout in seconds (optional)
Returns:
-
int
Bytes sent.
Or
- nil On failure.
- string Error message.
- ssl_client:recv ()
- Alias of ssl_client:read.
- ssl_client:read ()
- See read
- ssl_client:readfull ()
- See readfull
- ssl_client:readuntil ()
- See readuntil
- ssl_client:close ()
-
Close the TLS connection.
Frees internal TLS state and closes the underlying TCP socket.
Class ssl_server
Instances are returned by listen.