10

I've got an occasional communications failure in a boost asio ssl implementation, the super helpful error message returned by boost is 'asio.ssl:336458004'

I suspect that the numerical figure is some sort of aggregate construct composed of SSL flags, I say that because the linux error codes, the boost asio error codes and the ssl error codes do not have any reference to '336458004', so presumably it must be constructed dynamically.

Can anyone provide some insight into how I should decipher this error code?, Thanks.

2 Answers 2

17

they use ERR_PACK from crypto/err/err.h

this will allow converting error to string

#include <crypto/err/err.h>

std::string err = error.message();
if (error.category() == boost::asio::error::get_ssl_category()) {
    err = std::string(" (")
            +boost::lexical_cast<std::string>(ERR_GET_LIB(error.value()))+","
            +boost::lexical_cast<std::string>(ERR_GET_FUNC(error.value()))+","
            +boost::lexical_cast<std::string>(ERR_GET_REASON(error.value()))+") "
    ;
    //ERR_PACK /* crypto/err/err.h */
    char buf[128];
    ::ERR_error_string_n(error.value(), buf, sizeof(buf));
    err += buf;
}

Probably not included in boost so asio does not need link to ssl when using pure sockets

0
3

I eventually gained some insight into the problem by building openssl in debug and putting a breakpoint on the OpenSSL error reporting function ERR_put_error.

The callstack showed that the problem was originating from SSL_read, caused by the fact that the handshake function had not been initialized. The actual error number used by the ERR_put_error function is 276, how boost manages to mangle this into 336458004 is beyond me. The bug itself was caused by a a global flag which I was using to toggle the SSL functions as I tunnel through a proxy onto a remote HTTPS server.

Hope this helps someone.

2
  • I have the very same issue at the moment, but what does "handshake function had not been initialized" mean exactly? Does it mean that there are steps i have to do before calling this function, which i've failed to do?
    – Martin G
    Commented Sep 30, 2020 at 5:06
  • I can answer my own question. In my case it was calling accept on the websocket before handshaking the ssl stream first.
    – Martin G
    Commented Oct 5, 2020 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.