|
SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
|
Mutual TLS lets a server authenticate a client certificate during the initial handshake. This subset uses one certificate/key identity per SSL_CTX, loaded with the existing unencrypted PEM functions. It reuses native SharkSSL's client authentication and the wrapper's trust, date and metadata inspection paths.
Configure both contexts before creating SSL objects. For example, after creating client and server contexts and initializing the application-owned RNG:
See TLS setup and I/O for object ownership, BIO retries, PEM limits, RNG startup and verification limitations. An SSL object holds its context alive. Credential/CA replacement remains prohibited while any derived SSL exists. Native selection uses the configured identity when compatible with the peer's request. There is no dynamic selection callback or per-SSL identity override.
The int mode argument to SSL_CTX_set_verify or SSL_set_verify accepts these server settings. A verification callback requires the optional native hook described in Peer verification policy.
| Mode | Server behavior |
|---|---|
SSL_VERIFY_NONE (default) | Does not request a client certificate |
SSL_VERIFY_PEER | Requests a certificate; permits absence; rejects a presented invalid certificate |
SSL_VERIFY_PEER \| SSL_VERIFY_FAIL_IF_NO_PEER_CERT | Requires a valid client certificate |
SSL_VERIFY_FAIL_IF_NO_PEER_CERT alone and unknown flags are rejected. Client verification remains limited to NONE or PEER. Context settings are copied at SSL creation. Per-SSL settings may be changed before I/O starts. Invalid context settings prevent SSL creation until corrected; invalid per-SSL settings or changes after I/O starts latch a fatal SSL error.
Server authentication modes require native SHARKSSL_ENABLE_CLIENT_AUTH=1 and the compiled server/signature capabilities. Builds with client authentication disabled retain ordinary TLS; server PEER settings are rejected at configuration. Enable client authentication in the client build as well to send its identity.
Trust loading does not advertise CA names. The wrapper calls SharkSslCon_requestClientCertEx with a NULL request list; the native context's trust store is still used for validation. Separate advertised-CA-list setters are outside this subset. By default a server trusting no suitable CA rejects the presented certificate. An enabled verification callback can explicitly waive the missing issuer.
Native handshake processing verifies the certificate chain, client purpose and proof of private-key possession. The wrapper checks trust and dates before reporting success or exposing application data. With the hook enabled, those policy checks run while processing the peer Certificate message. The notBefore allowance of up to 24 hours remains in effect. It deliberately differs from OpenSSL.
Absent optional certificates leave SSL_get_verify_result at X509_V_OK and peer-certificate getters return NULL. Zero alone therefore does not establish client identity. A required missing certificate fails with SSL_ERROR_SSL and SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE in the thread's error queue; its X509 verification result also remains zero. Wrapper trust/date rejection reports SSL_R_CERTIFICATE_VERIFY_FAILED and the corresponding X509 result. Native handshake rejections may leave that result zero and expose a native alert code.
Native metadata retention is best effort. The read-only SharkSslCon_receivedEmptyCertificate query distinguishes an actual empty client Certificate message from failed metadata retention. If metadata is unavailable for a nonempty certificate, optional and required authentication both reject it with X509_V_ERR_CERT_REJECTED and a verification-failure reason. This prevents an allocation failure from being treated as anonymous access.
With the hook enabled, rejecting a presented client chain during verification sends a fatal certificate alert. A missing required certificate or a later metadata-retention failure still fails the local SSL operation. Close the failed transport.
After successful mutual TLS, the server can inspect and retain its client's certificate using the metadata-only X509 APIs. This does not retain complete DER or implement application authorization based on certificate fields.
The native TLS 1.2 server accepts the RSAE-PSS signature schemes advertised in its CertificateRequest. SHA-256, SHA-384 and SHA-512 depend on the corresponding compiled hash capabilities and SHARKSSL_ENABLE_RSASSA_PSS. The default native configuration enables SHA-256/384; SHA-512 requires explicit configuration. The existing native verifier checks the signature using the client certificate's RSA key. Legacy PKCS#1 and ECDSA paths remain available under their native flags.
This does not add a wrapper signature-selection API or automatic peer restriction. It does not add support for PSS-restricted certificate keys or the rsa_pss_pss_* schemes. Dynamic selection callbacks are outside this subset. Session resumption, renegotiation, post-handshake authentication and public trust-store objects remain outside this subset, as does full DER retention.
References: OpenSSL verification modes and trust loading versus advertised CA names.