Display human readable SSL error codes

This commit is contained in:
Miguel Portilla
2015-02-20 13:23:24 -05:00
committed by Tom Ritchford
parent fe5d1ff6c5
commit b927028416
7 changed files with 131 additions and 10 deletions

View File

@@ -135,6 +135,11 @@
</ClCompile>
<ClInclude Include="..\..\src\beast\beast\asio\bind_handler.h">
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\error.h">
</ClInclude>
<ClCompile Include="..\..\src\beast\beast\asio\impl\error.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\asio\impl\IPAddressConversion.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -144,8 +149,6 @@
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\placeholders.h">
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\ssl.h">
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\ssl_bundle.h">
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\streambuf.h">
@@ -153,6 +156,9 @@
<ClCompile Include="..\..\src\beast\beast\asio\tests\bind_handler.test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\asio\tests\error_test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\asio\tests\streambuf.test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>

View File

@@ -597,6 +597,12 @@
<ClInclude Include="..\..\src\beast\beast\asio\bind_handler.h">
<Filter>beast\asio</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\error.h">
<Filter>beast\asio</Filter>
</ClInclude>
<ClCompile Include="..\..\src\beast\beast\asio\impl\error.cpp">
<Filter>beast\asio\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\asio\impl\IPAddressConversion.cpp">
<Filter>beast\asio\impl</Filter>
</ClCompile>
@@ -609,9 +615,6 @@
<ClInclude Include="..\..\src\beast\beast\asio\placeholders.h">
<Filter>beast\asio</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\ssl.h">
<Filter>beast\asio</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\asio\ssl_bundle.h">
<Filter>beast\asio</Filter>
</ClInclude>
@@ -621,6 +624,9 @@
<ClCompile Include="..\..\src\beast\beast\asio\tests\bind_handler.test.cpp">
<Filter>beast\asio\tests</Filter>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\asio\tests\error_test.cpp">
<Filter>beast\asio\tests</Filter>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\asio\tests\streambuf.test.cpp">
<Filter>beast\asio\tests</Filter>
</ClCompile>

View File

@@ -22,6 +22,8 @@
#endif
#include <beast/asio/impl/IPAddressConversion.cpp>
#include <beast/asio/impl/error.cpp>
#include <beast/asio/tests/bind_handler.test.cpp>
#include <beast/asio/tests/streambuf.test.cpp>
#include <beast/asio/tests/error_test.cpp>

View File

@@ -17,11 +17,11 @@
*/
//==============================================================================
#ifndef BEAST_ASIO_SSL_H_INCLUDED
#define BEAST_ASIO_SSL_H_INCLUDED
#ifndef BEAST_ASIO_ERROR_H_INCLUDED
#define BEAST_ASIO_ERROR_H_INCLUDED
#include <boost/asio.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/system/error_code.hpp>
namespace beast {
namespace asio {
@@ -32,8 +32,12 @@ bool
is_short_read (boost::system::error_code const& ec)
{
return (ec.category() == boost::asio::error::get_ssl_category())
&& (ERR_GET_REASON(ec.value()) == SSL_R_SHORT_READ);
&& (ERR_GET_REASON(ec.value()) == SSL_R_SHORT_READ);
}
/** Returns a human readable message if the error code is SSL related. */
std::string
asio_message(boost::system::error_code const& ec);
}
}

View File

@@ -0,0 +1,59 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <beast/asio/error.h>
#include <boost/lexical_cast.hpp>
namespace beast {
namespace asio {
// This buffer must be at least 120 bytes, most examples use 256.
// https://www.openssl.org/docs/crypto/ERR_error_string.html
static std::uint32_t const errorBufferSize (256);
std::string
asio_message (boost::system::error_code const& ec)
{
std::string error;
if (ec.category () == boost::asio::error::get_ssl_category ())
{
error = " ("
+ boost::lexical_cast<std::string> (ERR_GET_LIB (ec.value ()))
+ ","
+ boost::lexical_cast<std::string> (ERR_GET_FUNC (ec.value ()))
+ ","
+ boost::lexical_cast<std::string> (ERR_GET_REASON (ec.value ()))
+ ") ";
//
char buf[errorBufferSize];
::ERR_error_string_n (ec.value (), buf, errorBufferSize);
error += buf;
}
else
{
error = ec.message ();
}
return error;
}
}
}

View File

@@ -0,0 +1,44 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <beast/asio/error.h>
#include <beast/unit_test/suite.h>
#include <string>
namespace beast {
namespace asio {
class error_test : public unit_test::suite
{
public:
void run ()
{
{
boost::system::error_code ec = boost::system::error_code (335544539,
boost::asio::error::get_ssl_category ());
std::string const s = beast::asio::asio_message (ec);
expect(s == " (20,0,219) error:140000DB:SSL routines:SSL routines:short read");
}
}
};
BEAST_DEFINE_TESTSUITE(error,asio,beast);
}
}

View File

@@ -25,7 +25,7 @@
#include <ripple/server/impl/ServerImpl.h>
#include <beast/asio/IPAddressConversion.h>
#include <beast/asio/placeholders.h>
#include <beast/asio/ssl.h> // for is_short_read?
#include <beast/asio/error.h> // for is_short_read?
#include <beast/http/message.h>
#include <beast/http/parser.h>
#include <beast/module/core/time/Time.h>