For security in FIX messaging, C++ FIX Engine provides the ability to encrypt FIX connections with the SSL (Secure Sockets Layer) or TLS (Transport Layer Security) protocols. SSL v3.0, TLS v1.0, v1.1, v1.2, v1.3 are supported. The actual protocol and version are chosen automatically by a server side during the TLS/SSL Handshake. The client sends the highest version number that is supported and the server sends the highest version number that is supported by both sides. This is the protocol version that will be used during the connection.
Enabling TLS encrypts the connection, but does not enable certificate verification. SSL.VerifyPeer is false by default. To verify the counterparty's certificate, configure peer verification and the trusted CA file before connecting.
For a first connection to a controlled test endpoint, you can evaluate TLS encryption without provisioning a trusted CA file. This path does not verify the server's certificate; use it only in a controlled test environment without production credentials or traffic.
The following snippet assumes that the Engine is initialized with SSL.VerifyPeer=false and that the test endpoint requires neither SNI nor client credentials. Replace the host, port, and CompIDs with your test endpoint's values.
Before production use, configure trust and enable peer verification as shown in Connection with Certificate Verification. Also review the identity limitations in What Peer Verification Checks.
For an initiator session with certificate verification:
Peer verification checks the certificate chain against the configured trust and rejects certificate validation failures, such as an untrusted issuer or an expired certificate. It does not match the certificate to the connection's hostname or to a FIX CompID. A successful TLS handshake therefore must not be interpreted as proof of either identity match.
For production, use the CA certificates obtained through the agreed provisioning process described in Configure Certificate Verification. Where available, scope the CA file to an issuer used only for the intended counterparty's FIX service, rather than a general public CA bundle. Any otherwise valid certificate issued by a trusted CA can pass chain verification, including certificates for other parties if that CA also issues them.
If the counterparty requires SNI to select its TLS endpoint, set OnixS::FIX::Session::sslClientSni before connecting. An explicit value supplies the server name; "*" uses the connection URL. With "*", the connection URL must be a DNS name, not an IP address. SNI selects the server name sent in the handshake; it does not enable hostname verification.
This example assumes that the Engine is initialized and that the trusted CA file is available. Replace the host, port, CompIDs, and file path with the values agreed with your counterparty. For what this verification does and does not check, see What Peer Verification Checks.
The example sets ResetSeqNumFlag(141)=Y in the initial Logon to request that both sides reset sequence numbers during initial testing. Production reconnects normally preserve sequence numbers; reset them only according to the counterparty's agreed policy. See Resetting Message Sequence Numbers via ResetSeqNumFlag Field for the flag's behavior and venue constraints.
A trusted CA file identifies which issuers to trust when verifying the counterparty. A client certificate and private key identify your application to a counterparty that requires mutual TLS. They are not required merely to verify the server's certificate.
Before logon, set both OnixS::FIX::Session::sslCertificateFile and OnixS::FIX::Session::sslPrivateKeyFile. They may reference the same PEM file if it contains both items. For an encrypted private key, also set OnixS::FIX::Session::sslPrivateKeyPassword, which accepts an OnixS::Cryptography::SecureString supplied by the application.
The certificate file can also contain a certificate chain with multiple CA certificates; see SSL.CertificateFile in Complete Reference of Configuration Settings. Chain-file loading applies only when no CA file is configured (including the Engine-level fallback for initiators). With the explicit CA configuration above, the certificate file is loaded as a single certificate.
Call this helper before logonAsInitiator when client credentials are required. Its password argument comes from the application's credential handling; no password is embedded in the example.
Per-session TLS settings are supported only for initiators. Acceptors use the global Engine settings:
Create the acceptor session, select OnixS::FIX::EncryptionMethod::SSL, and call OnixS::FIX::Session::logonAsAcceptor. See Per-session TLS/SSL Settings for initiator settings and their Engine-level fallback, and Troubleshooting for connection failures.
By default, a server side automatically chooses the actual TLS/SSL protocol and version during the TLS/SSL Handshake. However, some erroneous or more restricted servers, which allow only the specific protocol version, can reject TLS/SSL connections acting in such an algorithm. In such cases, the client can limit the TLS/SSL protocol versions to be used. For this purpose, SSL.MinProtocolVersion and SSL.MaxProtocolVersion parameters of Engine configuration settings can be used. Also, there are corresponding session-level OnixS::FIX::Session::sslMinProtocolVersion and OnixS::FIX::Session::sslMaxProtocolVersion settings: