OnixS C++ FIX Engine 4.14.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Per-session TLS/SSL Settings

TLS settings can be configured for individual initiator sessions before logon. The main settings are:

Setting Purpose
OnixS::FIX::Session::sslVerifyPeer Enable verification of the counterparty's certificate.
OnixS::FIX::Session::sslCaFile Supply the PEM file of trusted CA certificates.
OnixS::FIX::Session::sslCertificateFile Supply the client's certificate when mutual TLS is required.
OnixS::FIX::Session::sslPrivateKeyFile Supply the private key belonging to the client's certificate.
OnixS::FIX::Session::sslPrivateKeyPassword Supply an application-provided OnixS::Cryptography::SecureString for an encrypted private key.
OnixS::FIX::Session::sslClientSni Supply an SNI server name; with "*", the connection URL must be a DNS name, not an IP address.
Note
Per-session TLS/SSL settings are supported only for initiator sessions. Acceptor sessions use global FIX Engine TLS/SSL settings. See Acceptor Configuration.

Engine-level Fallback

When a per-session CA file is unset, the Engine-level SSL.CaFile supplies the trust configuration. For example, an initiator can enable sslVerifyPeer(true) and use the CA file configured through OnixS::FIX::EngineSettings::sslCaFile without setting a per-session CA file.

Peer verification is enabled if either the session or Engine enables it. Setting the per-session option to false does not disable verification enabled globally. Both levels default to disabled. Check both levels when diagnosing certificate verification failures.

See What Peer Verification Checks for the distinction between certificate-chain verification and hostname matching, and Optional Client Credentials for Mutual TLS for encrypted private keys.

Example

The following initiator sessions explicitly verify the server and also supply client credentials for mutual TLS. Replace the paths and connection settings with your counterparty's values. The example assumes unencrypted client keys; set sslPrivateKeyPassword before logon for encrypted keys. Configure trust and credentials before connecting each session.

const std::string TargetCompID = "CNX";
const std::string Host = "TargetHost";
const std::string TrustedCaFile = "trusted-ca.pem";
const int HeartbeatIntervalSeconds = 30;
// Send ResetSeqNumFlag(141)=Y to request a reset on both sides during initial testing.
const bool ResetSequenceNumbersForInitialTesting = true;
// Stream FIX Session.
{
const std::string StreamSenderCompID = "str";
const std::string StreamSslCertificateAndPrivateKeyFile = "str.pem";
const int StreamPort = 442;
Session streamSession(StreamSenderCompID, TargetCompID, ProtocolVersion::FIX_42, nullptr);
streamSession.encryptionMethod(EncryptionMethod::SSL);
streamSession.sslVerifyPeer(true);
streamSession.sslCaFile(TrustedCaFile);
// Supply client credentials as well when the counterparty requires mutual TLS.
streamSession.sslCertificateFile(StreamSslCertificateAndPrivateKeyFile);
streamSession.sslPrivateKeyFile(StreamSslCertificateAndPrivateKeyFile);
streamSession.logonAsInitiator(Host, StreamPort, HeartbeatIntervalSeconds, ResetSequenceNumbersForInitialTesting);
std::clog << "Stream session is established." << std::endl;
streamSession.logout().shutdown();
}
// Trading FIX Session.
{
const std::string TradingSenderCompID = "tr";
const std::string TradingSslCertificateAndPrivateKeyFile = "tr.pem";
const int TradingPort = 443;
Session tradingSession(TradingSenderCompID, TargetCompID, ProtocolVersion::FIX_42, nullptr);
tradingSession.encryptionMethod(EncryptionMethod::SSL);
tradingSession.sslVerifyPeer(true);
tradingSession.sslCaFile(TrustedCaFile);
// Supply client credentials as well when the counterparty requires mutual TLS.
tradingSession.sslCertificateFile(TradingSslCertificateAndPrivateKeyFile);
tradingSession.sslPrivateKeyFile(TradingSslCertificateAndPrivateKeyFile);
tradingSession.logonAsInitiator(Host, TradingPort, HeartbeatIntervalSeconds, ResetSequenceNumbersForInitialTesting);
std::clog << "Trading session is established." << std::endl;
tradingSession.logout().shutdown();
}