SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
Select TLS versions and ciphers

These controls let an application limit TLS negotiation before a connection's handshake starts. They use SharkSSL's existing protocol and cipher selection functions. The parser accepts explicit cipher names only; it does not interpret OpenSSL cipher-rule expressions.

Interfaces and lifetime

Scope Interfaces
Context protocol bounds SSL_CTX_set_min_proto_version, SSL_CTX_set_max_proto_version, SSL_CTX_get_min_proto_version, SSL_CTX_get_max_proto_version
Connection protocol bounds SSL_set_min_proto_version, SSL_set_max_proto_version, SSL_get_min_proto_version, SSL_get_max_proto_version
TLS 1.2 cipher names SSL_CTX_set_cipher_list, SSL_set_cipher_list
TLS 1.3 cipher names SSL_CTX_set_ciphersuites, SSL_set_ciphersuites
Configured preferences SSL_get_cipher_list(const SSL* ssl, int priority)

Setters take a required SSL_CTX* or SSL*, and return int: 1 for an accepted setting, 0 for a rejected call. Failed calls leave the previous setting intact. Protocol getters take a const SSL_CTX* or const SSL* and return the stored int bound. NULL objects are rejected by setters; getters return zero for NULL.

SSL_new copies the context's controls. Later context changes affect future connections only. Connection setters change that connection's copy and reject changes once handshake processing starts, including while waiting for BIO I/O or after a fatal handshake failure. Configure credentials before creating SSL objects, as required by the separate PEM contract. All mutable operations still require caller serialization.

Settings use fixed storage and allocate no memory. Cipher strings are parsed and copied as native identifiers, so the caller can release or change its string after the setter returns. The wrapper applies the complete configuration once before the first native handshake step. It checks the negotiated version and cipher again before reporting handshake success or releasing plaintext.

Protocol bounds

The int version argument accepts 0, TLS1_2_VERSION (0x0303) or TLS1_3_VERSION (0x0304). Zero is the default and means the lowest or highest version available in the native build. Getters retain zero for that setting; they do not return a negotiated version. Use SSL_get_version after success for the negotiated protocol name.

Older TLS/SSL versions, DTLS and unknown version numbers are rejected. A valid modern bound may name a version omitted from the native build. Crossed bounds may also be stored, allowing callers to set the two bounds in either order. If the final bounds have no usable intersection with the compiled protocols, the first handshake attempt fails with SSL_ERROR_SSL before producing output. No protocol is silently re-enabled to satisfy an impossible configuration.

A TLS 1.3-only server answers a legacy ClientHello that omits supported_versions with a fatal protocol_version alert before sending a ServerHello. This also applies when the client omits the entire extensions block. RFC 9846, Appendix E.2

A server with TLS 1.2 and TLS 1.3 enabled writes DOWNGRD followed by 0x01 into the last eight bytes of its ServerHello random when it automatically negotiates TLS 1.2. If the application explicitly caps the server connection at TLS 1.2, the server leaves those bytes random. A client that offered TLS 1.3 rejects either downgrade marker (0x00 or 0x01 after DOWNGRD) with illegal_parameter when it receives a TLS 1.2 ServerHello. TLS downgrade protection

Cipher names

To log a connection's configured ciphers, call SSL_get_cipher_list(ssl, i) starting at index zero and stop at NULL. This works immediately after SSL_new and after the handshake. It returns a borrowed, immutable const char* from the adapter's cipher table. A NULL connection, negative index or index past the last suite returns NULL.

The list starts with the configured TLS 1.3 suites, followed by the TLS 1.2 suites, in preference order within each group. It includes only suites compiled into this build. Protocol bounds affect negotiation while the getter continues to report the configured list. To identify the suite actually used by a successful handshake, call SSL_get_current_cipher.

The const char* names argument is a required NUL-terminated string containing exact names separated by colons. Names are case-sensitive. No whitespace, empty elements, commas, aliases, grouping, rule operators, security-level directives or IANA-style TLS 1.2 names are accepted. Duplicate names keep their first position. A NULL string fails.

TLS version Accepted names when their native features are enabled
TLS 1.2, ECDSA identity ECDHE-ECDSA-AES128-GCM-SHA256, ECDHE-ECDSA-AES256-GCM-SHA384, ECDHE-ECDSA-CHACHA20-POLY1305
TLS 1.2, RSA identity ECDHE-RSA-AES128-GCM-SHA256, ECDHE-RSA-AES256-GCM-SHA384, ECDHE-RSA-CHACHA20-POLY1305
TLS 1.3 TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256

An unknown, unsupported or compiled-out name rejects the complete call. This differs from OpenSSL's permissive handling of unknown names. DEFAULT, HIGH, ALL, !, +, - rules and @SECLEVEL expressions are deliberately outside this subset. A hyphen inside an exact listed cipher name is valid.

TLS 1.2 and TLS 1.3 setters replace independent lists. The untouched list keeps the native compiled defaults. An empty TLS 1.2 string fails and preserves its old list. An empty TLS 1.3 string succeeds and disables its suites. An empty cipher set for the highest enabled version fails handshake setup; it does not silently lower the protocol maximum. Set the maximum to TLS 1.2 explicitly when disabling the TLS 1.3 list in a dual build.

Native selection combines the effective lists into SHARKSSL_SELECT_CIPHERSUITE_LIST_DEPTH slots, default eight. Only suites within the final protocol bounds consume slots. Untouched native defaults use the native default path and do not require these slots. After either cipher list has been explicitly configured, an effective combined selection exceeding the native capacity fails before handshake output with SSL_ERROR_SSL. Setters can therefore succeed while the final combination is unusable. Narrow a list or protocol range, or configure a larger native capacity consistently. Lists are never truncated.

For example, the standard dual build has six TLS 1.2 and three TLS 1.3 defaults. Setting one TLS 1.3 suite retains the six TLS 1.2 defaults and fits seven slots. Explicitly setting all three TLS 1.3 suites while retaining those six defaults needs nine slots and exceeds the default capacity. Restricting that connection to TLS 1.3 uses only the three TLS 1.3 slots.

SHARKSSL_ENABLE_SELECT_CIPHERSUITE=0 makes cipher setters fail, including the empty TLS 1.3 setter. Version controls still work. Cipher names do not enable algorithms omitted at compilation. Legacy DHE suites, if enabled natively, remain in an untouched native default list but cannot be named by this parser. Native certificate selection and server preference rules still apply. The wrapper preserves order within each explicit list; it does not add OpenSSL options for changing server/client preference or a security-level framework.

References: protocol bounds, cipher selection, and OpenSSL's effective-version downgrade check.