From: Radoslaw Zarzynski Date: Thu, 11 May 2017 12:48:10 +0000 (+0200) Subject: rgw: introduce rgw::auth::s3::AWS4_HMAC_SHA256_STR to kill magics. X-Git-Tag: v12.1.0~155^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a5a8b272ff261679246e50b39ff63e35ba7607e7;p=ceph.git rgw: introduce rgw::auth::s3::AWS4_HMAC_SHA256_STR to kill magics. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_auth_s3.cc b/src/rgw/rgw_auth_s3.cc index c02fb550218..d8113e6109d 100644 --- a/src/rgw/rgw_auth_s3.cc +++ b/src/rgw/rgw_auth_s3.cc @@ -331,9 +331,7 @@ static inline int parse_v4_credentials_hdrs(const req_info& info, /* i const char* const http_auth = info.env->get("HTTP_AUTHORIZATION"); string auth_str = http_auth; -#define AWS4_HMAC_SHA256_STR "AWS4-HMAC-SHA256" -#define CREDENTIALS_PREFIX_LEN (sizeof(AWS4_HMAC_SHA256_STR) - 1) - uint64_t min_len = CREDENTIALS_PREFIX_LEN + 1; + constexpr size_t min_len = strlen(AWS4_HMAC_SHA256_STR) + 1; if (auth_str.length() < min_len) { dout(10) << "credentials string is too short" << dendl; return -EINVAL; diff --git a/src/rgw/rgw_auth_s3.h b/src/rgw/rgw_auth_s3.h index 0d2a9608933..9d0cb129515 100644 --- a/src/rgw/rgw_auth_s3.h +++ b/src/rgw/rgw_auth_s3.h @@ -318,6 +318,8 @@ namespace rgw { namespace auth { namespace s3 { +static constexpr char AWS4_HMAC_SHA256_STR[] = "AWS4-HMAC-SHA256"; + static constexpr char AWS4_EMPTY_PAYLOAD_HASH[] = \ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 06c0417cc28..b6006114827 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3108,6 +3108,8 @@ enum class AwsRoute { static inline std::pair discover_aws_flavour(const req_info& info) { + using rgw::auth::s3::AWS4_HMAC_SHA256_STR; + AwsVersion version = AwsVersion::UNKOWN; AwsRoute route = AwsRoute::UNKOWN; @@ -3116,7 +3118,8 @@ discover_aws_flavour(const req_info& info) /* Authorization in Header */ route = AwsRoute::HEADERS; - if (!strncmp(http_auth, "AWS4-HMAC-SHA256", 16)) { + if (!strncmp(http_auth, AWS4_HMAC_SHA256_STR, + strlen(AWS4_HMAC_SHA256_STR))) { /* AWS v4 */ version = AwsVersion::V4; } else if (!strncmp(http_auth, "AWS ", 4)) { @@ -3126,7 +3129,7 @@ discover_aws_flavour(const req_info& info) } else { route = AwsRoute::QUERY_STRING; - if (info.args.get("X-Amz-Algorithm") == "AWS4-HMAC-SHA256") { + if (info.args.get("X-Amz-Algorithm") == AWS4_HMAC_SHA256_STR) { /* AWS v4 */ version = AwsVersion::V4; } else if (!info.args.get("AWSAccessKeyId").empty()) {