Betfair API'ing 证书登录使用 C++ boost SSL 套接字

Betfair API'ing Certificate login using C++ boost SSL Sockets

首先,感谢您来到这里。我正在尝试使用 boost 的 ssl 套接字使用证书登录来登录 betfair,但是,一旦我发送我的 http 登录 POST,我就会收到消息 CERT_AUTH_REQUIRED。在必发网站上,它表示这意味着 "Certificate required or certificate present but could not authenticate with it"。 我能够连接、握手和 send/receive 数据。但是,我似乎无法使用我的代码登录。我已经使用 curl 测试了确切的证书,没有任何问题。

* ALPN, server accepted to use http/1.1
* Server certificate:
*        subject: C=IE; ST=Leinster; L=Dublin; O=Paddy Power Betfair Public Limi
ted Company; OU=IT Networks; CN=betfair.com
*        start date: Sep 11 05:50:38 2018 GMT
*        expire date: Sep 11 05:59:00 2020 GMT
*        issuer: C=US; O=HydrantID (Avalanche Cloud Corporation); CN=HydrantID S
SL ICA G2
*        SSL certificate verify result: self signed certificate in certificate c
hain (19), continuing anyway.
> POST /api/certlogin HTTP/1.1
> Host: identitysso-cert.betfair.com
> User-Agent: curl/7.46.0
> Accept: */*
> X-Application: AOxcQMZwVN3jOsLZ4
> Content-Length: 41
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 41 out of 41 bytes
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=ISO-8859-1
< Content-Length: 87
< Date: Wed, 06 Mar 2019 11:09:35 GMT
<
{"sessionToken":"ZFbyo3HeAh07UFTHzhhGjOyQFeX2MKdHHHHtAm2S7FXw=","loginStatus":"SU
CCESS"}* Connection #0 to host identitysso-cert.betfair.com left intact

我已经使用同样有效的 python 代码进一步测试了这些证书。 我的 C++ 代码如下。我试过发送不正确的密码,这导致服务器状态变为 INVALID_USERNAME_OR_PASSWORD。

boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12);

// load certificates
ctx.load_verify_file(cert_filename.c_str());
// ctx.use_private_key_file(private_filename.c_str(), boost::asio::ssl::context::pem);
ctx.use_rsa_private_key_file(private_filename.c_str(), boost::asio::ssl::context::pem);

mSocket.reset(new boost::asio::ssl::stream<tcp::socket>(mIoService, ctx));
mSocket->set_verify_mode(boost::asio::ssl::verify_peer);
mSocket->set_verify_callback(
    boost::bind(&BetfairSession::VerifyCertificate, this, _1, _2));

tcp::resolver resolver(mIoService);
tcp::resolver::query query("identitysso-cert.betfair.com", port);
tcp::resolver::iterator endpointIter = resolver.resolve(query);

非常感谢:)

我认为您混淆了客户端证书和 CA 列表。

这个:

ctx.load_verify_file(cert_filename.c_str());

正在加载 CA 证书列表以验证服务器证书。

您可以在此处找到此列表的示例: http://curl.haxx.se/ca/cacert.pem

您还需要设置用于 SSL 连接的证书,您可以使用 "use_certificate_chain_file" 方法完成此操作。 例如

ctx.use_certificate_chain_file(cert_filename.c_str());