Package ej.wasi.ssl
Class WasiSSL
- java.lang.Object
-
- ej.wasi.ssl.WasiSSL
-
- All Implemented Interfaces:
WasiConstants
public class WasiSSL extends Object implements WasiConstants
Wasi SSL/TLS connection class.
-
-
Field Summary
-
Fields inherited from interface ej.wasi.WasiConstants
AF_INET, AF_INET6, BLOCKING_CONNECT_TIMEOUT, BUFFERED_INPUT_STREAM_SIZE, CLOCK_MONOTONIC, CLOCK_REALTIME, DIRENT_COOKIE_OFFSET, DIRENT_ENTRY_NAME_LENGTH_OFFSET, DIRENT_FILE_TYPE_OFFSET, DIRENT_INODE_OFFSET, DIRENT_SIZE, ERRNO_ACCES, ERRNO_ADDRINUSE, ERRNO_ADDRNOTAVAIL, ERRNO_AFNOSUPPORT, ERRNO_AGAIN, ERRNO_BADF, ERRNO_CONNREFUSED, ERRNO_EXIST, ERRNO_FAULT, ERRNO_HOSTUNREACH, ERRNO_INPROGRESS, ERRNO_INTR, ERRNO_INVAL, ERRNO_IO, ERRNO_ISCONN, ERRNO_ISDIR, ERRNO_MSGSIZE, ERRNO_NAMETOOLONG, ERRNO_NOENT, ERRNO_NOMEM, ERRNO_NOSYS, ERRNO_NOTCONN, ERRNO_NOTDIR, ERRNO_NOTEMPTY, ERRNO_NOTSOCK, ERRNO_NOTSUP, ERRNO_OVERFLOW, ERRNO_SPIPE, ERRNO_SUCCESS, EVENT_AVAILABLE_BYTE_OFFSET, EVENT_ERROR_OFFSET, EVENT_EVENT_TYPE_OFFSET, EVENT_READ_WRITE_HANGUP_OFFSET, EVENT_SIZE, EVENT_USER_DATA_OFFSET, FDFLAGS_APPEND_MASK, FDFLAGS_NON_BLOCK_MASK, FDSTAT_BASE_RIGHTS_OFFSET, FDSTAT_FILE_TYPE_OFFSET, FDSTAT_FLAGS_OFFSET, FDSTAT_INHERITING_RIGHTS_OFFSET, FILESTAT_FILESIZE_OFFSET, FILESTAT_FILETYPE_OFFSET, FILESTAT_INODE_OFFSET, FILESTAT_LAST_MODIFIED_TIME_OFFSET, IFF_LOOPBACK, IFF_RUNNING, IFF_UP, IOVEC_BUFFER_INDEX, IOVEC_BUFFER_LENGTH_INDEX, IOVEC_SIZE, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, IPPROTO_IP, IPPROTO_IPV6, IPv4AddressSize, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPv6AddressSize, LOOKUPFLAGS_SYMLINK_FOLLOW_MASK, MILLIS_TO_NANO, NON_BLOCKING_TIMEOUT, OFLAGS_CREAT_MASK, OFLAGS_DIRECTORY_MASK, OFLAGS_EXCL_MASK, OFLAGS_TRUNC_MASK, POLLING_TIMEOUT, PREOPENTYPE_DIR, PREOPENTYPE_UNKNOWN, PRESTAT_PREOPEN_DIRNAME_OFFSET, PRESTAT_PREOPEN_TAG_OFFSET, RIFLAGS_MSG_PEEK_MASK, RIFLAGS_WAITALL_MASK, RIGHTS_ALL, RIGHTS_DIR, SDFLAGS_READ, SDFLAGS_WRITE, SO_BROADCAST, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SOCK_CLOEXEC, SOCK_NONBLOCK, SOCKET_LEVEL, UDP_PEEK_BUFFER_MAX_SIZE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Retrieve the number of bytes available for reading on the socket.booleanisConnectionReset()Check whether the connection been reset by the peer.static intregisterSSLContext(WasmModule module, SSLContext ctx)Registers the given ssl context and returns its Wasi identifier.static intSSL_accept(WasmModule module, int ssl)Waits for a TLS/SSL client to initiate the handshake.static intSSL_connect(WasmModule module, int ssl)Starts the TLS/SSL handshake process with the server.static voidSSL_CTX_free(WasmModule module, int ctx)Releases/Frees the Wasi SSLContext identified by the given identifier.static voidSSL_free(WasmModule module, int ssl)Releases/Frees theWasiSSLidentified by the given identifier.static intSSL_new(WasmModule module, int ctx)Creates a newWasiSSLfor a TLS/SSL connection.static intSSL_pending(WasmModule module, int ssl)Returns the number of bytes available for an immediate read on the given TLS/SSL connection.static intSSL_read(WasmModule module, int ssl, int buf, int len)Readslenbytes from the given ssl connection and store them in the buffer.static intSSL_set_fd(WasmModule module, int ssl, int fd)Associates the file descriptor fd with the input/output operations for the encrypted TLS/SSL side of ssl.static intSSL_set_tlsext_host_name(WasmModule module, int ssl, int hostname)Sets the hostname sent by the client for Server Name Indication (SNI).static intSSL_shutdown(WasmModule module, int ssl)Terminates an active TLS/SSL connection by sending a "close notify" alert to the peer.static intSSL_want_read(WasmModule module, int ssl)Checks whether the TLS/SSL connection needs more data to be read from the underlying socket to proceed.static intSSL_want_write(int ssl)Checks whether the TLS/SSL connection needs more data to be written to the underlying socket to proceed.static intSSL_write(WasmModule module, int ssl, int buf, int len)Writeslenbytes from the buffer buf over the given ssl connection.
-
-
-
Method Detail
-
registerSSLContext
public static int registerSSLContext(WasmModule module, SSLContext ctx)
Registers the given ssl context and returns its Wasi identifier.- Parameters:
module- the Wasm module instance.ctx- the ssl context to be registered.- Returns:
- the Wasi identifier of the ssl context or
0if an error occurs.
-
SSL_new
public static int SSL_new(WasmModule module, int ctx)
Creates a newWasiSSLfor a TLS/SSL connection.- Parameters:
module- the Wasm module instance.ctx- the Wasi SSLContext identifier.- Returns:
- the new
WasiSSLidentifier orNULLif an error occurs.
-
SSL_set_fd
public static int SSL_set_fd(WasmModule module, int ssl, int fd)
Associates the file descriptor fd with the input/output operations for the encrypted TLS/SSL side of ssl.- Parameters:
module- the Wasm module instancessl- theWasiSSLidentifier.fd- the socket file descriptor.- Returns:
1on success or0on error.
-
SSL_accept
public static int SSL_accept(WasmModule module, int ssl)
Waits for a TLS/SSL client to initiate the handshake. It is called by the server once theWasiSSLhas been created and its underlying socket has been set up.- Parameters:
module- the Wasm module instancessl- the identifier of theWasiSSLrepresenting the TLS/SSL connection- Returns:
1on a successful handshake or0on error
-
SSL_pending
public static int SSL_pending(WasmModule module, int ssl)
Returns the number of bytes available for an immediate read on the given TLS/SSL connection. It tells whether decrypted data is ready to be read without blocking.- Parameters:
module- the Wasm module instancessl- the identifier of theWasiSSLrepresenting the TLS/SSL connection- Returns:
- the number of bytes available in the TLS/SSL buffer, or
0if an error occurs
-
SSL_set_tlsext_host_name
public static int SSL_set_tlsext_host_name(WasmModule module, int ssl, int hostname)
Sets the hostname sent by the client for Server Name Indication (SNI). It must be called beforeSSL_connect(WasmModule, int).- Parameters:
module- the Wasm module instancessl- the identifier of theWasiSSLrepresenting the TLS/SSL connectionhostname- the pointer to the null-terminated hostname string to send, or0to leave the hostname unset- Returns:
1on success or0on error
-
SSL_connect
public static int SSL_connect(WasmModule module, int ssl)
Starts the TLS/SSL handshake process with the server.- Parameters:
module- the Wasm module instance.ssl- the identifier of theWasiSSLrepresenting the TLS/SSL connection.- Returns:
1on success or0on error.
-
SSL_write
public static int SSL_write(WasmModule module, int ssl, int buf, int len)
Writeslenbytes from the buffer buf over the given ssl connection.- Parameters:
module- the Wasm module instancessl- the identifier of theWasiSSLrepresenting the TLS/SSL connection.buf- a pointer to the buffer containing the data to be sent.len- the number of bytes to write from the buffer.- Returns:
- the number of bytes successfully written, or a negative value on error.
-
SSL_read
public static int SSL_read(WasmModule module, int ssl, int buf, int len)
Readslenbytes from the given ssl connection and store them in the buffer.- Parameters:
module- the Wasm module instancessl- the identifier of theWasiSSLrepresenting the TLS/SSL connection.buf- the buffer pointer where the received data will be stored.len- the maximum number of bytes to read into the buffer.- Returns:
- the number of bytes actually read, or a negative value if an error occurs.
-
SSL_want_read
public static int SSL_want_read(WasmModule module, int ssl)
Checks whether the TLS/SSL connection needs more data to be read from the underlying socket to proceed. It tells whether the socket is ready for reading in non-blocking I/O scenarios.- Parameters:
module- the Wasm module instancessl- the identifier of theWasiSSLrepresenting the TLS/SSL connection- Returns:
1if more data needs to be read or0otherwise
-
SSL_want_write
public static int SSL_want_write(int ssl)
Checks whether the TLS/SSL connection needs more data to be written to the underlying socket to proceed. Non-blocking writes are not supported, so a failed write is never retried.- Parameters:
ssl- the identifier of theWasiSSLrepresenting the TLS/SSL connection- Returns:
0, as a failed write is never retried
-
SSL_shutdown
public static int SSL_shutdown(WasmModule module, int ssl)
Terminates an active TLS/SSL connection by sending a "close notify" alert to the peer.- Parameters:
module- the Wasm module instance.ssl- the identifier of theWasiSSLrepresenting the TLS/SSL connection to be shut down.- Returns:
1on success or a negative value if an error occurs.
-
SSL_free
public static void SSL_free(WasmModule module, int ssl)
Releases/Frees theWasiSSLidentified by the given identifier.- Parameters:
module- the Wasm module instance.ssl- the identifier of theWasiSSLrepresenting the TLS/SSL connection to be released.
-
SSL_CTX_free
public static void SSL_CTX_free(WasmModule module, int ctx)
Releases/Frees the Wasi SSLContext identified by the given identifier.- Parameters:
module- the Wasm module instance.ctx- A pointer to the SSL_CTX structure to be freed.
-
isConnectionReset
public boolean isConnectionReset() throws IOExceptionCheck whether the connection been reset by the peer.- Returns:
- connection reset status.
- Throws:
IOException- if the socket is not connected or an I/O error occurs.
-
available
public int available() throws IOExceptionRetrieve the number of bytes available for reading on the socket.- Returns:
- the number of bytes available for reading on the socket.
- Throws:
IOException- if an I/O error occurs.
-
-