FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JCL-385: Improve PKCE verifier to always produce spec conforming values by acoburn · Pull Request #517 · inrupt/solid-client-java · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • PKCE.java
      • PKCETest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
public final class PKCE {

private static final BigInteger PADDING = BigInteger.valueOf(2).pow(256);

/**
* Create a PKCE challenge value using the S256 algorithm.
*
Expand Down Expand Up @@ -73,7 +75,7 @@ static String createChallenge(final String verifier, final String alg) {
* @return the Base64URL-encoded verifier
*/
static String createVerifier() {
final byte[] rand = new BigInteger(32 * 8, new SecureRandom()).toByteArray();
final byte[] rand = PADDING.add(new BigInteger(32 * 8, new SecureRandom())).toByteArray();
return Base64.getUrlEncoder().withoutPadding().encodeToString(rand);
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package com.inrupt.client.openid;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -30,16 +29,16 @@ class PKCETest {

@Test
void createChallengeTest() {
assertTrue(PKCE.createChallenge("🐶🐶🐶", "SHA-256").getBytes(UTF_8).length >= 43);
assertTrue(PKCE.createChallenge("🐶🐶🐶", "SHA-256").getBytes(UTF_8).length <= 128);
assertTrue(PKCE.createChallenge("", "SHA-256").getBytes(UTF_8).length >= 43);
assertTrue(PKCE.createChallenge("", "SHA-256").getBytes(UTF_8).length <= 128);
assertTrue(PKCE.createChallenge("🐶🐶🐶", "SHA-256").length() >= 43);
Comment on lines -36 to +32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

For my own understanding, was the .getBytes(UTF_8) useful in the first place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, the getBytes test was unnecessary. The spec requires checking the character length of the resulting string, not the size of the byte array. Admittedly, for ASCII strings, the two will be equivalent, but it is unnecessary

assertTrue(PKCE.createChallenge("🐶🐶🐶", "SHA-256").length() <= 128);
assertTrue(PKCE.createChallenge("", "SHA-256").length() >= 43);
assertTrue(PKCE.createChallenge("", "SHA-256").length() <= 128);
assertThrows(NullPointerException.class, () -> PKCE.createChallenge(null, "SHA-256"));
}

@Test
void createVerifierTest() {
assertTrue(PKCE.createVerifier().getBytes(UTF_8).length >= 43);
assertTrue(PKCE.createVerifier().getBytes(UTF_8).length <= 128);
assertTrue(PKCE.createVerifier().length() >= 43);
assertTrue(PKCE.createVerifier().length() <= 128);
}
}

Back | FazBrowse Home | New Git URL