Skip to content

Commit

Permalink
proper path searching for CA certs
Browse files Browse the repository at this point in the history
  • Loading branch information
gbirchmeier committed Jun 26, 2024
1 parent de1898f commit cfb9c1c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 102 deletions.
3 changes: 2 additions & 1 deletion Examples/Executor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static void Main(string[] args)
SessionSettings settings = new SessionSettings(args[0]);
IApplication executorApp = new Executor();
IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
ILogFactory logFactory = new FileLogFactory(settings);
ILogFactory logFactory = new ScreenLogFactory(settings);
//ILogFactory logFactory = new FileLogFactory(settings);
ThreadedSocketAcceptor acceptor = new ThreadedSocketAcceptor(executorApp, storeFactory, settings, logFactory);
HttpServer srv = new HttpServer(HttpServerPrefix, settings);

Expand Down
6 changes: 5 additions & 1 deletion Examples/Executor/executor.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ ConnectionType=acceptor
SocketAcceptPort=5001
StartTime=00:00:00
EndTime=00:00:00
FileLogPath=log
UseDataDictionary=Y
ResetOnLogon=Y
ResetOnLogout=Y
ResetOnDisconnect=Y

FileLogPath=log
ScreenLogShowIncoming=Y
ScreenLogShowOutgoing=Y
ScreenLogShowEvents=Y

[SESSION]
BeginString=FIX.4.0
SenderCompID=EXECUTOR
Expand Down
96 changes: 9 additions & 87 deletions Examples/Executor/executor_ssl.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,106 +4,28 @@ SocketAcceptPort=5001
SocketReuseAddress=Y
StartTime=00:00:00
EndTime=00:00:00
FileLogPath=log
UseDataDictionary=Y
ResetOnLogon=Y
ResetOnLogout=Y
ResetOnDisconnect=Y

FileLogPath=log
ScreenLogShowIncoming=Y
ScreenLogShowOutgoing=Y
ScreenLogShowEvents=Y


SSLEnable=Y
# It is recommended to install the certificate and refer to it by name instead of using filename + password
SSLCertificate=QuickFixn-TestServer.pfx
SSLCertificate=../QuickFixn-TestServer.pfx
SSLCertificatePassword=QuickFixn-TestServer
# For production refer to certificate by name instead: SSLCertificate=CN=QuickFixn-TestServer
SSLCACertificate=QuickFixn-TestCA.cer
SSLCACertificate=../QuickFixn-TestCA.cer
SSLCheckCertificateRevocation=N

[SESSION]
BeginString=FIX.4.0
SenderCompID=EXECUTOR
TargetCompID=CLIENT1
FileStorePath=store
DataDictionary=../../spec/fix/FIX40.xml

[SESSION]
BeginString=FIX.4.0
SenderCompID=EXECUTOR
TargetCompID=CLIENT2
FileStorePath=store
DataDictionary=../../spec/fix/FIX40.xml

[SESSION]
BeginString=FIX.4.1
SenderCompID=EXECUTOR
TargetCompID=CLIENT1
FileStorePath=store
DataDictionary=../../spec/fix/FIX41.xml

[SESSION]
BeginString=FIX.4.1
SenderCompID=EXECUTOR
TargetCompID=CLIENT2
FileStorePath=store
DataDictionary=../../spec/fix/FIX41.xml

[SESSION]
BeginString=FIX.4.2
SenderCompID=EXECUTOR
TargetCompID=CLIENT1
FileStorePath=store
DataDictionary=../../spec/fix/FIX42.xml

[SESSION]
BeginString=FIX.4.2
SenderCompID=EXECUTOR
TargetCompID=CLIENT2
FileStorePath=store
DataDictionary=../../spec/fix/FIX42.xml

[SESSION]
BeginString=FIX.4.3
SenderCompID=EXECUTOR
TargetCompID=CLIENT1
FileStorePath=store
DataDictionary=../../spec/fix/FIX43.xml

[SESSION]
BeginString=FIX.4.3
SenderCompID=EXECUTOR
TargetCompID=CLIENT2
FileStorePath=store
DataDictionary=../../spec/fix/FIX43.xml

[SESSION]
BeginString=FIX.4.4
SenderCompID=EXECUTOR
TargetCompID=CLIENT1
FileStorePath=store
DataDictionary=../../spec/fix/FIX44.xml



[SESSION]
BeginString=FIX.4.4
SenderCompID=EXECUTOR
TargetCompID=CLIENT2
FileStorePath=store
DataDictionary=../../spec/fix/FIX44.xml

#[SESSION]
#BeginString=FIXT.1.1
#DefaultApplVerID=FIX.5.0
#SenderCompID=EXECUTOR
#TargetCompID=CLIENT1
#FileStorePath=store
#TransportDataDictionary=../../spec/fix/FIXT11.xml
#AppDataDictionary=../../spec/fix/FIX50.xml

#[SESSION]
#BeginString=FIXT.1.1
#DefaultApplVerID=FIX.5.0
#SenderCompID=EXECUTOR
#TargetCompID=CLIENT2
#FileStorePath=store
#TransportDataDictionary=../../spec/fix/FIXT11.xml
#AppDataDictionary=../../spec/fix/FIX50.xml

1 change: 1 addition & 0 deletions Examples/TradeClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static void Main(string[] args)
TradeClientApp application = new TradeClientApp();
IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
ILogFactory logFactory = new ScreenLogFactory(settings);
//ILogFactory logFactory = new FileLogFactory(settings);
QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(application, storeFactory, settings, logFactory);

// this is a developer-test kludge. do not emulate.
Expand Down
7 changes: 4 additions & 3 deletions Examples/TradeClient/tradeclient.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
ConnectionType=initiator
ReconnectInterval=2
FileStorePath=store
FileLogPath=log
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
DataDictionary=../../spec/fix/FIX44.xml
SocketConnectHost=127.0.0.1
SocketConnectPort=5001
SocketIgnoreProxy=Y
LogoutTimeout=5
ResetOnLogon=Y
ResetOnDisconnect=Y

FileLogPath=log
ScreenLogShowIncoming=Y
ScreenLogShowOutgoing=Y
ScreenLogShowEvents=Y

LogoutTimeout=5
ResetOnLogon=Y

[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
BeginString=FIX.4.4
Expand Down
16 changes: 10 additions & 6 deletions Examples/TradeClient/tradeclient_ssl.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
ConnectionType=initiator
ReconnectInterval=2
FileStorePath=store
FileLogPath=log
StartTime=00:00:00
EndTime=00:00:00
UseDataDictionary=Y
Expand All @@ -11,15 +10,20 @@ SocketConnectHost=127.0.0.1
SocketConnectPort=5001
SSLEnable=Y

FileLogPath=log
ScreenLogShowIncoming=Y
ScreenLogShowOutgoing=Y
ScreenLogShowEvents=Y

LogoutTimeout=5
ResetOnLogon=Y

# It is recommended to install the certificate and refer to it by name instead of using filename + password
SSLCertificate=QuickFixn-TestClient.pfx
SSLCertificate=../QuickFixn-TestClient.pfx
SSLCertificatePassword=QuickFixn-TestClient
# For production refer to certificate by name instead: SSLCertificate=CN=QuickFixn-TestClient
SSLServerName=QuickFixn-TestServer
SSLCACertificate=QuickFixn-TestCA.cer

LogoutTimeout=5
ResetOnLogon=Y
SSLCACertificate=../QuickFixn-TestCA.cer

[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
Expand Down
3 changes: 1 addition & 2 deletions QuickFIXn/Transport/SslCertCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ private static X509Certificate2 LoadCertificateInner(string name, string? passwo
{
var certPath = StringUtil.FixSlashes(name);

// If no extension is found try to get from certificate store
// If cert file not found, then try to get from certificate store
if (!File.Exists(certPath))
{
var certFromStore = GetCertificateFromStore(StringUtil.FixSlashes(name));
if (certFromStore is not null)
return certFromStore;

// see TODO in LoadCertificate()
string msg =
$"Certificate '{name}' could not be loaded from store or path '{Directory.GetCurrentDirectory()}'";
Console.WriteLine(msg);
Expand Down
6 changes: 4 additions & 2 deletions QuickFIXn/Transport/SslStreamFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ private bool VerifyRemoteCertificate(
return false;
}

string caCertPath = StringUtil.FixSlashes(_socketSettings.CACertificatePath);

// If CA Certificate is specified then validate against the CA certificate, otherwise it is validated against the installed certificates
X509Certificate2? cert = SslCertCache.LoadCertificate(_socketSettings.CACertificatePath, null);
X509Certificate2? cert = SslCertCache.LoadCertificate(caCertPath, null);
if (cert is null) {
_nonSessionLog.OnEvent(
$"Certificate '{_socketSettings.CACertificatePath}' could not be loaded from store or path '{Directory.GetCurrentDirectory()}'");
$"Certificate '{caCertPath}' could not be loaded from store or path '{Directory.GetCurrentDirectory()}'");
return false;
}

Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ What's New
* Cleanup/nullable-ize SocketInitiatorThread (gbirchmeier)
* #839 - change ScreenLog to output FIX messages with "|" instead of non-visible SOH (gbirchmeier)
* #844 - implement "Weekdays" setting (MichalUssuri/gbirchmeier)
* #859 - implement proper path searching for CA certs in config (gbirchmeier)

### v1.11.2:
* same as v1.11.1, but I fixed the readme in the pushed nuget packages
Expand Down

0 comments on commit cfb9c1c

Please sign in to comment.