4

I'm trying to make a bot to access and do stuff with BitStamp API (https://www.bitstamp.net/api/), but I'm hitting a snag.

In the page linked, they show an example of how to authenticate with c++ (the V2 version). I'm having problems with this part for the authentication using openSSL:

HMAC_CTX ctx;
HMAC_CTX_init(&ctx);

HMAC_Init_ex(&ctx, api_secret.c_str(), api_secret.length(), EVP_sha256(), NULL);
HMAC_Update(&ctx, (unsigned char*)data_to_sign.c_str(), data_to_sign.length());
HMAC_Final(&ctx, result, &len);
HMAC_CTX_cleanup(&ctx);

std::string x_auth_signature = b2a_hex( (char *)result, 32 );
free(result);

and

std::string b2a_hex(char *byte_arr, int n)
{
    const static std::string hex_codes = "0123456789abcdef";
    std::string hex_string;
    for ( int i = 0; i < n ; ++i ) {
        unsigned char bin_value = byte_arr[i];
        hex_string += hex_codes[( bin_value >> 4 ) & 0x0F];
        hex_string += hex_codes[bin_value & 0x0F];
    }
    return hex_string;
}

Using openSSL 3.0, seems like HMAC_CTX has been deprecated.

When compiling I get the following error messages:

Error C4996 'HMAC_Update': Since OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 70
Error C4996 'HMAC_Init_ex': Since OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 69
Error C4996 'HMAC_Final': Since OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 71
Error C4996 'HMAC_CTX_reset': Since OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 72
Error C4996 'HMAC_CTX_new': Since OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 68

I have scoured the internet looking for any migration tips, but i can't find anything. Any kind soul can help me or point me in the direction of how to migrate this piece of code to openSSL3.0 supported code?

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
LostTab
  • 43
  • 1
  • 4

1 Answers1

2

OK, there are several issues:

  • Error C4996 'HMAC_Update': Since OpenSSL 3.0

    Look here: https://stackoverflow.com/a/20448142/421195

    It sounds like you're using Microsoft Visual Studio C++ to compile. You might be able to eliminate the C4996 "error" with #pragma warning(disable : 4996)

  • "Seems like i download the 3.0 alpha version"

    You might have better luck with Open SSL 1.1:

https://www.openssl.org/

08-Dec-2020 OpenSSL 1.1.1i is now available, including bug and security fixes

'Hope that helps! Please post back your results.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Thanks for the help. The #pragma warning didn't do anything for me, but going back to OpenSSL1.1.1i and rebuilding all the external library dependencies did the trick. That should teach me to not download master branches on github again :D – LostTab Dec 24 '20 at 18:43