|
SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
|
The SharkSSL API.
Use the groups below to find configuration, connection processing, session management, and certificate conversion APIs.
Modules | |
| SharkSsl Configuration (macros) | |
| Add/remove SharkSSL features and/or optimize for speed versus size. | |
| Core API | |
| The transport agnostic SharkSSL API. | |
| SSL Session Management | |
| Reduce the work needed to reconnect to an authenticated peer. | |
| Certificate Management API | |
| Optional high level certificate management API. | |
| SharkSsl info and status | |
| SharkSsl information classes and return values. | |
| Post-quantum cryptography | |
| Hybrid ML-KEM TLS key agreement and ML-DSA-65 signature verification. | |
Data Structures | |
| struct | SharkSslCertVerifyHook |
| Application-owned policy for a presented peer chain, called synchronously after native chain checks and before the handshake advances. More... | |
Macros | |
| #define | SharkSsl_setIntf(o, sharkSslIntf) (o)->intf=sharkSslIntf |
| #define | SharkSsl_getIntf(o) (o)->intf |
| #define | SharkSslCon_terminate(o) SharkSsl_terminateCon(0, o) |
| The SharkSslCon object must be reclaimed when you close the network connection. More... | |
| #define | SharkSsl_setCAList(o, caList) SharkSsl_setCAListEx((o), (caList), 0) |
| Install an application-trusted CA list without validating its allocation extent. More... | |
| #define | SHARKSSL_SET_FAVOR_RSA 1 |
| Enable RSA preference in SharkSslCon_favorRSA. More... | |
| #define | SHARKSSL_CLEAR_FAVOR_RSA 0 |
| Disable RSA preference in SharkSslCon_favorRSA. More... | |
| #define | SHARKSSL_PQC_ALLOW_X25519 1 |
| Permit compiled PQC groups and classical X25519 when available. More... | |
| #define | SHARKSSL_PQC_REQUIRE_HYBRID 2 |
| Permit only compiled hybrid classical/ML-KEM groups. More... | |
| #define | SHARKSSL_PQC_REQUIRE_PQC 3 |
| Permit compiled hybrid and standalone ML-KEM groups, with no classical-only exchange. More... | |
| #define | SharkSslCon_requestClientCert(o, caList) SharkSslCon_requestClientCertEx((o), (caList), 0) |
| Request client authentication with an application-trusted CA list. More... | |
| #define | SharkSslCon_setCertificateAuthorities(o, caList) SharkSslCon_setCertificateAuthoritiesEx((o), (caList), 0) |
| Configure the extension with an application-trusted CA list. More... | |
| #define | SHARKSSL_ALPN_SELECT 1 |
| Select the returned offered protocol. More... | |
| #define | SHARKSSL_ALPN_NOACK 0 |
| Continue without an ALPN selection. More... | |
| #define | SHARKSSL_ALPN_FATAL (-1) |
| Reject with no_application_protocol. More... | |
Typedefs | |
| typedef struct SharkSslCertVerifyHook | SharkSslCertVerifyHook |
| Application-owned policy for a presented peer chain, called synchronously after native chain checks and before the handshake advances. More... | |
| typedef int(* | ALPNFunction) (SharkSslCon *, const char *, void *) |
| typedef int(* | ALPNFunctionEx) (SharkSslCon *o, const U8 **selected, U8 *selectedLen, const U8 *offered, U16 offeredLen, void *pvoid) |
| Select a protocol from a validated complete binary ALPN list. More... | |
Functions | |
| SHARKSSL_API void | SharkSsl_constructor (SharkSsl *o, SharkSsl_Role role, U16 cacheSize, U16 inBufStartSize, U16 outBufSize) |
| A SharkSsl object is the coordinator for managing SharkSslCon objects. More... | |
| SHARKSSL_API void | SharkSsl_destructor (SharkSsl *o) |
| Close the SharkSsl object. More... | |
| SharkSslCon * | SharkSsl_createCon (SharkSsl *o) |
| Create a SharkSslCon object. More... | |
| void | SharkSsl_terminateCon (const SharkSsl *o, SharkSslCon *con) |
| Terminate a SharkSslCon object created by function SharkSsl_createCon. More... | |
| SHARKSSL_API U16 | SharkSsl_getCacheSize (SharkSsl *o) |
| Returns the SharkSsl session cache size. More... | |
| SHARKSSL_API U16 | SharkSslCon_getCiphersuite (SharkSslCon *o) |
| Returns the active session's chiper suite. More... | |
| SHARKSSL_API U8 | SharkSslCon_getProtocol (SharkSslCon *o) |
| Returns the active session's protocol version. More... | |
| SHARKSSL_API U8 | SharkSslCon_setSNI (SharkSslCon *o, const char *name, U16 length) |
| set Server Name Indication for TLS client connections More... | |
| U8 | SharkSslCon_certificateRequested (SharkSslCon *o) |
| Returns TRUE if the server requested a certificate from the client to verify that the client's identity (authentication) More... | |
| SHARKSSL_API U8 | SharkSslCon_setCertVerifyHook (SharkSslCon *o, const SharkSslCertVerifyHook *hook) |
| Install a certificate policy before the first I/O. More... | |
| SHARKSSL_API SharkSslCertInfo * | SharkSslCon_getCertInfo (SharkSslCon *o) |
| Returns the peer's certificate if the handshaking has completed. More... | |
| SHARKSSL_API U8 | SharkSslCon_receivedEmptyCertificate (SharkSslCon *o) |
| Test a completed server connection's retained empty-certificate state. More... | |
| SHARKSSL_API U8 | SharkSsl_addCertificate (SharkSsl *o, SharkSslCert cert) |
| Add a trusted, generated certificate to the SharkSsl object. More... | |
| SHARKSSL_API U8 | SharkSsl_addCertificateEx (SharkSsl *o, SharkSslCert cert, U32 certLen) |
| Add a certificate blob after checking its actual size, chain boundaries, key fields, and leaf DER structure. More... | |
| SHARKSSL_API U8 | SharkSsl_addCertificatePSA (SharkSsl *o, SharkSslCert cert, psa_key_id_t psaKey) |
| Add an RSA, EC, or EdDSA certificate with a provider-owned private signing key. More... | |
| SHARKSSL_API U8 | SharkSsl_addCertificatePSAEx (SharkSsl *o, SharkSslCert cert, U32 certLen, psa_key_id_t psaKey) |
| Length-checked counterpart of SharkSsl_addCertificatePSA. More... | |
| SHARKSSL_API U8 | SharkSslCon_selectCertificatePSA (SharkSslCon *o, SharkSslCert cert) |
| Select one PSA certificate already registered on this connection's SharkSsl object. More... | |
| SHARKSSL_API U8 | SharkSsl_setCAListEx (SharkSsl *o, SharkSslCAList caList, U32 caListLen) |
| Set a Certificate Authority (CA) list so the SharkSSL object can perform certificate validation on the peer's certificate. More... | |
| SHARKSSL_API U8 | SharkSslCon_trustedCA (SharkSslCon *o) |
| Returns TRUE if the certificate is valid and is signed with a root certificate trusted by SharkSSL. More... | |
| U8 | SharkSslCon_isCAListEmpty (SharkSslCon *o) |
| Check whether the connection owner has no CA-list pointer. More... | |
| U8 | SharkSslCon_favorRSA (SharkSslCon *o, U8 flag) |
| Configures TLS 1.2 cipher-suite selection to favor RSA-authenticated suites when both RSA and ECDSA certificates are available. More... | |
| U8 | SharkSslCon_selectProtocol (SharkSslCon *o, U8 protocol) |
| Select an enabled TLS protocol before negotiation or resumption. More... | |
| SHARKSSL_API U8 | SharkSslCon_requestClientCertEx (SharkSslCon *o, const void *caList, U32 caListLen) |
| Request client-certificate authentication. More... | |
| SHARKSSL_API U8 | SharkSslCon_setCertificateAuthoritiesEx (SharkSslCon *o, const void *caList, U32 caListLen) |
| Configure the TLS 1.3 Certificate Authorities extension specified in RFC 9846, Section 4.2.4. More... | |
| SHARKSSL_API U8 | SharkSslCon_setALPNProtocols (SharkSslCon *o, const char *protList) |
| This function is used by client solutions to specify a list of application layer protocols according to RFC 7301 (ALPN). More... | |
| SHARKSSL_API U8 | SharkSslCon_setALPNProtocolsEx (SharkSslCon *o, const U8 *protList, U16 protListLen) |
| Set a borrowed binary ALPN list before the client handshake starts. More... | |
| SHARKSSL_API const char * | SharkSslCon_getALPNProtocol (SharkSslCon *o) |
| This function is used by client solutions to return the application layer protocol selected by the server among the ones specified through SharkSslCon_setALPNProtocols. More... | |
| SHARKSSL_API U8 | SharkSslCon_setALPNFunction (SharkSslCon *o, ALPNFunction func, void *pvoid) |
| Install a server-side application-protocol selection callback. More... | |
| SHARKSSL_API U8 | SharkSslCon_setALPNFunctionEx (SharkSslCon *o, ALPNFunctionEx func, void *pvoid) |
| Install the binary ALPN server selector, replacing the legacy selector. More... | |
| SHARKSSL_API const U8 * | SharkSslCon_getALPNProtocolEx (SharkSslCon *o, U8 *protocolLen) |
| Inspect the selected ALPN bytes without assuming string termination. More... | |
| SHARKSSL_API U8 | SharkSslCon_selectCiphersuite (SharkSslCon *o, U16 cipherSuite) |
| This function enables you to limit the number of ciphers at runtime. More... | |
| SHARKSSL_API U8 | SharkSslCon_clearCiphersuiteSelection (SharkSslCon *o) |
| Clears the selection, thus enabling all ciphers. More... | |
| SHARKSSL_API U8 | SharkSslCon_renegotiate (SharkSslCon *o) |
| This function enables you to renegotiate an already established SSL/TLS connection. More... | |
| SHARKSSL_API SharkSslConTrust | SharkSslCon_trusted (SharkSslCon *o, const char *name, SharkSslCertInfo **cPtr) |
| Return the peer's trust status and certificate. More... | |
| SHARKSSL_API void | SubjectAltNameEnumerator_constructor (SubjectAltNameEnumerator *o, U8 *ptr, SharkSslSANLen len) |
| Initialize a cursor over encoded subject alternative names. More... | |
| SHARKSSL_API void | SubjectAltNameEnumerator_getElement (SubjectAltNameEnumerator *o, SubjectAltName *s) |
| Return the next SAN and advance the cursor. More... | |
| SHARKSSL_API void * | sharkssl_mallocObject (size_t size) |
| Allocate aligned storage for SharkSSL C++ objects. More... | |
| SHARKSSL_API void | sharkssl_freeObject (void *object) |
| Release storage obtained from sharkssl_mallocObject. More... | |
| SHARKSSL_API SharkSslKey | sharkssl_PEM_extractPublicKey_ext (const char *certPEM, U8 *keyType) |
| Extract a SharkSSL key allocation and report its internal key type. More... | |
| SHARKSSL_API U32 | sharkssl_B64Decode (U8 *outStr, U32 outStrSize, const char *b64beg, const char *b64end) |
| Decode Base64 alphabet characters from a bounded text range. More... | |
| #define SHARKSSL_ALPN_FATAL (-1) |
Reject with no_application_protocol.
| #define SHARKSSL_ALPN_NOACK 0 |
Continue without an ALPN selection.
| #define SHARKSSL_ALPN_SELECT 1 |
Select the returned offered protocol.
| #define SHARKSSL_CLEAR_FAVOR_RSA 0 |
Disable RSA preference in SharkSslCon_favorRSA.
| #define SharkSsl_getIntf | ( | o | ) | (o)->intf |
| #define SHARKSSL_PQC_ALLOW_X25519 1 |
Permit compiled PQC groups and classical X25519 when available.
| #define SHARKSSL_PQC_REQUIRE_HYBRID 2 |
Permit only compiled hybrid classical/ML-KEM groups.
| #define SHARKSSL_PQC_REQUIRE_PQC 3 |
Permit compiled hybrid and standalone ML-KEM groups, with no classical-only exchange.
| #define SHARKSSL_SET_FAVOR_RSA 1 |
Enable RSA preference in SharkSslCon_favorRSA.
| #define SharkSsl_setCAList | ( | o, | |
| caList | |||
| ) | SharkSsl_setCAListEx((o), (caList), 0) |
Install an application-trusted CA list without validating its allocation extent.
| #define SharkSsl_setIntf | ( | o, | |
| sharkSslIntf | |||
| ) | (o)->intf=sharkSslIntf |
| #define SharkSslCon_requestClientCert | ( | o, | |
| caList | |||
| ) | SharkSslCon_requestClientCertEx((o), (caList), 0) |
Request client authentication with an application-trusted CA list.
| #define SharkSslCon_setCertificateAuthorities | ( | o, | |
| caList | |||
| ) | SharkSslCon_setCertificateAuthoritiesEx((o), (caList), 0) |
Configure the extension with an application-trusted CA list.
| #define SharkSslCon_terminate | ( | o | ) | SharkSsl_terminateCon(0, o) |
The SharkSslCon object must be reclaimed when you close the network connection.
| typedef int(* ALPNFunction) (SharkSslCon *, const char *, void *) |
| typedef int(* ALPNFunctionEx) (SharkSslCon *o, const U8 **selected, U8 *selectedLen, const U8 *offered, U16 offeredLen, void *pvoid) |
Select a protocol from a validated complete binary ALPN list.
Called synchronously from decrypt only when the peer offers ALPN. Input is temporary and must not be retained. Set selected/selectedLen to a nonempty offered protocol; it may be in the input or other storage valid through callback return. The library checks membership and copies it. Return SHARKSSL_ALPN_SELECT, SHARKSSL_ALPN_NOACK, or SHARKSSL_ALPN_FATAL. Do not recursively process I/O or change ALPN settings from this callback.
| o | SharkSslCon*; connection being processed. |
| selected | const U8**; required output pointer to the chosen bytes. |
| selectedLen | U8*; required output length, 1..255 on selection. |
| offered | const U8*; borrowed validated length-prefixed list. |
| offeredLen | U16; number of bytes in offered, excluding a list header. |
| pvoid | void*; borrowed argument from the setter. |
| typedef struct SharkSslCertVerifyHook SharkSslCertVerifyHook |
Application-owned policy for a presented peer chain, called synchronously after native chain checks and before the handshake advances.
A missing trust anchor is reported in trustedCA. Returning zero sends a fatal bad_certificate alert. Returning nonzero continues the handshake with the original CA trust result. Signature and subsequent TLS checks still apply. An empty Certificate message or a resumed handshake without a Certificate message does not invoke this hook.
| U8 SharkSsl_addCertificate | ( | SharkSsl * | o, |
| SharkSslCert | cert | ||
| ) |
Add a trusted, generated certificate to the SharkSsl object.
A SharkSsl object in server mode is required to have at least one certificate.
This pointer-only API cannot determine the size of a malformed or truncated blob. Use SharkSsl_addCertificateEx for data loaded from a file or another potentially untrusted source.
Note: You must install the certificate(s) before using the SharkSsl object – i.e. before calling SharkSsl_createCon.
| o | SharkSsl *; required initialized object owned by the application. |
| cert | SharkSslCert; required certificate/identity blob in SharkSSL encoding. Borrowed for the object and connection lifetimes; install before creating connections. |
| SHARKSSL_API U8 SharkSsl_addCertificateEx | ( | SharkSsl * | o, |
| SharkSslCert | cert, | ||
| U32 | certLen | ||
| ) |
Add a certificate blob after checking its actual size, chain boundaries, key fields, and leaf DER structure.
This does not verify certificate signatures or chain trust. The caller retains ownership of cert and must keep it alive for the lifetime of the SharkSsl object.
| o | SharkSsl *; required initialized object with no live connections. |
| cert | SharkSslCert; required SharkSSL certificate/identity blob, borrowed for the object and connection lifetimes. |
| certLen | U32; actual number of bytes available at cert, greater than 0. |
| U8 SharkSsl_addCertificatePSA | ( | SharkSsl * | o, |
| SharkSslCert | cert, | ||
| psa_key_id_t | psaKey | ||
| ) |
Add an RSA, EC, or EdDSA certificate with a provider-owned private signing key.
This pointer-only API requires a trusted, generated certificate blob. Use SharkSsl_addCertificatePSAEx when the blob may be malformed or truncated. The caller retains ownership of psaKey and must keep it valid until the SharkSsl object and all its connections are destroyed. The key must match the certificate and permit signing with the negotiated algorithm. With SHARKSSL_PSA_CONSUMER_STRICT_IDENTITY=1, every local certificate must be added through this function with a public-only certificate blob.
| o | SharkSsl *; required initialized object owned by the application. |
| cert | SharkSslCert; required borrowed certificate matching psaKey. The strict PSA identity profile requires a public-only blob. |
| psaKey | psa_key_id_t; borrowed non-null private signing handle, kept valid until the SharkSsl object and all its connections are destroyed. |
| SHARKSSL_API U8 SharkSsl_addCertificatePSAEx | ( | SharkSsl * | o, |
| SharkSslCert | cert, | ||
| U32 | certLen, | ||
| psa_key_id_t | psaKey | ||
| ) |
Length-checked counterpart of SharkSsl_addCertificatePSA.
Applies the blob checks described by SharkSsl_addCertificateEx.
| o | SharkSsl *; required initialized object with no live connections. |
| cert | SharkSslCert; required SharkSSL certificate blob matching psaKey, borrowed for the object and connection lifetimes. The strict PSA identity profile requires a public-only blob. |
| certLen | U32; actual number of bytes available at cert, greater than 0. |
| psaKey | psa_key_id_t; required provider-owned private signing key handle. The caller keeps it valid until the SharkSsl object and all its connections are destroyed. It must permit the negotiated signing algorithm. |
| U32 sharkssl_B64Decode | ( | U8 * | outStr, |
| U32 | outStrSize, | ||
| const char * | b64beg, | ||
| const char * | b64end | ||
| ) |
Decode Base64 alphabet characters from a bounded text range.
Non-alphabet characters, including padding and whitespace, are skipped. This is not a strict Base64 validator.
| outStr | U8 *; Required writable caller-owned destination. |
| outStrSize | U32; Destination capacity in bytes; decoding stops writing when full. |
| b64beg | const char *; Required start of readable input range. |
| b64end | const char *; Required one-past-end pointer in the same input buffer. |
| SHARKSSL_API void SharkSsl_constructor | ( | SharkSsl * | o, |
| SharkSsl_Role | role, | ||
| U16 | cacheSize, | ||
| U16 | inBufStartSize, | ||
| U16 | outBufSize | ||
| ) |
A SharkSsl object is the coordinator for managing SharkSslCon objects.
You must at a minimum create one SharkSsl object. A more advanced configuration may include several SharkSsl objects. For example, a system that includes both a client and server SSL stack must create and initialize two SharkSsl objects.
| o | Uninitialized data of size sizeof(SharkSsl). |
| role | Select client or server SSL mode. See SharkSsl_Role for details. |
| cacheSize | The session resumption cache size. Setting this to zero disables the cache management code. See SSL Session Management for details. |
| inBufStartSize | Initial input-buffer capacity, in bytes, for each SharkSslCon created from this object. The value does not include the private record headroom allocated by SharkSSL. For a client, the buffer must hold the complete ClientHello selected by the compiled features and the connection options, such as SNI and ALPN. ClientHello construction checks the complete size before writing and does not grow this buffer. For a server, SharkSSL raises the initial allocation when necessary to accommodate the largest installed certificate and the compiled key-exchange requirements. Later received records and fragmented handshake messages may grow the input buffer when SHARKSSL_DISABLE_INBUF_EXPANSION is zero. |
| outBufSize | Output-buffer capacity, in bytes, for each SharkSslCon. The buffer must hold the compiled internal handshake state as well as the handshake message, cipher overhead, and temporary data required by the selected protocol, ciphers, certificates, and connection options. |
There is no configuration-independent minimum for either buffer. If an allocation fails, or a required handshake message and its scratch space do not fit, the handshake API returns SharkSslCon_AllocationError. With SHARKSSL_DISABLE_INBUF_EXPANSION enabled, input which requires a larger receive buffer follows the same controlled error path. Terminate the connection after this result.
| SharkSslCon * SharkSsl_createCon | ( | SharkSsl * | o | ) |
Create a SharkSslCon object.
You must create one SharkSslCon object for each active network connection that requires encryption.
The following code snippet is from the example programs.
| o | SharkSsl *; required initialized object owned by the application. |
| void SharkSsl_destructor | ( | SharkSsl * | o | ) |
Close the SharkSsl object.
Terminate every connection and release application-held session references first.
Closing a SharkSsl object is not common in embedded devices. You would normally keep the SharkSsl object for the lifetime of the application. You must make sure all SharkSslCon objects are terminated by calling SharkSslCon_terminate for each active connection prior to calling the SharkSsl_destructor.
This releases internal resources, not the caller-owned SharkSsl storage or borrowed certificate/key material.
| o | SharkSsl *; required initialized object owned by the application. |
| void sharkssl_freeObject | ( | void * | object | ) |
Release storage obtained from sharkssl_mallocObject.
Run any required object destructor before freeing the storage.
| object | void *; Owned allocation to release, or NULL for no action. Do not pass other allocations. |
| U16 SharkSsl_getCacheSize | ( | SharkSsl * | o | ) |
Returns the SharkSsl session cache size.
| o | SharkSsl *; required initialized object owned by the application. |
| void * sharkssl_mallocObject | ( | size_t | size | ) |
Allocate aligned storage for SharkSSL C++ objects.
The caller owns the allocation and must release it with sharkssl_freeObject, not baFree. This helper does not construct an object.
| size | size_t; Requested object-storage size in bytes. |
| SharkSslKey sharkssl_PEM_extractPublicKey_ext | ( | const char * | certPEM, |
| U8 * | keyType | ||
| ) |
Extract a SharkSSL key allocation and report its internal key type.
Requires SHARKSSL_ENABLE_PEM_API. Certificate parsing does not establish trust. Key input is accepted by the PEM key parser and can preserve private key material.
| certPEM | const char *; Required NUL-terminated PEM certificate or supported key text, borrowed for the call. |
| keyType | U8 *; Required output for the internal SharkSSL key-type discriminator; meaningful only on success. |
| SHARKSSL_API U8 SharkSsl_setCAListEx | ( | SharkSsl * | o, |
| SharkSslCAList | caList, | ||
| U32 | caListLen | ||
| ) |
Set a Certificate Authority (CA) list so the SharkSSL object can perform certificate validation on the peer's certificate.
| o | the SharkSsl object. |
| caList | list created by calling SharkSslCertStore_assemble or by using the command line tool SharkSSLParseCAList. |
| caListLen | allocation length when caList is a serialized index list created by SharkSSLParseCAList. A nonzero length validates the complete list before installing it. Lists created by SharkSslCertStore_assemble contain pointers and must use zero. Zero preserves the trusted-data behavior and requires the application to guarantee the list's lifetime and extent. |
The CA list must include all root certificates required for your system. It must remain valid and unchanged while the SharkSsl object uses it. Replacing it requires that all connections have been terminated and that the caller serialize the call with connection creation and session use. A successful call invalidates cached sessions established with the previous list; externally held session handles remain releasable but cannot resume.
The example program certcheck.c includes code that shows how to perform complete certificate validation of the connected servers.
| void SharkSsl_terminateCon | ( | const SharkSsl * | o, |
| SharkSslCon * | con | ||
| ) |
Terminate a SharkSslCon object created by function SharkSsl_createCon.
When called from an ALPN callback during SharkSslCon_decrypt, the connection is reclaimed when the outer decrypt call returns. The callback must stop using the connection after requesting termination.
| o | the SharkSsl object. Setting this parameter to NULL is the same as calling macro SharkSslCon_terminate. |
| con | the SharkSslCon object to reclaim. |
Code snippet from the example code: sessioncache.c
| U8 SharkSslCon_certificateRequested | ( | SharkSslCon * | o | ) |
Returns TRUE if the server requested a certificate from the client to verify that the client's identity (authentication)
| o | SharkSslCon *; required live connection created by SharkSsl_createCon. The caller serializes access. |
| U8 SharkSslCon_clearCiphersuiteSelection | ( | SharkSslCon * | o | ) |
Clears the selection, thus enabling all ciphers.
| o | SharkSslCon *; connection to reset before the initial handshake selection or during requested renegotiation. |
| U8 SharkSslCon_favorRSA | ( | SharkSslCon * | o, |
| U8 | flag | ||
| ) |
Configures TLS 1.2 cipher-suite selection to favor RSA-authenticated suites when both RSA and ECDSA certificates are available.
This setting does not affect TLS 1.3 certificate selection.
| o | connection to configure before the initial or renegotiation handshake starts. |
| flag | SHARKSSL_SET_FAVOR_RSA or SHARKSSL_CLEAR_FAVOR_RSA. |
| SHARKSSL_API const char * SharkSslCon_getALPNProtocol | ( | SharkSslCon * | o | ) |
This function is used by client solutions to return the application layer protocol selected by the server among the ones specified through SharkSslCon_setALPNProtocols.
This function has to be called after the handshake has been initiated.
| o | the SharkSslCon object returned by function SharkSsl_createCon. |
| SHARKSSL_API const U8 * SharkSslCon_getALPNProtocolEx | ( | SharkSslCon * | o, |
| U8 * | protocolLen | ||
| ) |
Inspect the selected ALPN bytes without assuming string termination.
For clients this supports both list setters and borrows the configured list. For servers it supports SharkSslCon_setALPNFunctionEx only, using library storage valid until the next handshake, setting replacement or destruction. A selection during handshake processing does not establish peer identity or handshake completion. The legacy server selector has no retained result.
| o | SharkSslCon*; connection, or NULL for no selection. |
| protocolLen | U8*; required output, set to zero when none is selected. |
| SharkSslCertInfo * SharkSslCon_getCertInfo | ( | SharkSslCon * | o | ) |
Returns the peer's certificate if the handshaking has completed.
The certificate is available at any time.
| o | SharkSslCon *; connection to inspect, or NULL. |
| U16 SharkSslCon_getCiphersuite | ( | SharkSslCon * | o | ) |
Returns the active session's chiper suite.
| o | SharkSslCon *; required live connection created by SharkSsl_createCon. The caller serializes access. |
| U8 SharkSslCon_getProtocol | ( | SharkSslCon * | o | ) |
Returns the active session's protocol version.
| o | SharkSslCon *; required live connection created by SharkSsl_createCon. The caller serializes access. |
| U8 SharkSslCon_isCAListEmpty | ( | SharkSslCon * | o | ) |
Check whether the connection owner has no CA-list pointer.
| o | SharkSslCon *; Required connection with a valid owning SharkSsl object. |
| SHARKSSL_API U8 SharkSslCon_receivedEmptyCertificate | ( | SharkSslCon * | o | ) |
Test a completed server connection's retained empty-certificate state.
Use this when optional client authentication must distinguish an absent certificate from unavailable retained certificate information. A NULL result from SharkSslCon_getCertInfo alone does not distinguish those conditions. This read-only query does not establish certificate trust or authorization. It reports retained native state, not notification of a new exchange.
| o | The connection, or NULL. |
| SHARKSSL_API U8 SharkSslCon_renegotiate | ( | SharkSslCon * | o | ) |
This function enables you to renegotiate an already established SSL/TLS connection.
Renegotiation is also known as rehandshake. The function informs the SharkSSL state machine for the active connection that you wish to renegotiate the connection. The actual renegotiation is initiated and performed the next time you call SharkSslCon_decrypt.
The function is typically used in combination with SharkSslCon_requestClientCert, when requesting client SSL certificate authentication on an existing connection. The function can also be used in combination with SharkSslCon_selectCiphersuite, to force a change in the cipher being used.
| o | the SharkSslCon object returned by function SharkSsl_createCon. |
| SHARKSSL_API U8 SharkSslCon_requestClientCertEx | ( | SharkSslCon * | o, |
| const void * | caList, | ||
| U32 | caListLen | ||
| ) |
Request client-certificate authentication.
The CA list specifies the authorities accepted by the server when validating the client certificate.
The function must be called before the initial handshake starts or just after calling SharkSslCon_renegotiate. Calling it after renegotiation lets an existing TLS 1.2 session request client authentication. It also initiates TLS 1.3 post-handshake authentication when that feature is enabled. A connection-specific CA list causes session resumption to fall back to a full handshake so the client certificate is checked against that list.
| o | the SharkSslCon object returned by SharkSsl_createCon. |
| caList | a CA list created by SharkSslCertStore_assemble or the SharkSSLParseCAList command-line tool. The list may be NULL when no CA list is supplied. |
| caListLen | allocation length when caList is a serialized index list created by SharkSSLParseCAList. A nonzero length validates the complete list before accepting the request. Lists created by SharkSslCertStore_assemble contain pointers and must use zero. Zero requires application-trusted data. |
| U8 SharkSslCon_selectCertificatePSA | ( | SharkSslCon * | o, |
| SharkSslCert | cert | ||
| ) |
Select one PSA certificate already registered on this connection's SharkSsl object.
Call this before handshake processing. The certificate and its PSA signing key remain owned by the caller for the existing SharkSsl lifetime. Passing NULL restores automatic certificate selection. Returns TRUE on success and FALSE if the certificate is not registered, has no PSA signing key, or the connection has started processing records.
| o | SharkSslCon *; required live connection created by SharkSsl_createCon. The caller serializes access. |
| cert | SharkSslCert; one PSA identity already registered on the parent SharkSsl, or NULL to restore automatic selection. |
| SHARKSSL_API U8 SharkSslCon_selectCiphersuite | ( | SharkSslCon * | o, |
| U16 | cipherSuite | ||
| ) |
This function enables you to limit the number of ciphers at runtime.
Cipher suites can be enabled/disabled at compile time, but your application may require that you also allow only specific ciphers at runtime. By default, all ciphers enabled at compile time can be used by SharkSSL. Calling this function disables the use of all ciphers except the selected cipher. You can call this function up to N times and re-enable N ciphers. N is by default set to 8 at compile time. You can change the N value by setting macro SHARKSSL_SELECT_CIPHERSUITE_LIST_DEPTH.
The function must be called before the initial handshake has completed or just after calling SharkSslCon_renegotiate. Calling SharkSslCon_selectCiphersuite and then SharkSslCon_renegotiate enables an existing session to change cipher.
Example:
SharkSslCon_selectCiphersuite(myCon, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384)
| o | the SharkSslCon object returned by function SharkSsl_createCon. |
| cipherSuite | is one of the supported ciphers enabled at compile time. |
| U8 SharkSslCon_selectProtocol | ( | SharkSslCon * | o, |
| U8 | protocol | ||
| ) |
Select an enabled TLS protocol before negotiation or resumption.
Select the protocol before configuring dependent cipher suites; incompatible selected suites are removed.
| o | SharkSslCon *; Required connection; call before client ClientHello, or no later than receipt of server-side ClientHello, and before assigning a resumption session. |
| protocol | U8; Enabled SHARKSSL_PROTOCOL_TLS_1_2 or SHARKSSL_PROTOCOL_TLS_1_3 selector. |
| U8 SharkSslCon_setALPNFunction | ( | SharkSslCon * | o, |
| ALPNFunction | func, | ||
| void * | pvoid | ||
| ) |
Install a server-side application-protocol selection callback.
Requires server ALPN support. The offered protocol string is temporary and must not be retained.
| o | SharkSslCon *; Required server connection, no later than the ServerHello state. |
| func | ALPNFunction; ALPNFunction callback, or NULL to remove it. Called synchronously with connection, offered NUL-terminated protocol and pvoid; return nonzero to select or 0 to continue. A NULL protocol reports no selection; return nonzero there to permit no negotiated ALPN, or 0 to reject the handshake. |
| pvoid | void *; Optional caller-owned callback context, retained for negotiation. |
| SHARKSSL_API U8 SharkSslCon_setALPNFunctionEx | ( | SharkSslCon * | o, |
| ALPNFunctionEx | func, | ||
| void * | pvoid | ||
| ) |
Install the binary ALPN server selector, replacing the legacy selector.
The existing SharkSslCon_setALPNFunction replaces this selector in turn. Only this new path allocates persistent selected-protocol storage, at most 256 bytes; the legacy callback's allocation behavior is unchanged.
| o | SharkSslCon*; required server connection before handshake processing, outside decrypt callbacks. |
| func | ALPNFunctionEx; callback, or NULL to remove the selector. |
| pvoid | void*; optional borrowed callback argument, alive while used. |
| SHARKSSL_API U8 SharkSslCon_setALPNProtocols | ( | SharkSslCon * | o, |
| const char * | protList | ||
| ) |
This function is used by client solutions to specify a list of application layer protocols according to RFC 7301 (ALPN).
It must be called before the initial handshake has started.
| o | the SharkSslCon object returned by function SharkSsl_createCon. |
| protList | a comma-separated list of protocol names, or NULL to clear the currently configured list. Each protocol name must contain from 1 to 255 bytes. Leading, trailing, and consecutive commas are not permitted. The complete string must not exceed 65532 bytes. The string is not copied and must therefore remain valid and unmodified for as long as it may be used by the connection, including calls to SharkSslCon_getALPNProtocol (e.g., a constant string stored in ROM). |
| SHARKSSL_API U8 SharkSslCon_setALPNProtocolsEx | ( | SharkSslCon * | o, |
| const U8 * | protList, | ||
| U16 | protListLen | ||
| ) |
Set a borrowed binary ALPN list before the client handshake starts.
Each entry is a nonzero U8 length followed by that many arbitrary bytes. This replaces the string-list setting; neither interface copies its list. Failed calls preserve the previous setting.
| o | SharkSslCon*; required client connection, outside decrypt callbacks. |
| protList | const U8*; required for nonzero length, borrowed and unchanged until connection destruction or replacement before the handshake. |
| protListLen | U16; byte length, 2..65533, or zero to clear the setting. Complete ClientHello size remains subject to native buffer limits. |
| SHARKSSL_API U8 SharkSslCon_setCertificateAuthoritiesEx | ( | SharkSslCon * | o, |
| const void * | caList, | ||
| U32 | caListLen | ||
| ) |
Configure the TLS 1.3 Certificate Authorities extension specified in RFC 9846, Section 4.2.4.
The function must be called before the initial handshake starts.
| o | the SharkSslCon object returned by SharkSsl_createCon. |
| caList | a CA list created by SharkSslCertStore_assemble or the SharkSSLParseCAList command-line tool. For this connection it overrides the list installed with SharkSsl_setCAList. |
| caListLen | allocation length when caList is a serialized index list created by SharkSSLParseCAList. A nonzero length validates the complete list before accepting it. Lists created by SharkSslCertStore_assemble contain pointers and must use zero. Zero requires application-trusted data. |
| SHARKSSL_API U8 SharkSslCon_setCertVerifyHook | ( | SharkSslCon * | o, |
| const SharkSslCertVerifyHook * | hook | ||
| ) |
Install a certificate policy before the first I/O.
Requires SHARKSSL_ENABLE_CERT_VERIFY_HOOK.
| o | Connection to configure. |
| hook | Borrowed hook, or NULL to remove it. Keep both the hook and its argument alive until replacement or connection destruction. |
| U8 SharkSslCon_setSNI | ( | SharkSslCon * | o, |
| const char * | name, | ||
| U16 | length | ||
| ) |
set Server Name Indication for TLS client connections
| o | SharkSslCon *; required live connection created by SharkSsl_createCon. The caller serializes access. |
| name | const char *; borrowed hostname bytes, required when length is nonzero. Keep them alive until ClientHello generation consumes them. |
| length | U16; hostname length in bytes, at most 64; zero clears the name. No NUL terminator is counted. |
| SHARKSSL_API SharkSslConTrust SharkSslCon_trusted | ( | SharkSslCon * | o, |
| const char * | name, | ||
| SharkSslCertInfo ** | cPtr | ||
| ) |
Return the peer's trust status and certificate.
This function extends SharkSslCon_trustedCA with reference-name and optional certificate-date checks. It accepts DNS names and canonical dotted-decimal IPv4 addresses; an IP address requires an iPAddress SAN.
| o | the SharkSslCon object. |
| name | the NUL-terminated ASCII reference name used for the connection. Reject embedded NULs before converting length-delimited input to this C string. Supply the same canonical identity to the resolver and this function; SharkSSL does not inspect the connected socket address. IPv6 text is not supported by this comparison API. A NULL name skips identity matching and must not be used to authenticate a named endpoint. |
| cPtr | optional output for the connection's SharkSslCertInfo object. |
| U8 SharkSslCon_trustedCA | ( | SharkSslCon * | o | ) |
Returns TRUE if the certificate is valid and is signed with a root certificate trusted by SharkSSL.
Root certificates can optionally be installed with parameter SharkSslCAList when calling SharkSsl_constructor.
Note, the function only validates the certificate and its chain. You must typically also validate the domain name and the certificate's date. Function SharkSslCon_trusted extends the certificate validation and also includes domain name validation and date check.
| o | SharkSslCon *; required live connection created by SharkSsl_createCon. The caller serializes access. |
| void SubjectAltNameEnumerator_constructor | ( | SubjectAltNameEnumerator * | o, |
| U8 * | ptr, | ||
| SharkSslSANLen | len | ||
| ) |
Initialize a cursor over encoded subject alternative names.
| o | SubjectAltNameEnumerator *; Required caller-owned enumerator storage. |
| ptr | U8 *; Required borrowed SAN content buffer, retained for enumeration. |
| len | SharkSslSANLen; SAN content length in bytes. |
| void SubjectAltNameEnumerator_getElement | ( | SubjectAltNameEnumerator * | o, |
| SubjectAltName * | s | ||
| ) |
Return the next SAN and advance the cursor.
| o | SubjectAltNameEnumerator *; Required initialized enumerator. |
| s | SubjectAltName *; Required output view; ptr/len borrow the original buffer. ptr is NULL on end or parse failure; other fields are then not valid. |