Skip to content

Commit 75ad316

Browse files
rgw: Update buffer size for HMAC signature and improve signature max size calculation
Move SIGNATURE_MAX_SIZE to public interface of AWSEngine::VersionAbstractor Use SIGNATURE_MAX_SIZE to size buffer in get_v2_signature Fixes: https://tracker.ceph.com/issues/72442 Signed-off-by: Edwin Rodriguez <[email protected]>
1 parent bafdbd6 commit 75ad316

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/rgw/rgw_auth_s3.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,12 +1024,13 @@ get_v2_signature(CephContext* const cct,
10241024

10251025
const auto digest = calc_hmac_sha1(secret_key, string_to_sign);
10261026

1027-
/* 64 is really enough */;
1028-
char buf[64];
1029-
const int ret = ceph_armor(std::begin(buf),
1030-
std::begin(buf) + 64,
1031-
reinterpret_cast<const char *>(digest.v),
1032-
reinterpret_cast<const char *>(digest.v + digest.SIZE));
1027+
/* Sized for signature */;
1028+
char buf[AWSEngine::VersionAbstractor::SIGNATURE_MAX_SIZE];
1029+
const int ret = ceph_armor(
1030+
std::begin(buf),
1031+
std::begin(buf) + AWSEngine::VersionAbstractor::SIGNATURE_MAX_SIZE,
1032+
reinterpret_cast<const char*>(digest.v),
1033+
reinterpret_cast<const char*>(digest.v + digest.SIZE));
10331034
if (ret < 0) {
10341035
ldout(cct, 10) << "ceph_armor failed" << dendl;
10351036
throw ret;

src/rgw/rgw_rest_s3.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,13 +939,14 @@ class AWSEngine : public rgw::auth::Engine {
939939
static constexpr size_t DIGEST_SIZE_V2 = CEPH_CRYPTO_HMACSHA1_DIGESTSIZE;
940940
static constexpr size_t DIGEST_SIZE_V4 = CEPH_CRYPTO_HMACSHA256_DIGESTSIZE;
941941

942+
public:
943+
942944
/* Knowing the signature max size allows us to employ the sstring, and thus
943945
* avoid dynamic allocations. The multiplier comes from representing digest
944946
* in the base64-encoded form. */
945947
static constexpr size_t SIGNATURE_MAX_SIZE = \
946948
std::max(DIGEST_SIZE_V2, DIGEST_SIZE_V4) * 2 + sizeof('\0');
947949

948-
public:
949950
virtual ~VersionAbstractor() {};
950951

951952
using access_key_id_t = std::string_view;

0 commit comments

Comments
 (0)