如何解决QuickFIX/n - SSL 启动器无 stunnel
一直在用头撞墙。
我正在尝试设置一个 quickfix 启动器来建立到 Bloomberg FIX 服务器的 SSL 连接。并且基于 docs,我认为这将相对直接实现。但是,我似乎无法弄清楚我哪里出错了。任何帮助将不胜感激。
注意事项:
- 我正在使用 dotnet cli 创建、构建和运行项目
- 彭博为我们提供了 3 种格式的证书:JKS、PEM 和 PKCS12
- 我已经使用 this S/O comment (Convert PFX to CER) 中描述的过程从提供的 PKCS12 证书生成了生成的
mycerts.cer
文件。但是,无论是否执行此步骤,错误信息都是相同的 - 可能还值得注意的是,我之前已经设法使用 python 版本的 quickfix 和 stunnel(处理 SSL 连接)建立并维护到bloomberg FIX 服务器的安全连接。但是我现在需要移除对 stunnel 的依赖,因此尝试切换到 quickfix/n
设置:
这是当前的 .csproj
文件
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Heimdall.AppTest\Heimdall.AppTest.csproj" />
</ItemGroup>
<ItemGroup>
<packagereference Include="QuickFIXn.Core" Version="1.10.0" />
<packagereference Include="QuickFIXn.FIX4.4" Version="1.10.0" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<copy SourceFiles=".\FIX44.xml" DestinationFolder="$(TargetDir)" />
<copy SourceFiles=".\bbgetomsClient.cfg" DestinationFolder="$(TargetDir)" />
<copy SourceFiles=".\pkcs12\cert.pfx" DestinationFolder="$(TargetDir)" />
<copy SourceFiles=".\openssl\mycerts.cer" DestinationFolder="$(TargetDir)" />
</Target>
</Project>
这是启动器应用程序使用的实际 bbgetomsClient.cfg
文件(基于 this issue)
[DEFAULT]
ApplicationID=client
ConnectionType=initiator
HeartBtInt=60
Resetonlogon=N
ResetSeqNumFlag=N
FileStorePath=incoming
FileLogPath=outgoing
ScreenLogShowIncoming=Y
ScreenLogShowOutgoing=Y
ScreenLogShowEvents=Y
UseDataDictionary=Y
DataDictionary=FIX44.xml
SocketConnectPort=xxxx
SocketConnectHost=xxx.xx.xxx.xx (same as SSLServerName)
SSLEnable=Y
SSLProtocols=Tls12
SSLCheckCertificateRevocation=N
SSLValidateCertificates=N
SSLServerName=xxx.xx.xxx.xx
SSLCertificate=cert.pfx
SSLCertificatePassword=<PfxCertPassword>
SSLCACertificate=mycerts.cer
[SESSION]
BeginString=FIX.4.4
SenderCompID=<SenderCompID>
TargetCompID=<TargetCompID>
StartTime=00:00:01
EndTime=23:59:59
这是超级基本的 program.cs
using System;
using System.Collections.Generic;
using System.Text;
using QuickFix;
using QuickFix.Fields;
using QuickFix.Transport;
using System.Linq;
namespace Heimdall.App
{
public class MyQuickFixApp : IApplication
{
public void FromApp(Message msg,SessionID sessionID)
{
Console.WriteLine("IN:<FromApp> " + msg);
}
public void OnCreate(SessionID sessionID) { }
public void Onlogout(SessionID sessionID) { }
public void Onlogon(SessionID sessionID) { }
public void FromAdmin(Message msg,SessionID sessionID)
{
Console.WriteLine("IN:<FromAdmin> " + msg);
}
public void ToAdmin(Message msg,SessionID sessionID)
{
Console.WriteLine("OUT:<ToAdmin> " + msg);
}
public void ToApp(Message msg,SessionID sessionID)
{
Console.WriteLine("IN:<ToApp> " + msg);
}
}
class Program
{
static void Main(string[] args)
{
SessionSettings settings = new SessionSettings("bbgetomsClient.cfg");
IApplication myApp = new MyQuickFixApp();
IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
ILogFactory logFactory = new FileLogFactory(settings);
Socketinitiator initiator = new Socketinitiator(
myApp,storeFactory,settings,logFactory);
try
{
initiator.Start();
while (true)
{
System.Threading.Thread.Sleep(2000);
}
}
catch (System.Exception e)
{
Console.WriteLine("==Fatal error==");
Console.WriteLine(e.ToString());
initiator.Stop();
}
}
}
}
错误:
使用上面列出的设置运行项目时,观察到以下错误:
20210107-13:23:00.242 : Unexpected exception: System.ArgumentNullException: Value cannot be null. (Parameter 'value')
at System.Collections.CollectionBase.OnValidate(Object value)
at System.Security.Cryptography.X509Certificates.X509CertificateCollection.OnValidate(Object value)
at System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
at System.Security.Cryptography.X509Certificates.X509CertificateCollection.Add(X509Certificate value)
at QuickFix.Transport.StreamFactory.SSLStreamFactory.GetClientCertificates()
at QuickFix.Transport.StreamFactory.SSLStreamFactory.CreateClientStreamAndAuthenticate(Stream innerStream)
at QuickFix.Transport.StreamFactory.CreateClientStream(IPEndPoint endpoint,SocketSettings settings,ILog logger)
at QuickFix.socketinitiatorThread.SetupStream()
at QuickFix.Transport.socketinitiator.socketinitiatorThreadStart(Object socketinitiatorThread)
据我所知,我的错误可能与this issue (.NetCore3.1 and QuickFIXn problem #571)
有关版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。