mirror of
https://github.com/monero-project/monero.git
synced 2024-12-25 10:29:23 -05:00
Replace in-tree MD5 with OpenSSL
This uses OpenSSL's non-deprecated EVP digest facility to calculate MD5 in HTTP digest authentication.
This commit is contained in:
parent
893916ad09
commit
0bc5969755
@ -63,11 +63,11 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <openssl/evp.h>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "hex.h"
|
#include "hex.h"
|
||||||
#include "md5_l.h"
|
|
||||||
#include "string_coding.h"
|
#include "string_coding.h"
|
||||||
|
|
||||||
/* This file uses the `u8` prefix and specifies all chars by ASCII numeric
|
/* This file uses the `u8` prefix and specifies all chars by ASCII numeric
|
||||||
@ -114,8 +114,8 @@ namespace
|
|||||||
void operator()(const T& arg) const
|
void operator()(const T& arg) const
|
||||||
{
|
{
|
||||||
const boost::iterator_range<const char*> data(boost::as_literal(arg));
|
const boost::iterator_range<const char*> data(boost::as_literal(arg));
|
||||||
md5::MD5Update(
|
EVP_DigestUpdate(
|
||||||
std::addressof(ctx),
|
ctx,
|
||||||
reinterpret_cast<const std::uint8_t*>(data.begin()),
|
reinterpret_cast<const std::uint8_t*>(data.begin()),
|
||||||
data.size()
|
data.size()
|
||||||
);
|
);
|
||||||
@ -126,25 +126,25 @@ namespace
|
|||||||
}
|
}
|
||||||
void operator()(const epee::wipeable_string& arg) const
|
void operator()(const epee::wipeable_string& arg) const
|
||||||
{
|
{
|
||||||
md5::MD5Update(
|
EVP_DigestUpdate(
|
||||||
std::addressof(ctx),
|
ctx,
|
||||||
reinterpret_cast<const std::uint8_t*>(arg.data()),
|
reinterpret_cast<const std::uint8_t*>(arg.data()),
|
||||||
arg.size()
|
arg.size()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
md5::MD5_CTX& ctx;
|
EVP_MD_CTX *ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
std::array<char, 32> operator()(const T&... args) const
|
std::array<char, 32> operator()(const T&... args) const
|
||||||
{
|
{
|
||||||
md5::MD5_CTX ctx{};
|
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_new(), &EVP_MD_CTX_free);
|
||||||
md5::MD5Init(std::addressof(ctx));
|
EVP_DigestInit(ctx.get(), EVP_md5());
|
||||||
boost::fusion::for_each(std::tie(args...), update{ctx});
|
boost::fusion::for_each(std::tie(args...), update{ctx.get()});
|
||||||
|
|
||||||
std::array<std::uint8_t, 16> digest{{}};
|
std::array<std::uint8_t, 16> digest{{}};
|
||||||
md5::MD5Final(digest.data(), std::addressof(ctx));
|
EVP_DigestFinal(ctx.get(), digest.data(), NULL);
|
||||||
return epee::to_hex::array(digest);
|
return epee::to_hex::array(digest);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -53,12 +53,12 @@
|
|||||||
#include <boost/spirit/include/qi_string.hpp>
|
#include <boost/spirit/include/qi_string.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <openssl/evp.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "md5_l.h"
|
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
|
|
||||||
@ -201,16 +201,16 @@ auth_responses parse_response(const http::http_response_info& response)
|
|||||||
|
|
||||||
std::string md5_hex(const std::string& in)
|
std::string md5_hex(const std::string& in)
|
||||||
{
|
{
|
||||||
md5::MD5_CTX ctx{};
|
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_new(), &EVP_MD_CTX_free);
|
||||||
md5::MD5Init(std::addressof(ctx));
|
EVP_DigestInit(ctx.get(), EVP_md5());
|
||||||
md5::MD5Update(
|
EVP_DigestUpdate(
|
||||||
std::addressof(ctx),
|
ctx.get(),
|
||||||
reinterpret_cast<const std::uint8_t*>(in.data()),
|
reinterpret_cast<const std::uint8_t*>(in.data()),
|
||||||
in.size()
|
in.size()
|
||||||
);
|
);
|
||||||
|
|
||||||
std::array<std::uint8_t, 16> digest{{}};
|
std::array<std::uint8_t, 16> digest{{}};
|
||||||
md5::MD5Final(digest.data(), std::addressof(ctx));
|
EVP_DigestFinal(ctx.get(), digest.data(), NULL);
|
||||||
return epee::string_tools::pod_to_hex(digest);
|
return epee::string_tools::pod_to_hex(digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user