SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
Inspect the negotiated TLS connection

Applications can inspect the protocol and cipher after a successful TLS handshake. These read-only functions use the same compiled cipher catalogue as the version and cipher controls. They allocate no memory and do not change the last I/O error or the configured selection.

/* ssl is a live connection whose handshake has succeeded. */
const SSL_CIPHER* cipher = SSL_get_current_cipher(ssl);
if (cipher)
{
int algorithmBits;
int secretBits = SSL_CIPHER_get_bits(cipher, &algorithmBits);
printf("%s %s (%d/%d bits)\n", SSL_get_version(ssl),
SSL_CIPHER_get_name(cipher), secretBits, algorithmBits);
}

The example requires <openssl/ssl.h> and <stdio.h>. It uses the adapter include directory and the existing standalone TLS sources; there is no additional source file or network dependency.

Interfaces

Interface Result
SSL_version(const SSL* ssl) int: TLS1_2_VERSION, TLS1_3_VERSION, or zero before wrapper handshake success
SSL_get_current_cipher(const SSL* ssl) Borrowed const SSL_CIPHER*, or NULL before wrapper handshake success
SSL_CIPHER_get_name(const SSL_CIPHER* cipher) Borrowed const char* containing the OpenSSL cipher name
SSL_CIPHER_standard_name(const SSL_CIPHER* cipher) Borrowed const char* containing the standard TLS name
SSL_CIPHER_get_version(const SSL_CIPHER* cipher) Borrowed const char*: the protocol version that introduced the cipher
SSL_CIPHER_get_bits(const SSL_CIPHER* cipher, int* algorithmBits) int secret-key bits; optionally writes algorithm-key bits
SSL_CIPHER_get_id(const SSL_CIPHER* cipher) uint32_t OpenSSL-style ID, 0x03000000 combined with the two-byte suite ID
SSL_CIPHER_get_protocol_id(const SSL_CIPHER* cipher) uint16_t TLS wire suite ID in host numeric form

SSL_get_cipher, SSL_get_cipher_name, SSL_get_cipher_bits and SSL_get_cipher_version are convenience macros over the current descriptor. Each evaluates its connection argument once. The opaque SSL_CIPHER type is distinct from EVP_CIPHER, which describes a cryptographic algorithm.

NULL SSL objects return NULL descriptors or numeric version zero. NULL cipher arguments produce "(NONE)" for string getters and zero for numeric getters. The int* algorithmBits argument is optional; it is left unchanged when the cipher is NULL. For current suites, the secret and algorithm bit counts are both 128 for AES-128, or both 256 for AES-256 and ChaCha20. These are symmetric key sizes, not a certificate key size or an overall security-strength rating.

All returned descriptors and strings are immutable library storage. Do not modify or free them. They remain valid after SSL/CTX destruction while the library stays loaded. Callers must still serialize access to a mutable SSL object; a descriptor may be inspected independently once obtained.

Availability and limits

The wrapper exposes negotiated information only after its handshake and peer policy checks succeed. Failed or incomplete handshakes have no current descriptor in this subset. OpenSSL may expose intermediate handshake state earlier; pending-cipher and handshake-state inspection APIs are not supplied. After an established connection closes or encounters a later I/O failure, these getters describe the completed handshake, not current connection health. With verification disabled, a descriptor does not establish peer identity.

The catalogue describes the nine modern choices listed in the controls guide. Compiled native DHE defaults also have descriptors, but their names remain rejected by the strict selection API. Introspection does not enable omitted features or expand the accepted cipher list. Cipher enumeration, NIDs, provider objects, description formatting and SSL_CIPHER_find are outside this subset.

References: current cipher and aliases, cipher properties, and negotiated version.