From 8c14002c2587f311bb8e13111a922ceca48b7450 Mon Sep 17 00:00:00 2001 From: wilsonianb Date: Mon, 20 Aug 2018 23:59:33 -0500 Subject: [PATCH] Do not use beast base64 encoding without fix: Boost 1.67 and 1.68 are missing this fix https://github.com/ripple/rippled/commit/0439dcfa7a5215cc74a8e254a28eadace6a524b7 --- CMakeLists.txt | 3 + src/ripple/app/misc/NetworkOPs.cpp | 2 +- src/ripple/app/misc/impl/Manifest.cpp | 8 +- src/ripple/app/misc/impl/ValidatorKeys.cpp | 4 +- src/ripple/app/misc/impl/ValidatorList.cpp | 8 +- src/ripple/app/misc/impl/ValidatorSite.cpp | 2 +- src/ripple/basics/base64.h | 81 +++++++ src/ripple/basics/impl/base64.cpp | 247 +++++++++++++++++++++ src/ripple/net/impl/RPCCall.cpp | 3 +- src/ripple/overlay/impl/OverlayImpl.cpp | 3 +- src/ripple/overlay/impl/TMHello.cpp | 14 +- src/ripple/rpc/impl/ServerHandlerImp.cpp | 4 +- src/ripple/unity/basics1.cpp | 1 + src/test/app/Manifest_test.cpp | 6 +- src/test/app/ValidatorKeys_test.cpp | 4 +- src/test/app/ValidatorList_test.cpp | 24 +- src/test/app/ValidatorSite_test.cpp | 4 +- src/test/basics/base64_test.cpp | 77 +++++++ src/test/jtx/TrustedPublisherServer.h | 4 +- src/test/rpc/ValidatorRPC_test.cpp | 4 +- src/test/server/ServerStatus_test.cpp | 5 +- src/test/unity/basics_test_unity.cpp | 1 + 22 files changed, 461 insertions(+), 48 deletions(-) create mode 100644 src/ripple/basics/base64.h create mode 100644 src/ripple/basics/impl/base64.cpp create mode 100644 src/test/basics/base64_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 323c88b25..6e7740b8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1082,6 +1082,7 @@ add_library (xrpl_core nounity, main sources: subdir: basics (partial) #]===============================] + src/ripple/basics/impl/base64.cpp src/ripple/basics/impl/contract.cpp src/ripple/basics/impl/CountedObject.cpp src/ripple/basics/impl/Log.cpp @@ -1179,6 +1180,7 @@ target_link_libraries (xrpl_core #]=================================] install ( FILES + src/ripple/basics/base64.h src/ripple/basics/Blob.h src/ripple/basics/Buffer.h src/ripple/basics/CountedObject.h @@ -1790,6 +1792,7 @@ target_sources (rippled PRIVATE src/test/basics/Slice_test.cpp src/test/basics/StringUtilities_test.cpp src/test/basics/TaggedCache_test.cpp + src/test/basics/base64_test.cpp src/test/basics/base_uint_test.cpp src/test/basics/contract_test.cpp src/test/basics/hardened_hash_test.cpp diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 2f29784f9..ded313bb9 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +56,6 @@ #include #include #include -#include #include #include diff --git a/src/ripple/app/misc/impl/Manifest.cpp b/src/ripple/app/misc/impl/Manifest.cpp index 56b15c036..f17dbfa92 100644 --- a/src/ripple/app/misc/impl/Manifest.cpp +++ b/src/ripple/app/misc/impl/Manifest.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -182,7 +182,7 @@ ValidatorToken::make_ValidatorToken(std::vector const& tokenBlob) for (auto const& line : tokenBlob) tokenStr += beast::rfc2616::trim(line); - tokenStr = boost::beast::detail::base64_decode(tokenStr); + tokenStr = base64_decode(tokenStr); Json::Reader r; Json::Value token; @@ -384,7 +384,7 @@ ManifestCache::load ( if (! configManifest.empty()) { auto mo = Manifest::make_Manifest ( - boost::beast::detail::base64_decode(configManifest)); + base64_decode(configManifest)); if (! mo) { JLOG (j_.error()) << "Malformed validator_token in config"; @@ -419,7 +419,7 @@ ManifestCache::load ( revocationStr += beast::rfc2616::trim(line); auto mo = Manifest::make_Manifest ( - boost::beast::detail::base64_decode(revocationStr)); + base64_decode(revocationStr)); if (! mo || ! mo->revoked() || applyManifest (std::move(*mo)) == ManifestDisposition::invalid) diff --git a/src/ripple/app/misc/impl/ValidatorKeys.cpp b/src/ripple/app/misc/impl/ValidatorKeys.cpp index 7f5d19fd6..a3a202a8b 100644 --- a/src/ripple/app/misc/impl/ValidatorKeys.cpp +++ b/src/ripple/app/misc/impl/ValidatorKeys.cpp @@ -20,10 +20,10 @@ #include #include +#include #include #include #include -#include namespace ripple { ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j) @@ -45,7 +45,7 @@ ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j) auto const pk = derivePublicKey( KeyType::secp256k1, token->validationSecret); auto const m = Manifest::make_Manifest( - boost::beast::detail::base64_decode(token->manifest)); + base64_decode(token->manifest)); if (! m || pk != m->signingKey) { diff --git a/src/ripple/app/misc/impl/ValidatorList.cpp b/src/ripple/app/misc/impl/ValidatorList.cpp index a6da63dc2..d9470a496 100644 --- a/src/ripple/app/misc/impl/ValidatorList.cpp +++ b/src/ripple/app/misc/impl/ValidatorList.cpp @@ -18,12 +18,12 @@ //============================================================================== #include +#include #include #include #include #include #include -#include #include #include @@ -291,7 +291,7 @@ ValidatorList::applyList ( for (auto const& valManifest : manifests) { auto m = Manifest::make_Manifest ( - boost::beast::detail::base64_decode(valManifest)); + base64_decode(valManifest)); if (! m || ! keyListings_.count (m->masterKey)) { @@ -321,7 +321,7 @@ ValidatorList::verify ( std::string const& blob, std::string const& signature) { - auto m = Manifest::make_Manifest (boost::beast::detail::base64_decode(manifest)); + auto m = Manifest::make_Manifest (base64_decode(manifest)); if (! m || ! publisherLists_.count (m->masterKey)) return ListDisposition::untrusted; @@ -342,7 +342,7 @@ ValidatorList::verify ( return ListDisposition::untrusted; auto const sig = strUnHex(signature); - auto const data = boost::beast::detail::base64_decode (blob); + auto const data = base64_decode (blob); if (! sig.second || ! ripple::verify ( publisherManifests_.getSigningKey(pubKey), diff --git a/src/ripple/app/misc/impl/ValidatorSite.cpp b/src/ripple/app/misc/impl/ValidatorSite.cpp index 01a6695bc..7e35a2343 100644 --- a/src/ripple/app/misc/impl/ValidatorSite.cpp +++ b/src/ripple/app/misc/impl/ValidatorSite.cpp @@ -21,10 +21,10 @@ #include #include #include +#include #include #include #include -#include #include namespace ripple { diff --git a/src/ripple/basics/base64.h b/src/ripple/basics/base64.h new file mode 100644 index 000000000..516b588b3 --- /dev/null +++ b/src/ripple/basics/base64.h @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012-2018 Ripple Labs Inc. + + 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. +*/ +//============================================================================== + +// +// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +/* + Portions from http://www.adp-gmbh.ch/cpp/common/base64.html + Copyright notice: + + base64.cpp and base64.h + + Copyright (C) 2004-2008 René Nyffenegger + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + + 3. This notice may not be removed or altered from any source distribution. + + René Nyffenegger rene.nyffenegger@adp-gmbh.ch + +*/ + +#ifndef RIPPLE_BASICS_BASE64_H_INCLUDED +#define RIPPLE_BASICS_BASE64_H_INCLUDED + +#include + +namespace ripple { + +std::string +base64_encode (std::uint8_t const* data, + std::size_t len); + +inline +std::string +base64_encode(std::string const& s) +{ + return base64_encode (reinterpret_cast < + std::uint8_t const*> (s.data()), s.size()); +} + +std::string +base64_decode(std::string const& data); + +} // ripple + +#endif diff --git a/src/ripple/basics/impl/base64.cpp b/src/ripple/basics/impl/base64.cpp new file mode 100644 index 000000000..c13eece48 --- /dev/null +++ b/src/ripple/basics/impl/base64.cpp @@ -0,0 +1,247 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012-2018 Ripple Labs Inc. + + 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. +*/ +//============================================================================== + +// +// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +/* + Portions from http://www.adp-gmbh.ch/cpp/common/base64.html + Copyright notice: + + base64.cpp and base64.h + + Copyright (C) 2004-2008 René Nyffenegger + + This source code is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this source code must not be misrepresented; you must not + claim that you wrote the original source code. If you use this source code + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original source code. + + 3. This notice may not be removed or altered from any source distribution. + + René Nyffenegger rene.nyffenegger@adp-gmbh.ch + +*/ + +#include + +#include +#include + +namespace ripple { + +namespace base64 { + +inline +char const* +get_alphabet() +{ + static char constexpr tab[] = { + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + }; + return &tab[0]; +} + +inline +signed char const* +get_inverse() +{ + static signed char constexpr tab[] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0-15 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16-31 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // 32-47 + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 48-63 + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79 + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 80-95 + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111 + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, // 112-127 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 128-143 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 144-159 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160-175 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 176-191 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 192-207 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 208-223 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 224-239 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // 240-255 + }; + return &tab[0]; +} + + +/// Returns max chars needed to encode a base64 string +inline +std::size_t constexpr +encoded_size(std::size_t n) +{ + return 4 * ((n + 2) / 3); +} + +/// Returns max bytes needed to decode a base64 string +inline +std::size_t constexpr +decoded_size(std::size_t n) +{ + return ((n / 4) * 3) + 2; +} + +/** Encode a series of octets as a padded, base64 string. + + The resulting string will not be null terminated. + + @par Requires + + The memory pointed to by `out` points to valid memory + of at least `encoded_size(len)` bytes. + + @return The number of characters written to `out`. This + will exclude any null termination. +*/ +std::size_t +encode(void* dest, void const* src, std::size_t len) +{ + char* out = static_cast(dest); + char const* in = static_cast(src); + auto const tab = base64::get_alphabet(); + + for(auto n = len / 3; n--;) + { + *out++ = tab[ (in[0] & 0xfc) >> 2]; + *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)]; + *out++ = tab[((in[2] & 0xc0) >> 6) + ((in[1] & 0x0f) << 2)]; + *out++ = tab[ in[2] & 0x3f]; + in += 3; + } + + switch(len % 3) + { + case 2: + *out++ = tab[ (in[0] & 0xfc) >> 2]; + *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)]; + *out++ = tab[ (in[1] & 0x0f) << 2]; + *out++ = '='; + break; + + case 1: + *out++ = tab[ (in[0] & 0xfc) >> 2]; + *out++ = tab[((in[0] & 0x03) << 4)]; + *out++ = '='; + *out++ = '='; + break; + + case 0: + break; + } + + return out - static_cast(dest); +} + +/** Decode a padded base64 string into a series of octets. + + @par Requires + + The memory pointed to by `out` points to valid memory + of at least `decoded_size(len)` bytes. + + @return The number of octets written to `out`, and + the number of characters read from the input string, + expressed as a pair. +*/ +std::pair +decode(void* dest, char const* src, std::size_t len) +{ + char* out = static_cast(dest); + auto in = reinterpret_cast(src); + unsigned char c3[3], c4[4]; + int i = 0; + int j = 0; + + auto const inverse = base64::get_inverse(); + + while(len-- && *in != '=') + { + auto const v = inverse[*in]; + if(v == -1) + break; + ++in; + c4[i] = v; + if(++i == 4) + { + c3[0] = (c4[0] << 2) + ((c4[1] & 0x30) >> 4); + c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2); + c3[2] = ((c4[2] & 0x3) << 6) + c4[3]; + + for(i = 0; i < 3; i++) + *out++ = c3[i]; + i = 0; + } + } + + if(i) + { + c3[0] = ( c4[0] << 2) + ((c4[1] & 0x30) >> 4); + c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2); + c3[2] = ((c4[2] & 0x3) << 6) + c4[3]; + + for(j = 0; j < i - 1; j++) + *out++ = c3[j]; + } + + return {out - static_cast(dest), + in - reinterpret_cast(src)}; +} + +} // base64 + +std::string +base64_encode (std::uint8_t const* data, + std::size_t len) +{ + std::string dest; + dest.resize(base64::encoded_size(len)); + dest.resize(base64::encode(&dest[0], data, len)); + return dest; +} + +std::string +base64_decode(std::string const& data) +{ + std::string dest; + dest.resize(base64::decoded_size(data.size())); + auto const result = base64::decode( + &dest[0], data.data(), data.size()); + dest.resize(result.first); + return dest; +} + +} // ripple diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index b73af1570..82fa88893 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1523,7 +1524,7 @@ void fromNetwork ( } // HTTP basic authentication - auto const auth = boost::beast::detail::base64_encode(strUsername + ":" + strPassword); + auto const auth = base64_encode(strUsername + ":" + strPassword); std::map mapRequestHeaders; diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index 08b11eb6e..a56c08f88 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -764,7 +765,7 @@ OverlayImpl::crawl() for_each ([&](std::shared_ptr&& sp) { auto& pv = av.append(Json::Value(Json::objectValue)); - pv[jss::public_key] = boost::beast::detail::base64_encode( + pv[jss::public_key] = base64_encode( sp->getNodePublic().data(), sp->getNodePublic().size()); pv[jss::type] = sp->slot()->inbound() ? diff --git a/src/ripple/overlay/impl/TMHello.cpp b/src/ripple/overlay/impl/TMHello.cpp index 98d12f2a2..a2bbaf1ee 100644 --- a/src/ripple/overlay/impl/TMHello.cpp +++ b/src/ripple/overlay/impl/TMHello.cpp @@ -20,10 +20,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -152,7 +152,7 @@ appendHello (boost::beast::http::fields& h, h.insert ("Public-Key", hello.nodepublic()); - h.insert ("Session-Signature", boost::beast::detail::base64_encode ( + h.insert ("Session-Signature", base64_encode ( hello.nodeproof())); if (hello.has_nettime()) @@ -162,11 +162,11 @@ appendHello (boost::beast::http::fields& h, h.insert ("Ledger", std::to_string (hello.ledgerindex())); if (hello.has_ledgerclosed()) - h.insert ("Closed-Ledger", boost::beast::detail::base64_encode ( + h.insert ("Closed-Ledger", base64_encode ( hello.ledgerclosed())); if (hello.has_ledgerprevious()) - h.insert ("Previous-Ledger", boost::beast::detail::base64_encode ( + h.insert ("Previous-Ledger", base64_encode ( hello.ledgerprevious())); if (hello.has_local_ip_str()) @@ -251,7 +251,7 @@ parseHello (bool request, boost::beast::http::fields const& h, beast::Journal jo if (iter == h.end()) return boost::none; // TODO Security Review - hello.set_nodeproof (boost::beast::detail::base64_decode (iter->value().to_string())); + hello.set_nodeproof (base64_decode (iter->value().to_string())); } { @@ -286,13 +286,13 @@ parseHello (bool request, boost::beast::http::fields const& h, beast::Journal jo { auto const iter = h.find ("Closed-Ledger"); if (iter != h.end()) - hello.set_ledgerclosed (boost::beast::detail::base64_decode (iter->value().to_string())); + hello.set_ledgerclosed (base64_decode (iter->value().to_string())); } { auto const iter = h.find ("Previous-Ledger"); if (iter != h.end()) - hello.set_ledgerprevious (boost::beast::detail::base64_decode (iter->value().to_string())); + hello.set_ledgerprevious (base64_decode (iter->value().to_string())); } { diff --git a/src/ripple/rpc/impl/ServerHandlerImp.cpp b/src/ripple/rpc/impl/ServerHandlerImp.cpp index 1d8f56c5e..7f8456360 100644 --- a/src/ripple/rpc/impl/ServerHandlerImp.cpp +++ b/src/ripple/rpc/impl/ServerHandlerImp.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -39,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -97,7 +97,7 @@ authorized ( return false; std::string strUserPass64 = it->second.substr (6); boost::trim (strUserPass64); - std::string strUserPass = boost::beast::detail::base64_decode (strUserPass64); + std::string strUserPass = base64_decode (strUserPass64); std::string::size_type nColon = strUserPass.find (":"); if (nColon == std::string::npos) return false; diff --git a/src/ripple/unity/basics1.cpp b/src/ripple/unity/basics1.cpp index 3d85e2228..f72f71030 100644 --- a/src/ripple/unity/basics1.cpp +++ b/src/ripple/unity/basics1.cpp @@ -18,6 +18,7 @@ //============================================================================== +#include #include #include #include diff --git a/src/test/app/Manifest_test.cpp b/src/test/app/Manifest_test.cpp index 393db0afb..ce79319f3 100644 --- a/src/test/app/Manifest_test.cpp +++ b/src/test/app/Manifest_test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -123,7 +123,7 @@ public: Serializer s; st.add(s); - return boost::beast::detail::base64_encode (std::string( + return base64_encode (std::string( static_cast (s.data()), s.size())); } @@ -176,7 +176,7 @@ public: Serializer s; st.add(s); - return boost::beast::detail::base64_encode (std::string( + return base64_encode (std::string( static_cast (s.data()), s.size())); } diff --git a/src/test/app/ValidatorKeys_test.cpp b/src/test/app/ValidatorKeys_test.cpp index 99a0ebdfe..115972140 100644 --- a/src/test/app/ValidatorKeys_test.cpp +++ b/src/test/app/ValidatorKeys_test.cpp @@ -19,10 +19,10 @@ #include #include +#include #include #include #include -#include #include namespace ripple { @@ -91,7 +91,7 @@ public: derivePublicKey(KeyType::secp256k1, tokenSecretKey); auto const m = Manifest::make_Manifest( - boost::beast::detail::base64_decode(tokenManifest)); + base64_decode(tokenManifest)); BEAST_EXPECT(m); NodeID const tokenNodeID = calcNodeID(m->masterKey); diff --git a/src/test/app/ValidatorList_test.cpp b/src/test/app/ValidatorList_test.cpp index 16553c0fa..7ca68aab1 100644 --- a/src/test/app/ValidatorList_test.cpp +++ b/src/test/app/ValidatorList_test.cpp @@ -17,10 +17,10 @@ */ //============================================================================== -#include +#include +#include #include #include -#include #include #include #include @@ -89,7 +89,7 @@ private: derivePublicKey(KeyType::ed25519, secret); auto const signingKeys = randomKeyPair(KeyType::secp256k1); return { masterPublic, signingKeys.first, - boost::beast::detail::base64_encode(makeManifestString ( + base64_encode(makeManifestString ( masterPublic, secret, signingKeys.first, signingKeys.second, 1)) }; } @@ -112,7 +112,7 @@ private: data.pop_back(); data += "]}"; - return boost::beast::detail::base64_encode(data); + return base64_encode(data); } std::string @@ -120,7 +120,7 @@ private: std::string const& blob, std::pair const& keys) { - auto const data = boost::beast::detail::base64_decode (blob); + auto const data = base64_decode (blob); return strHex(sign( keys.first, keys.second, makeSlice(data))); } @@ -374,7 +374,7 @@ private: auto const publisherPublic = derivePublicKey(KeyType::ed25519, publisherSecret); auto const pubSigningKeys1 = randomKeyPair(KeyType::secp256k1); - auto const manifest1 = boost::beast::detail::base64_encode(makeManifestString ( + auto const manifest1 = base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys1.first, pubSigningKeys1.second, 1)); @@ -426,7 +426,7 @@ private: } // do not use list from untrusted publisher - auto const untrustedManifest = boost::beast::detail::base64_encode( + auto const untrustedManifest = base64_encode( makeManifestString ( randomMasterKey(), publisherSecret, pubSigningKeys1.first, pubSigningKeys1.second, 1)); @@ -473,7 +473,7 @@ private: // apply list with new publisher key updated by manifest auto const pubSigningKeys2 = randomKeyPair(KeyType::secp256k1); - auto manifest2 = boost::beast::detail::base64_encode(makeManifestString ( + auto manifest2 = base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys2.first, pubSigningKeys2.second, 2)); @@ -497,7 +497,7 @@ private: // do not apply list with revoked publisher key // applied list is removed due to revoked publisher key auto const signingKeysMax = randomKeyPair(KeyType::secp256k1); - auto maxManifest = boost::beast::detail::base64_encode(makeManifestString ( + auto maxManifest = base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys2.first, pubSigningKeys2.second, std::numeric_limits::max ())); @@ -747,7 +747,7 @@ private: std::vector emptyCfgKeys; auto const publisherKeys = randomKeyPair(KeyType::secp256k1); auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1); - auto const manifest = boost::beast::detail::base64_encode ( + auto const manifest = base64_encode ( makeManifestString ( publisherKeys.first, publisherKeys.second, pubSigningKeys.first, pubSigningKeys.second, 1)); @@ -917,7 +917,7 @@ private: auto const publisherPublic = derivePublicKey(KeyType::ed25519, publisherSecret); auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1); - auto const manifest = boost::beast::detail::base64_encode(makeManifestString ( + auto const manifest = base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys.first, pubSigningKeys.second, 1)); @@ -1021,7 +1021,7 @@ private: auto const publisherPublic = derivePublicKey(KeyType::ed25519, publisherSecret); auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1); - auto const manifest = boost::beast::detail::base64_encode(makeManifestString ( + auto const manifest = base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys.first, pubSigningKeys.second, 1)); diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index ebc60a08c..327e127cc 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include namespace ripple { namespace test { @@ -67,7 +67,7 @@ private: Serializer s; st.add(s); - return boost::beast::detail::base64_encode (std::string( + return base64_encode (std::string( static_cast (s.data()), s.size())); } diff --git a/src/test/basics/base64_test.cpp b/src/test/basics/base64_test.cpp new file mode 100644 index 000000000..5d367ed37 --- /dev/null +++ b/src/test/basics/base64_test.cpp @@ -0,0 +1,77 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012-2018 Ripple Labs Inc. + + 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. +*/ +//============================================================================== + +// +// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#include +#include + +namespace ripple { + +class base64_test : public beast::unit_test::suite +{ +public: + void + check (std::string const& in, std::string const& out) + { + auto const encoded = base64_encode (in); + BEAST_EXPECT(encoded == out); + BEAST_EXPECT(base64_decode (encoded) == in); + } + + void + run() override + { + check ("", ""); + check ("f", "Zg=="); + check ("fo", "Zm8="); + check ("foo", "Zm9v"); + check ("foob", "Zm9vYg=="); + check ("fooba", "Zm9vYmE="); + check ("foobar", "Zm9vYmFy"); + + check( + "Man is distinguished, not only by his reason, but by this singular passion from " + "other animals, which is a lust of the mind, that by a perseverance of delight " + "in the continued and indefatigable generation of knowledge, exceeds the short " + "vehemence of any carnal pleasure." + , + "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" + "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" + "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu" + "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo" + "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" + ); + + std::string const notBase64 = "not_base64!!"; + std::string const truncated = "not"; + BEAST_EXPECT(base64_decode(notBase64) == base64_decode(truncated)); + } +}; + +BEAST_DEFINE_TESTSUITE(base64, ripple_basics, ripple); + +} // ripple diff --git a/src/test/jtx/TrustedPublisherServer.h b/src/test/jtx/TrustedPublisherServer.h index ccc0ac1ba..3fb916cda 100644 --- a/src/test/jtx/TrustedPublisherServer.h +++ b/src/test/jtx/TrustedPublisherServer.h @@ -22,10 +22,10 @@ #include #include #include +#include #include #include #include -#include #include namespace ripple { @@ -80,7 +80,7 @@ public: } data.pop_back(); data += "]}"; - std::string blob = boost::beast::detail::base64_encode(data); + std::string blob = base64_encode(data); list_ = "{\"blob\":\"" + blob + "\""; diff --git a/src/test/rpc/ValidatorRPC_test.cpp b/src/test/rpc/ValidatorRPC_test.cpp index 6052e2c77..67466dec3 100644 --- a/src/test/rpc/ValidatorRPC_test.cpp +++ b/src/test/rpc/ValidatorRPC_test.cpp @@ -19,12 +19,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include @@ -75,7 +75,7 @@ class ValidatorRPC_test : public beast::unit_test::suite Serializer s; st.add(s); - return boost::beast::detail::base64_encode( + return base64_encode( std::string(static_cast(s.data()), s.size())); } diff --git a/src/test/server/ServerStatus_test.cpp b/src/test/server/ServerStatus_test.cpp index 8bc81f13b..99749c987 100644 --- a/src/test/server/ServerStatus_test.cpp +++ b/src/test/server/ServerStatus_test.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -553,7 +554,7 @@ class ServerStatus_test : doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); - auth.set("Authorization", "Basic " + boost::beast::detail::base64_encode("me:badpass")); + auth.set("Authorization", "Basic " + base64_encode("me:badpass")); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); @@ -569,7 +570,7 @@ class ServerStatus_test : // finally if we use the correct user/pass encoded, we should get a 200 auth.set("Authorization", "Basic " + - boost::beast::detail::base64_encode(user + ":" + pass)); + base64_encode(user + ":" + pass)); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); BEAST_EXPECT(resp.result() == boost::beast::http::status::ok); BEAST_EXPECT(! resp.body().empty()); diff --git a/src/test/unity/basics_test_unity.cpp b/src/test/unity/basics_test_unity.cpp index a711181dd..d9b3409b6 100644 --- a/src/test/unity/basics_test_unity.cpp +++ b/src/test/unity/basics_test_unity.cpp @@ -18,6 +18,7 @@ */ //============================================================================== +#include #include #include #include