Merge pull request #4175 from mrezai/fix-pkce-s256-code-challenge
KEYCLOAK-4956: Fix incorrect PKCE S256 code challenge generation
This commit is contained in:
commit
f1132ffabe
2 changed files with 7 additions and 15 deletions
|
@ -560,13 +560,9 @@ public class TokenEndpoint {
|
||||||
// https://tools.ietf.org/html/rfc7636#section-4.6
|
// https://tools.ietf.org/html/rfc7636#section-4.6
|
||||||
private String generateS256CodeChallenge(String codeVerifier) throws Exception {
|
private String generateS256CodeChallenge(String codeVerifier) throws Exception {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
md.update(codeVerifier.getBytes());
|
md.update(codeVerifier.getBytes("ISO_8859_1"));
|
||||||
StringBuilder sb = new StringBuilder();
|
byte[] digestBytes = md.digest();
|
||||||
for (byte b : md.digest()) {
|
String codeVerifierEncoded = Base64Url.encode(digestBytes);
|
||||||
String hex = String.format("%02x", b);
|
|
||||||
sb.append(hex);
|
|
||||||
}
|
|
||||||
String codeVerifierEncoded = Base64Url.encode(sb.toString().getBytes());
|
|
||||||
return codeVerifierEncoded;
|
return codeVerifierEncoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,13 +444,9 @@ public class OAuthProofKeyForCodeExchangeTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
private String generateS256CodeChallenge(String codeVerifier) throws Exception {
|
private String generateS256CodeChallenge(String codeVerifier) throws Exception {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
md.update(codeVerifier.getBytes());
|
md.update(codeVerifier.getBytes("ISO_8859_1"));
|
||||||
StringBuilder sb = new StringBuilder();
|
byte[] digestBytes = md.digest();
|
||||||
for (byte b : md.digest()) {
|
String codeChallenge = Base64Url.encode(digestBytes);
|
||||||
String hex = String.format("%02x", b);
|
|
||||||
sb.append(hex);
|
|
||||||
}
|
|
||||||
String codeChallenge = Base64Url.encode(sb.toString().getBytes());
|
|
||||||
return codeChallenge;
|
return codeChallenge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue