C++ OpenSSL 1.0 migration to 3.0

Viewed 4184

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?

1 Answers

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.

Related