Blame SOURCES/0023-oidc_child-increase-wait-interval-by-5s-if-slow_down.patch

0034f4
From 55bfa944ad0197ae294d85ac42abf98297fa3a5d Mon Sep 17 00:00:00 2001
0034f4
From: Sumit Bose <sbose@redhat.com>
0034f4
Date: Thu, 18 Aug 2022 14:19:59 +0200
0034f4
Subject: [PATCH 23/24] oidc_child: increase wait interval by 5s if 'slow_down'
0034f4
 is returned
0034f4
MIME-Version: 1.0
0034f4
Content-Type: text/plain; charset=UTF-8
0034f4
Content-Transfer-Encoding: 8bit
0034f4
0034f4
While waiting for the user to authenticate with the IdP oidc_child
0034f4
currently only handles the error code 'authorization_pending' and waits
0034f4
for the given interval until a new request is send. But there is also
0034f4
'slow_down' which should not be treated as fatal error but should just
0034f4
increase the waiting time permanently for 5s.
0034f4
0034f4
Resolves: https://github.com/SSSD/sssd/issues/6146
0034f4
0034f4
Reviewed-by: Justin Stephenson <jstephen@redhat.com>
0034f4
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
0034f4
(cherry picked from commit 5ed7670766483040211713f8182510775c76b962)
0034f4
0034f4
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
0034f4
---
0034f4
 src/oidc_child/oidc_child_curl.c | 8 +++++++-
0034f4
 src/oidc_child/oidc_child_json.c | 6 ++++++
0034f4
 2 files changed, 13 insertions(+), 1 deletion(-)
0034f4
0034f4
diff --git a/src/oidc_child/oidc_child_curl.c b/src/oidc_child/oidc_child_curl.c
0034f4
index 6e80c3abf..cf0976021 100644
0034f4
--- a/src/oidc_child/oidc_child_curl.c
0034f4
+++ b/src/oidc_child/oidc_child_curl.c
0034f4
@@ -378,8 +378,14 @@ errno_t get_token(TALLOC_CTX *mem_ctx,
0034f4
             break;
0034f4
         }
0034f4
 
0034f4
-        sleep(dc_ctx->interval);
0034f4
         waiting_time += dc_ctx->interval;
0034f4
+        if (waiting_time >= dc_ctx->expires_in) {
0034f4
+            /* Next sleep will end after the request is expired on the
0034f4
+             * server side, so we can just error out now. */
0034f4
+            ret = ETIMEDOUT;
0034f4
+            break;
0034f4
+        }
0034f4
+        sleep(dc_ctx->interval);
0034f4
     } while (waiting_time < dc_ctx->expires_in);
0034f4
 
0034f4
     if (ret != EOK) {
0034f4
diff --git a/src/oidc_child/oidc_child_json.c b/src/oidc_child/oidc_child_json.c
0034f4
index efc1997aa..a89794c4c 100644
0034f4
--- a/src/oidc_child/oidc_child_json.c
0034f4
+++ b/src/oidc_child/oidc_child_json.c
0034f4
@@ -413,6 +413,12 @@ errno_t parse_token_result(struct devicecode_ctx *dc_ctx,
0034f4
         if (strcmp(json_string_value(tmp), "authorization_pending") == 0) {
0034f4
             json_decref(result);
0034f4
             return EAGAIN;
0034f4
+        } else if (strcmp(json_string_value(tmp), "slow_down") == 0) {
0034f4
+            /* RFC 8628: "... the interval MUST be increased by 5 seconds for"
0034f4
+             *           "this and all subsequent requests." */
0034f4
+            dc_ctx->interval += 5;
0034f4
+            json_decref(result);
0034f4
+            return EAGAIN;
0034f4
         } else {
0034f4
             *error_description = get_json_string(dc_ctx, result,
0034f4
                                                  "error_description");
0034f4
-- 
0034f4
2.37.3
0034f4