首先,谢谢你来到这里。我正在尝试使用boost的ssl套接字使用证书登录使用betfair登录但是,一旦我发送了我的http登录POST,我收到消息CERT_AUTH_REQUIRED。在betfair网站上,它表示这意味着“需要证书或证书,但无法通过它进行身份验证”。我能够连接,握手和发送/接收数据。但是,我似乎无法使用我的代码登录。我已经使用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());