Use better base64 handling in ServerHandlerImp.

This commit is contained in:
Tom Ritchford
2014-11-11 17:59:05 -05:00
parent fffdf1dfba
commit b0d47ebcc6

View File

@@ -28,6 +28,7 @@
#include <ripple/overlay/Overlay.h>
#include <ripple/resource/Manager.h>
#include <ripple/resource/Fees.h>
#include <beast/crypto/base64.h>
#include <beast/cxx14/algorithm.h> // <algorithm>
#include <beast/http/rfc2616.h>
#include <boost/algorithm/string.hpp>
@@ -307,25 +308,6 @@ ServerHandlerImp::isWebsocketUpgrade (beast::http::message const& request)
return false;
}
// VFALCO DEPRECATED
static std::string
DecodeBase64 (std::string s)
{
// FIXME: This performs badly
BIO* b64, *bmem;
// Its 2014 and we're using calloc?
char* buffer = static_cast<char*> (calloc (s.size (), sizeof (char)));
b64 = BIO_new (BIO_f_base64 ());
BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new_mem_buf (const_cast<char*> (s.data ()), s.size ());
bmem = BIO_push (b64, bmem);
BIO_read (bmem, buffer, s.size ());
BIO_free_all (bmem);
std::string result (buffer);
free (buffer);
return result;
}
// VFALCO TODO Rewrite to use beast::http::headers
bool
ServerHandlerImp::authorized (HTTP::Port const& port,
@@ -339,7 +321,7 @@ ServerHandlerImp::authorized (HTTP::Port const& port,
return false;
std::string strUserPass64 = it->second.substr (6);
boost::trim (strUserPass64);
std::string strUserPass = DecodeBase64 (strUserPass64);
std::string strUserPass = beast::base64_decode (strUserPass64);
std::string::size_type nColon = strUserPass.find (":");
if (nColon == std::string::npos)
return false;
@@ -595,7 +577,7 @@ to_Port(ParsedPort const& parsed, std::ostream& log)
throw std::exception();
}
p.protocol = parsed.protocol;
if (p.websockets() &&
if (p.websockets() &&
(parsed.protocol.count("peer") > 0 ||
parsed.protocol.count("http") > 0 ||
parsed.protocol.count("https") > 0))