Package ej.wasi.ssl

Class WasiSSL

    • 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 0 if an error occurs.
      • SSL_new

        public static int SSL_new​(WasmModule module,
                                  int ctx)
        Creates a new WasiSSL for a TLS/SSL connection.
        Parameters:
        module - the Wasm module instance.
        ctx - the Wasi SSLContext identifier.
        Returns:
        the new WasiSSL identifier or NULL if 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 instance
        ssl - the WasiSSL identifier.
        fd - the socket file descriptor.
        Returns:
        1 on success or 0 on 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 the WasiSSL has been created and its underlying socket has been set up.
        Parameters:
        module - the Wasm module instance
        ssl - the identifier of the WasiSSL representing the TLS/SSL connection
        Returns:
        1 on a successful handshake or 0 on 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 instance
        ssl - the identifier of the WasiSSL representing the TLS/SSL connection
        Returns:
        the number of bytes available in the TLS/SSL buffer, or 0 if 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 before SSL_connect(WasmModule, int).
        Parameters:
        module - the Wasm module instance
        ssl - the identifier of the WasiSSL representing the TLS/SSL connection
        hostname - the pointer to the null-terminated hostname string to send, or 0 to leave the hostname unset
        Returns:
        1 on success or 0 on 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 the WasiSSL representing the TLS/SSL connection.
        Returns:
        1 on success or 0 on error.
      • SSL_write

        public static int SSL_write​(WasmModule module,
                                    int ssl,
                                    int buf,
                                    int len)
        Writes len bytes from the buffer buf over the given ssl connection.
        Parameters:
        module - the Wasm module instance
        ssl - the identifier of the WasiSSL representing 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)
        Reads len bytes from the given ssl connection and store them in the buffer.
        Parameters:
        module - the Wasm module instance
        ssl - the identifier of the WasiSSL representing 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 instance
        ssl - the identifier of the WasiSSL representing the TLS/SSL connection
        Returns:
        1 if more data needs to be read or 0 otherwise
      • 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 the WasiSSL representing 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 the WasiSSL representing the TLS/SSL connection to be shut down.
        Returns:
        1 on success or a negative value if an error occurs.
      • SSL_free

        public static void SSL_free​(WasmModule module,
                                    int ssl)
        Releases/Frees the WasiSSL identified by the given identifier.
        Parameters:
        module - the Wasm module instance.
        ssl - the identifier of the WasiSSL representing 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 IOException
        Check 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 IOException
        Retrieve 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.