From 1bbefca92e5a1608281b0a17ebdcc371b5338428 Mon Sep 17 00:00:00 2001 From: Sebastian Schuster Date: Mon, 20 Nov 2023 07:57:58 +0100 Subject: [PATCH] 24672 remove linebreaks from basicauth base64 encoding to comply to standard Signed-off-by: Sebastian Schuster --- core/src/main/java/org/keycloak/util/BasicAuthHelper.java | 8 ++------ .../test/java/org/keycloak/util/BasicAuthHelperTest.java | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/keycloak/util/BasicAuthHelper.java b/core/src/main/java/org/keycloak/util/BasicAuthHelper.java index d7e8d018c5..9a6091f297 100755 --- a/core/src/main/java/org/keycloak/util/BasicAuthHelper.java +++ b/core/src/main/java/org/keycloak/util/BasicAuthHelper.java @@ -33,11 +33,7 @@ import java.nio.charset.StandardCharsets; */ public class BasicAuthHelper { public static String createHeader(String username, String password) { - try { - return "Basic " + Base64.encodeBytes((username + ':' + password).getBytes(StandardCharsets.UTF_8), Base64.DO_BREAK_LINES); - } catch (IOException e) { - return null; - } + return "Basic " + Base64.encodeBytes((username + ':' + password).getBytes(StandardCharsets.UTF_8)); } public static String[] parseHeader(String header) { @@ -49,7 +45,7 @@ public class BasicAuthHelper { String val; try { - val = new String(Base64.decode(header.substring(6), Base64.DO_BREAK_LINES)); + val = new String(Base64.decode(header.substring(6))); } catch (IOException e) { return null; } diff --git a/core/src/test/java/org/keycloak/util/BasicAuthHelperTest.java b/core/src/test/java/org/keycloak/util/BasicAuthHelperTest.java index 2303f86c0b..82fe086491 100644 --- a/core/src/test/java/org/keycloak/util/BasicAuthHelperTest.java +++ b/core/src/test/java/org/keycloak/util/BasicAuthHelperTest.java @@ -9,10 +9,10 @@ public class BasicAuthHelperTest { @Test public void createHeader() { String username = "Aladdin"; - String password = "open sesame"; + String password = "open sesameopen sesameopen sesameopen sesameopen sesameopen sesame"; String actual = BasicAuthHelper.createHeader(username, password); - String expect = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="; + String expect = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZW9wZW4gc2VzYW1lb3BlbiBzZXNhbWVvcGVuIHNlc2FtZW9wZW4gc2VzYW1lb3BlbiBzZXNhbWU="; assertEquals(expect, actual); } @@ -20,7 +20,7 @@ public class BasicAuthHelperTest { @Test public void parseHeader() { String username = "Aladdin"; - String password = "open sesame"; + String password = "open sesameopen sesameopen sesameopen sesameopen sesameopen sesameopen sesame"; String header = BasicAuthHelper.createHeader(username, password); String[] actual = BasicAuthHelper.parseHeader(header);