How do I know if libcurl processed my SSL files correctly

I am trying to login to betfair via the betfair api using curl. I already managed to do this through the curl version from the command line from the bash script, but now I want to do this from my C ++ code directly with libcurl. Unfortunately, libcurl is not supported by betfair, so there is no direct documentation, but if command-line curl works, then everything should be doable.

My libcurl does not work right away during a login attempt (which should get a "session token" as an answer). I tell the hang about my certificate and key line:

curl_easy_setopt(curl, CURLOPT_SSLCERT,"client-2048.crt");
curl_easy_setopt(curl, CURLOPT_SSLKEY,"client-2048.key");

Later I call curl_easy_perform(curl);, I get the answer:

{"loginStatus":"CERT_AUTH_REQUIRED"}

According to the betfair documentation, this means: โ€œA certificate or certificate is required, but cannot authenticate with itโ€

So, I think the SSL authentication is incorrect. As an experiment, I tried to deliberately put the junk certificate and key file names (for example, "client-2048_XXX.crt"), but did not see a difference in response from betfair or any of the twists (configured through curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);and curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);), so I donโ€™t know for sure that libcurl handled my certificates and key files correctly. In fact, I even suspect that maybe he doesnโ€™t process them at all - maybe I miss some other option according to CURLOPT_PLEASE_USE_SSL_AUTHENTICATION, which leads to ignoring files?

: , ( ):

curl_easy_setopt(curl, CURLOPT_URL, "https://identitysso.betfair.com/api/certlogin");
curl_easy_setopt(curl, CURLOPT_SSLCERT,"client-2048.crt");
curl_easy_setopt(curl, CURLOPT_SSLKEY,"client-2048.key");
curl_easy_setopt(curl, CURLOPT_POST, 1);

struct curl_slist *chunk = NULL;
chunk = curl_slist_append(chunk, "X-Application: _HIDDEN_");
chunk = curl_slist_append(chunk,"Content-Type: application/x-www-form-urlencoded");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);

curl_easy_setopt(curl, CURLOPT_POSTFIELDS,"username=_HIDDEN_&password=_HIDDEN_");

curl_easy_perform(curl);

EDIT: , , , - libcurl SSL. , curl_version_info, , , :

char *ssl_version;        /* human readable string */

"WinSSL", , , , SSL.

EDIT: FYI, "client-2048":.crt,.pem,.key .csr. , exe . ( _getcwd()) , , exe .

: login.sh(, , , , ). getlog.exe , , JSON.

#!/bin/bash    
# uses rescript    
APP_KEY=_HIDDEN_
#SESSION_TOKEN=$2

HOST=https://api.betfair.com/exchange/betting
AUTHURL=https://identitysso.betfair.com/api/certlogin
CURL=curl    

function bflogin()
{
    echo "bflogin()"

    OUT=$($CURL -s -k --cert client-2048.crt --key client-2048.key --data "username=_HIDDEN_&password=_HIDDEN_" -H "X-Application: $APP_KEY" -H "Content-Type: application/x-www-form-urlencoded" $AUTHURL)
    echo $OUT
    SESSION_TOKEN=$(echo $OUT | getlog.exe)
    echo
    echo "Here -> "$SESSION_TOKEN
    echo $SESSION_TOKEN > st.txt
}
+4
1

crt .

, , PEM . CURLOPT_SSLCERTTYPE PEM.

+1

Source: https://habr.com/ru/post/1672242/


All Articles