#include <rapidjson/writer.h>
#include "rapidjson/error/error.h"
#include "rapidjson/error/en.h"
+#include <regex>
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rgw
}
}
+static bool validate_barbican_key_id(std::string_view key_id) {
+ // Barbican expects UUID4 secret ids.
+ // See barbican: common/utils.py, api/controllers/secrets.py
+ static const std::regex uuid_4_re{
+ R"(^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$)"};
+ return std::regex_match(key_id.data(), uuid_4_re);
+}
+
/**
* Determine if a string (url) ends with a given suffix.
* Must deal with (ignore) trailing slashes.
const std::string& barbican_token,
optional_yield y,
std::string& actual_key) {
+ if (!validate_barbican_key_id(key_id)) {
+ return -EINVAL;
+ }
+
int res;
CephContext* cct = dpp->get_cct();
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
+#include "gtest/gtest.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "common/ceph_context.h"
}
}
+class BarbicanKeyIdValidationTest
+ : public ::testing::TestWithParam<std::pair<std::string_view, bool>> {};
+
+TEST_P(BarbicanKeyIdValidationTest, ValidateKeyId) {
+ const auto ¶m = GetParam();
+ EXPECT_EQ(validate_barbican_key_id(param.first), param.second);
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ KeyIDTests, BarbicanKeyIdValidationTest,
+ ::testing::Values(
+ std::make_pair("asdf", false),
+ std::make_pair("cb6f82b2-aace-464f-bd50-c3103b97ad92", true),
+ std::make_pair("7cd71431-7f9b-5a2f-8215-126164bda0e4", true),
+ std::make_pair("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", false),
+ std::make_pair("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", false),
+ std::make_pair("", false),
+ std::make_pair("../cb6f82b2-aace-464f-bd50-c3103b97ad92", false),
+ std::make_pair("/cb6f82b2-aace-464f-bd50-c3103b97ad92", false),
+ std::make_pair("cb6f82b2/aace../464f-bd50-c3103b97ad92", false),
+ std::make_pair(" ", false)));
TEST_F(TestSSEKMS, string_ends_maybe_slash)
{