The sample code below implements the simplest client and server FIX sessions with SSL support.
Note: The code is just an example, it is not guaranteed to be free from security exploits. Application should implement its own SSL authentication methods in order to achieve a complete secure connection.
Client:
/// <summary> /// The FIXStandaloneApplication.FIXEngineInitialized event handler. /// </summary> /// <param name="fixEngine">The instance of T:Teraspaces.QWFIX.FIXEngine.</param> void ClientFIXEngineInitialized(FIXEngine fixEngine) { FIXEngineSessionEndPoint sessionEndPoint = null; string serverName = "YourServerName"; foreach (FIXEngineSessionEndPoint curEndPoint in fixEngine.Settings.SessionEndPoints) { // TODO: Identify the correct FIXEngineSessionEndPoint } sessionEndPoint.SslParameters = new FIXSessionSslParameters( RemoteCertificateValidationCallback, null, null, false, serverName); } static bool RemoteCertificateValidationCallback( Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { // Warning: This is just an sample. Application SHOULD implement its own authentication and authorization // procedure. The current implementation simply grant access to ANY certificate, which is simply unsecure. return true; }
Server:
/// <summary> /// The FIXStandaloneApplication.FIXEngineInitialized event handler. /// </summary> /// <param name="fixEngine">The instance of T:Teraspaces.QWFIX.FIXEngine.</param> void ServerFIXEngineInitialized(FIXEngine fixEngine) { FIXEngineSessionEndPoint sessionEndPoint = null; string serverName = "YourServerName"; foreach (FIXEngineSessionEndPoint curEndPoint in fixEngine.Settings.SessionEndPoints) { // TODO: Identify the correct FIXEngineSessionEndPoint } X509Certificate cert = X509Certificate.CreateFromCertFile(@"cert file"); sessionEndPoint.SslParameters = new FIXSessionSslParameters( null, null, null, false, serverName); }