net.tls Package

Function Description

The TLS package provides secure communications over a computer network with its capabilities such as creating TLS servers, performing TLS handshakes based on protocols, sending and receiving encrypted data, and restoring TLS sessions.

This package supports TLS 1.2 and TLS 1.3.

This package depends on the SSL and crypto dynamic library files of OpenSSL 3. Therefore, related tools must be installed in advance.

  • For Linux, perform the following operations:
    • Install the OpenSSL 3 development tool package using the package management tool of the system if the tool supports the installation, and ensure that the system installation directory contains the libssl.so, libssl.so.3, libcrypto.so, and libcrypto.so.3 dynamic library files. For example, on Ubuntu 22.04, run the sudo apt install libssl-dev command to install the libssl-dev tool package.
    • Download and install the OpenSSL 3.*x*.*x* source code compilation software package if the preceding method fails, and ensure that the installation directory contains the libssl.so, libssl.so.3, libcrypto.so, and libcrypto.so.3 dynamic library files. Then, use either of the following methods to ensure that the system linker can find these files:
      • Install OpenSSL in the system path if it has not been installed in the system.
      • Set the directory where the OpenSSL development tool package files are located to the environment variables LD_LIBRARY_PATH and LIBRARY_PATH if OpenSSL is installed in a user-defined directory.
  • For Windows, perform the following operations:
    • Download and install the OpenSSL 3.*x*.*x* source code compilation software package for the x64 architecture, or download and install the OpenSSL 3.*x*.*x* software package precompiled by a third party for developers.
    • Ensure that the installation directory contains the libssl.dll.a (or libssl.lib), libssl-3-x64.dll, libcrypto.dll.a (or libcrypto.lib), and libcrypto-3-x64.dll library files.
    • Set the directory containing libssl.dll.a (or libssl.lib) and libcrypto.dll.a (or libcrypto.lib) to the environment variable LIBRARY_PATH, and the directory containing libssl-3-x64.dll and libcrypto-3-x64.dll to the environment variable PATH.
  • For macOS, perform the following operations:
    • Run the brew install openssl@3 command to install OpenSSL, and ensure that the system installation directory contains the libcrypto.dylib and libcrypto.3.dylib dynamic library files.
    • Download and install the OpenSSL 3.*x*.*x* source code compilation software package if the preceding method fails, and ensure that the installation directory contains the libcrypto.dylib and libcrypto.3.dylib dynamic library files. Then, use either of the following methods to ensure that the system linker can find these files:
      • Install OpenSSL in the system path if it has not been installed in the system.
      • Set the directory where the OpenSSL development tool package files are located to the environment variables DYLD_LIBRARY_PATH and LIBRARY_PATH if OpenSSL is installed in a user-defined directory.

Note:

If OpenSSL 3 is not installed or an earlier version is installed, the program may fail to work with the following exception thrown: TlsException: Can not load openssl library or function xxx.

API List

Class

NameDescription
TlsSessionContextThe server enables the session feature to restore sessions and stores sessions for client authentication.
TlsSocketCreates an encrypted transmission channel between the client and server.

Enumeration

NameDescription
CertificateVerifyModeCertificate authentication mode.
SignatureAlgorithmSpecifies the signature algorithm type. The signature algorithm is used to ensure the identity authentication, integrity, and authenticity of transmitted data.
SignatureSchemeTypeSpecifies the encryption algorithm type, which is used to protect the security and privacy of network communication.
SignatureTypeSpecifies the signature algorithm type, which is used for authenticity authentication.
TlsClientIdentificationModeSpecifies the mode for the server to authenticate the client certificate.
TlsVersionSpecifies the TLS protocol version.

Struct

NameDescription
CipherSuiteSpecifies the cipher suite in TLS.
TlsClientConfigSpecifies the client configuration.
TlsServerConfigSpecifies the server configuration.
TlsSessionAfter the TLS handshake with the client is successful, a session is generated. If the connection is lost due to some reasons, the client can reuse the session by using the session ID and skip the handshake process.

Exception Class

NameDescription
TlsExceptionIndicates the exception type thrown when an error occurs during TLS processing.