From 26952b94efa67c839b90d0de75546bb6e4674924 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Thu, 13 Apr 2017 18:32:29 +0200 Subject: [PATCH] rgw: dissect AWSv4's Canonical URI crafting into a separated function. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_auth_s3.h | 17 +++++++++++++++++ src/rgw/rgw_rest_s3.cc | 14 +------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/rgw/rgw_auth_s3.h b/src/rgw/rgw_auth_s3.h index b4a85c016dbc..f81559097497 100644 --- a/src/rgw/rgw_auth_s3.h +++ b/src/rgw/rgw_auth_s3.h @@ -159,6 +159,23 @@ namespace rgw { namespace auth { namespace s3 { + +static inline std::string get_v4_canonical_uri(const req_info& info) { + /* The code should normalize according to RFC 3986 but S3 does NOT do path + * normalization that SigV4 typically does. This code follows the same + * approach that boto library. See auth.py:canonical_uri(...). */ + + std::string canonical_uri = info.request_uri_aws4; + + if (canonical_uri.empty()) { + canonical_uri = "/"; + } else { + boost::replace_all(canonical_uri, "+", "%20"); + } + + return canonical_uri; +} + std::string hash_string_sha256(const char* data, int len); std::string get_v4_canonical_request_hash(CephContext* cct, diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 77d8d00a4d80..4541b9f9c231 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3746,21 +3746,9 @@ int RGW_Auth_S3::authorize_v4(RGWRados *store, struct req_state *s, bool force_b */ /* craft canonical uri */ - - /* here code should normalize via rfc3986 but S3 does **NOT** do path normalization - * that SigV4 typically does. this code follows the same approach that boto library - * see auth.py:canonical_uri(...) */ - - s->aws4_auth->canonical_uri = s->info.request_uri_aws4; - - if (s->aws4_auth->canonical_uri.empty()) { - s->aws4_auth->canonical_uri = "/"; - } else { - boost::replace_all(s->aws4_auth->canonical_uri, "+", "%20"); - } + s->aws4_auth->canonical_uri = rgw::auth::s3::get_v4_canonical_uri(s->info); /* craft canonical query string */ - s->aws4_auth->canonical_qs = s->info.request_params; if (!s->aws4_auth->canonical_qs.empty()) { -- 2.47.3