Struct

struct CipherSuite

public struct CipherSuite <: ToString & Equatable<CipherSuite>

Description: Represents the cipher suite in TLS.

Parent Type:

static prop allSupported

public static prop allSupported: Array<CipherSuite>

Description: Returns all supported cipher suites.

Returns: array for storing cipher suites

Type: Array<CipherSuite>

func toString()

public func toString(): String

Description: Returns the cipher suite name.

Returns:

operator func !=(CipherSuite)

public operator func !=(that: CipherSuite): Bool

Description: Checks whether two cipher suites are not equal.

Parameters:

  • that: CipherSuite: the other cipher suite to be compared with

Returns:

  • Bool: If the two cipher suites are not equal, true is returned. Otherwise, false is returned.

operator func ==(CipherSuite)

public operator func ==(that: CipherSuite): Bool

Description: Checks whether two cipher suites are equal.

Parameters:

  • that: CipherSuite: the other cipher suite to be compared with

Returns:

  • Bool: If the two cipher suites are equal, true is returned. Otherwise, false is returned.

struct TlsClientConfig

public struct TlsClientConfig

Description: Represents the client configuration.

var keylogCallback

public var keylogCallback: ?(TlsSocket, String) -> Unit = None

Description: Represents a callback function for the handshake process. It provides the initial TLS key data for debugging and decryption.

Type: ?(TlsSocket, String) -> Unit

var verifyMode

public var verifyMode: CertificateVerifyMode = CertificateVerifyMode.Default

Description: Sets or obtains the certificate authentication mode. The default value is Default.

Type: CertificateVerifyMode

prop alpnProtocolsList

public mut prop alpnProtocolsList: Array<String>

Description: Negotiates the application layer protocol. If the list is empty, the client does not negotiate the application layer protocol.

Type: Array<String>

Throws:

prop cipherSuitesV1_2

public mut prop cipherSuitesV1_2: ?Array<String>

Description: Represents the TLS 1.2-based cipher suite.

Type: ?Array<String>

Throws:

prop cipherSuitesV1_3

public mut prop cipherSuitesV1_3: ?Array<String>

Description: Represents the TLS 1.3-based cipher suite.

Type: ?Array<String>

Throws:

prop clientCertificate

public mut prop clientCertificate: ?(Array<X509Certificate>, PrivateKey)

Description: Represents the client certificate and private key.

Type: ?(Array<X509Certificate>, PrivateKey)

prop domain

public mut prop domain: ?String

Description: Represents the server host address (SNI) required for read and write. None indicates that the SNI is not required.

Type: ?String

Throws:

prop maxVersion

public mut prop maxVersion: TlsVersion

Description: Represents the latest TLS version supported.

Note:

If maxVersion is set but minVersion is not set, or if the set maxVersion is earlier than minVersion, TlsException is thrown during handshake.

Type: TlsVersion

prop minVersion

public mut prop minVersion: TlsVersion

Description: Represents the earliest TLS version supported.

Note:

If minVersion is set but maxVersion is not set, or if the set minVersion is later than maxVersion, TlsException is thrown during handshake.

Type: TlsVersion

prop securityLevel

public mut prop securityLevel: Int32

Description: Specifies the security level of the client. The default value is 2. The value ranges from 0 to 5. For details about the parameter description, see the description of openssl-SSL_CTX_set_security_level.

Type: Int32

prop signatureAlgorithms

public mut prop signatureAlgorithms: ?Array<SignatureAlgorithm>

Description: Specifies the signature and hash algorithm for order preserving. If the value is None or the list is empty, the client uses the default list. After the list is specified, the client may not send inappropriate signature algorithms. For details, see RFC5246 7.4.1.4.1 (TLS 1.2) and RFC8446 4.2.3 (TLS 1.3).

Type: ?Array<SignatureAlgorithm>

init()

public init()

Description: Constructs TlsClientConfig.

struct TlsServerConfig

public struct TlsServerConfig

Description: Represents the server configuration.

var clientIdentityRequired

public var clientIdentityRequired: TlsClientIdentificationMode = Disabled

Description: Sets or obtains the client authentication mode required by the server. By default, the client is not required to authenticate the server certificate or send its certificate.

Type: TlsClientIdentificationMode

var keylogCallback

public var keylogCallback: ?(TlsSocket, String) -> Unit = None

Description: Represents a callback function for the handshake process. It provides the initial TLS key data for debugging and decryption.

Type: ?(TlsSocket, String) -> Unit

var verifyMode

public var verifyMode: CertificateVerifyMode = CertificateVerifyMode.Default

Description: Sets or obtains the authentication mode. By default, the system certificate is authenticated.

Type: CertificateVerifyMode

prop cipherSuitesV1_2

public mut prop cipherSuitesV1_2: Array<String>

Description: Represents the TLS 1.2-based cipher suite.

Type: Array<String>

Throws:

prop cipherSuitesV1_3

public mut prop cipherSuitesV1_3: Array<String>

Description: Represents the TLS 1.3-based cipher suite.

Type: Array<String>

Throws:

prop dhParameters

public mut prop dhParameters: ?DHParamters

Description: Specifies the DH key parameters of the server. The default value is None. By default, the parameter values automatically generated by OpenSSL are used.

Type: ?DHParamters

prop maxVersion

public mut prop maxVersion: TlsVersion

Description: Represents the latest TLS version supported.

Note:

If maxVersion is set but minVersion is not set, or if the set maxVersion is earlier than minVersion, TlsException is thrown during handshake.

Type: TlsVersion

prop minVersion

public mut prop minVersion: TlsVersion

Description: Represents the earliest TLS version supported.

Note:

If minVersion is set but maxVersion is not set, or if the set minVersion is later than maxVersion, TlsException is thrown during handshake.

Type: TlsVersion

prop securityLevel

public mut prop securityLevel: Int32

Description: Specifies the security level of the server. The default value is 2. The optional parameter value ranges from 0 to 5. For details about the parameter value, see the description of openssl-SSL_CTX_set_security_level. Description: Specifies the security level of the server. The default value is 2. The value ranges from 0 to 5. For details about the parameter description, see the description of openssl-SSL_CTX_set_security_level.

Type: Int32

Throws:

prop serverCertificate(Array<X509Certificate>, PrivateKey)

public mut prop serverCertificate: (Array<X509Certificate>, PrivateKey)

Description: Represents the server certificate and corresponding private key file.

Type: (Array<X509Certificate>, PrivateKey)

prop supportedAlpnProtocols

public mut prop supportedAlpnProtocols: Array<String>

Description: Negotiates the application layer protocol. If the client attempts to negotiate this protocol, the server selects the name of the protocol that intersects with the client. If the client does not attempt to negotiate the protocol, the configuration is ignored.

Type: Array<String>

Throws:

init(Array<X509Certificate>, PrivateKey)

public init(certChain: Array<X509Certificate>, certKey: PrivateKey)

Description: Constructs a TlsServerConfig object.

Parameters:

struct TlsSession

public struct TlsSession <: Equatable<TlsSession> & ToString & Hashable

Description: Indicates the established client session. This struct instance cannot be created by users, and its internal struct is invisible to users.

After 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.

Parent Type:

func hashCode()

public override func hashCode(): Int64

Description: Generates a session ID hash value.

Returns:

  • Int64: session ID hash value

func toString()

public override func toString(): String

Description: Generates a session ID string.

Returns:

operator func !=(TlsSession)

public override operator func !=(other: TlsSession)

Description: Checks whether two session IDs are different.

Parameters:

  • other: TlsSession: the other session object to be compared with

Returns:

  • Unit: If the two session objects are different, true is returned. Otherwise, false is returned.

operator func ==(TlsSession)

public override operator func ==(other: TlsSession)

Description: Checks whether two session IDs are the same.

Parameters:

  • other: TlsSession: the other session object to be compared with

Returns:

  • Unit: If the two session objects are the same, true is returned. Otherwise, false is returned.