mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-27 22:35:02 +00:00
Merge pull request #2481 from pobregat0/beast-base64
use base64 from boost::beast for basic authorization
This commit is contained in:
@@ -1275,7 +1275,7 @@ namespace http {
|
||||
auto provided = req.GetHeader ("Authorization");
|
||||
if (provided.length () > 0)
|
||||
{
|
||||
std::string expected = "Basic " + i2p::data::ToBase64Standard (user + ":" + pass);
|
||||
std::string expected = i2p::http::CreateBasicAuthorizationString (user, pass);
|
||||
if (expected == provided) return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -201,17 +201,6 @@ namespace data
|
||||
return outCount;
|
||||
}
|
||||
|
||||
std::string ToBase64Standard (std::string_view in)
|
||||
{
|
||||
auto str = ByteStreamToBase64 ((const uint8_t *)in.data (), in.length ());
|
||||
// replace '-' by '+' and '~' by '/'
|
||||
for (auto& ch: str)
|
||||
if (ch == '-')
|
||||
ch = '+';
|
||||
else if (ch == '~')
|
||||
ch = '/';
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace data
|
||||
return 4 * d.quot;
|
||||
}
|
||||
|
||||
std::string ToBase64Standard (std::string_view in); // using standard table, for Proxy-Authorization
|
||||
|
||||
} // data
|
||||
} // i2p
|
||||
|
||||
+5
-1
@@ -11,6 +11,7 @@
|
||||
#include <stdio.h>
|
||||
#include <ctime>
|
||||
#include <charconv>
|
||||
#include <boost/beast/core/detail/base64.hpp>
|
||||
#include "util.h"
|
||||
#include "Base.h"
|
||||
#include "HTTP.h"
|
||||
@@ -625,7 +626,10 @@ namespace http
|
||||
std::string CreateBasicAuthorizationString (const std::string& user, const std::string& pass)
|
||||
{
|
||||
if (user.empty () && pass.empty ()) return "";
|
||||
return "Basic " + i2p::data::ToBase64Standard (user + ":" + pass);
|
||||
auto credentials = user + ":" + pass;
|
||||
std::string encoded (boost::beast::detail::base64::encoded_size (credentials.length ()), 0);
|
||||
encoded.resize (boost::beast::detail::base64::encode (encoded.data (), credentials.data (), credentials.length ()));
|
||||
return "Basic " + encoded;
|
||||
}
|
||||
|
||||
} // http
|
||||
|
||||
Reference in New Issue
Block a user