From 00f2e36b84d6c37c254eb7bdb1445270b625a76b Mon Sep 17 00:00:00 2001 From: Guillaume Leroy Date: Sun, 24 Jul 2022 12:46:47 +0200 Subject: [PATCH] fix: fix base64 encoding chore: bump version to 1.5.1 ci(docker): use 1.5.1 as default version of keycloak-bcrypt --- .github/workflows/docker.yml | 2 +- build.gradle.kts | 2 +- .../keycloak/bcrypt/BCryptPasswordHashProvider.java | 13 ++++--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5e5905e..e9df488 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,7 +7,7 @@ on: keycloak_bcrypt_version: description: Keycloak BCrypt version required: true - default: 1.5.0 + default: 1.5.1 name: Docker diff --git a/build.gradle.kts b/build.gradle.kts index 300a985..aeb1c78 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.github.leroyguillaume" -version = "1.5.0" +version = "1.5.1" repositories { mavenCentral() diff --git a/src/main/java/com/github/leroyguillaume/keycloak/bcrypt/BCryptPasswordHashProvider.java b/src/main/java/com/github/leroyguillaume/keycloak/bcrypt/BCryptPasswordHashProvider.java index 6962a0f..312a441 100644 --- a/src/main/java/com/github/leroyguillaume/keycloak/bcrypt/BCryptPasswordHashProvider.java +++ b/src/main/java/com/github/leroyguillaume/keycloak/bcrypt/BCryptPasswordHashProvider.java @@ -38,9 +38,7 @@ public PasswordCredentialModel encodedCredential(final String rawPassword, final @Override public String encode(final String rawPassword, final int iterations) { final int cost = iterations == -1 ? defaultIterations : iterations; - final byte[] hash = BCrypt.with(BCrypt.Version.VERSION_2Y).hashToString(cost, rawPassword.toCharArray()) - .getBytes(); - return Base64.getEncoder().encodeToString(hash); + return BCrypt.with(BCrypt.Version.VERSION_2Y).hashToString(cost, rawPassword.toCharArray()); } @Override @@ -50,11 +48,8 @@ public void close() { @Override public boolean verify(final String rawPassword, final PasswordCredentialModel credential) { - final String base64EncodedHash = credential.getPasswordSecretData().getValue(); - final String base64DecodedHash = new String(Base64.getDecoder().decode(base64EncodedHash)); - - return BCrypt.verifyer(BCrypt.Version.VERSION_2Y) - .verify(rawPassword.toCharArray(), base64DecodedHash.toCharArray()) - .verified; + final String hash = credential.getPasswordSecretData().getValue(); + final BCrypt.Result verifier = BCrypt.verifyer().verify(rawPassword.toCharArray(), hash.toCharArray()); + return verifier.verified; } }