-
Notifications
You must be signed in to change notification settings - Fork 147
Remove and replace various com.nimbusds utils #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: avdunn/nimbus-removal
Are you sure you want to change the base?
Conversation
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ClientAssertion.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve with comments.
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ClientAssertion.java
Outdated
Show resolved
Hide resolved
String idTokenJson; | ||
|
||
try { | ||
idTokenJson = new String(Base64.getDecoder().decode(idToken.split("\\.")[1]), StandardCharsets.UTF_8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jwt's are base64url encoded, not base64. THis already results in a P1.
Can we add some tests around it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was mistakenly copied from a branch that had not yet been updated with the fix for the previous issue.
In the latest commit the logic both here and in TokenRequestExecutor
has been moved to a helper method in JsonHelper
, and new tests were added to confirm the behavior.
String idTokenJson; | ||
|
||
try { | ||
idTokenJson = new String(Base64.getDecoder().decode(idToken.split("\\.")[1]), StandardCharsets.UTF_8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very strange operation (extracting only the body). Why are you doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from similar code in TokenRequestExecutor, which had been parsing the body since that file was first added: https://github.com/AzureAD/microsoft-authentication-library-for-java/blame/bbdc93d59d54916cdbac4016f1b174822e9bb51c/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java#L123
An IdToken is created from the JSON of claims in the body: https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IdToken.java
I'm not sure exactly why just the body is decoded, however from some testing now it seems like Java's built-in base64 URL decoded cannot parse the signature so that may be why.
|
||
// Build header | ||
Map<String, Object> header = new HashMap<>(); | ||
header.put("alg", "RS256"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alg is PS256
not RS256
to suggest PSS padding instead of PKCS1 padding. Please have a look at the .NET code for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version of the library uses RS256 here, and has apparently done so since the 'sendX5C' API was first added in 2020 by PR #285:
Line 49 in 54f3d44
JWSHeader.Builder builder = new Builder(JWSAlgorithm.RS256); |
So this might need a more thorough investigation. Pretty much every integration test sends that "alg=RS256" header when retrieving the token to access ID labs, so the endpoint is either accepting or ignoring it.
|
||
// Decode and verify headers | ||
String headerJson = new String(Base64.getUrlDecoder().decode(jwtParts[0])); | ||
assertTrue(headerJson.contains("\"alg\":\"RS256\""), "Header should specify RS256 algorithm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be PS256 . RS256 means PKCS1 padding, which is not approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments have more context: #941 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PSS
…crosoft-authentication-library-for-java into avdunn/nimbus-utils # Conflicts: # msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/HelperAndUtilityTests.java
This PR removes various com.nimbusds helpers and utils, as per #909. In short, the following changes were made:
It also removes unused code in
IdToken
, and the unused classSAML11BearerGrant
(no longer needed due to the changes in #926)