From: Bingyin Zhang Date: Thu, 14 Dec 2017 08:03:36 +0000 (+0800) Subject: rgw: optimize time skew check X-Git-Tag: v12.2.5~143^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=413ed34d74bd758be7b55bd4fae2dabe82de9665;p=ceph.git rgw: optimize time skew check * Move query string check out of function is_time_skew_ok; Signed-off-by: Bingyin Zhang (cherry picked from commit 2c97b0ce8378dedef9296bd57273c0b9f1c1f440) --- diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 9c7eabbaeeb1..b3e8d637b1b3 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3671,16 +3671,15 @@ namespace rgw { namespace auth { namespace s3 { -bool AWSGeneralAbstractor::is_time_skew_ok(const utime_t& header_time, - const bool qsr) const +bool AWSGeneralAbstractor::is_time_skew_ok(const utime_t& header_time) const { /* Check for time skew first. */ const time_t req_sec = header_time.sec(); time_t now; time(&now); - if ((req_sec < now - RGW_AUTH_GRACE_MINS * 60 || - req_sec > now + RGW_AUTH_GRACE_MINS * 60) && !qsr) { + if (req_sec < now - RGW_AUTH_GRACE_MINS * 60 || + req_sec > now + RGW_AUTH_GRACE_MINS * 60) { ldout(cct, 10) << "req_sec=" << req_sec << " now=" << now << "; now - RGW_AUTH_GRACE_MINS=" << now - RGW_AUTH_GRACE_MINS * 60 @@ -3693,9 +3692,9 @@ bool AWSGeneralAbstractor::is_time_skew_ok(const utime_t& header_time, << " req_time=" << header_time << dendl; return false; - } else { - return true; } + + return true; } @@ -3968,7 +3967,7 @@ AWSGeneralAbstractor::get_auth_data_v2(const req_state* const s) const ldout(cct, 10) << "string_to_sign:\n" << rgw::crypt_sanitize::auth{s,string_to_sign} << dendl; - if (! is_time_skew_ok(header_time, qsr)) { + if (!qsr && !is_time_skew_ok(header_time)) { throw -ERR_REQUEST_TIME_SKEWED; } diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index d0aa098fa1b8..a515303f985b 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -767,8 +767,7 @@ public: class AWSGeneralAbstractor : public AWSEngine::VersionAbstractor { CephContext* const cct; - bool is_time_skew_ok(const utime_t& header_time, - const bool qsr) const; + bool is_time_skew_ok(const utime_t& header_time) const; virtual boost::optional get_v4_canonical_headers(const req_info& info,