Skip to content

Commit

Permalink
Adds urldecoding of keys before padding the secret
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Oct 27, 2023
1 parent ce1bf31 commit dea110f
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -242,7 +243,7 @@ JWK createJwkFromSettings(Settings settings, Settings jwtSettings) throws Except
String exchangeKey = settings.get("exchange_key");

if (!Strings.isNullOrEmpty(exchangeKey)) {
exchangeKey = padSecret(exchangeKey, JWSAlgorithm.HS512);
exchangeKey = padSecret(new String(Base64.getDecoder().decode(exchangeKey), StandardCharsets.UTF_8), JWSAlgorithm.HS512);

return new OctetSequenceKey.Builder(exchangeKey.getBytes(StandardCharsets.UTF_8)).algorithm(JWSAlgorithm.HS512)
.keyUse(KeyUse.SIGNATURE)
Expand All @@ -256,7 +257,7 @@ JWK createJwkFromSettings(Settings settings, Settings jwtSettings) throws Except
);
}

String k = padSecret(jwkSettings.get("k"), JWSAlgorithm.HS512);
String k = padSecret(new String(Base64.getDecoder().decode(jwkSettings.get("k")), StandardCharsets.UTF_8), JWSAlgorithm.HS512);

return new OctetSequenceKey.Builder(k.getBytes(StandardCharsets.UTF_8)).algorithm(JWSAlgorithm.HS512)
.keyUse(KeyUse.SIGNATURE)
Expand Down

0 comments on commit dea110f

Please sign in to comment.