diff --git a/src/v/security/CMakeLists.txt b/src/v/security/CMakeLists.txt index 405ec27b79a28..58fceef252e4f 100644 --- a/src/v/security/CMakeLists.txt +++ b/src/v/security/CMakeLists.txt @@ -41,7 +41,6 @@ v_cc_library( v::rpc absl::flat_hash_map absl::flat_hash_set - cryptopp re2 gssapi_krb5 krb5 diff --git a/src/v/security/jwt.h b/src/v/security/jwt.h index e23c7ced2d490..4e1be855917bc 100644 --- a/src/v/security/jwt.h +++ b/src/v/security/jwt.h @@ -19,6 +19,7 @@ #include "security/oidc_error.h" #include "strings/string_switch.h" #include "strings/utf8.h" +#include "utils/base64.h" #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #include @@ -96,27 +96,14 @@ time_point(json::Value const& doc, std::string_view field) { } template -auto base64_url_decode(bytes_view sv) { - // TODO: Replace this with non-CryptoPP implementation - // TODO: https://github.com/redpanda-data/core-internal/issues/1132 - CryptoPP::Base64URLDecoder decoder; - - decoder.Put(sv.data(), sv.size()); - decoder.MessageEnd(); - - StringT decoded; - if (auto size = decoder.MaxRetrievable(); size != 0) { - decoded.resize(size); - decoder.Get( - reinterpret_cast(decoded.data()), decoded.size()); - } - return decoded; +auto base64_url_decode(std::string_view sv) { + return base64url_to_bytes(sv); }; template std::optional base64_url_decode(json::Value const& v, std::string_view field) { - auto b64 = string_view(v, field); + auto b64 = string_view<>(v, field); if (!b64.has_value()) { return std::nullopt; } @@ -445,9 +432,7 @@ inline result make_rs256_verifier(json::Value const& jwk) { } auto key = crypto::key::load_rsa_public_key(n.value(), e.value()); return verifier{rs256_verifier{std::move(key)}}; - } catch (CryptoPP::Exception const& ex) { - return errc::jwk_invalid; - } catch (crypto::exception const&) { + } catch (base64_url_decoder_exception&) { return errc::jwk_invalid; } } @@ -506,25 +491,26 @@ class verifier { // Verify the JWS signature and return the JWT result verify(jws const& jws) const { std::string_view sv(jws._encoded); - std::vector jose_enc; + std::vector jose_enc; jose_enc.reserve(3); boost::algorithm::split( jose_enc, - detail::char_view_cast(sv), + detail::char_view_cast(sv), [](char c) { return c == '.'; }); if (jose_enc.size() != 3) { return errc::jws_invalid_parts; } - constexpr auto make_dom = [](bytes_view bv) -> result { + constexpr auto make_dom = + [](std::string_view bv) -> result { try { auto bytes = detail::base64_url_decode(bv); auto str = detail::char_view_cast(bytes); json::Document dom; dom.Parse(str.data(), str.length()); return dom; - } catch (CryptoPP::Exception const& ex) { + } catch (base64_url_decoder_exception&) { return errc::jws_invalid_b64; } };