Skip to content

Conversation

@vi7us
Copy link

@vi7us vi7us commented Jun 24, 2025

As per request not to use SHA-1 algorithm for calculation of SHA-1 certificate thumbprint, this parameter is now optional and if not passed, is calculated inside the library itself.

@vi7us vi7us requested a review from a team as a code owner June 24, 2025 11:27
Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

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

Approved with comments. @rayluo for final sign-off

update as per discussion
and isinstance(client_credential.get('public_certificate'), str)
): # Then we treat the public_certificate value as PEM content
headers["x5c"] = extract_certs(client_credential['public_certificate'])
if sha256_thumbprint and not authority.is_adfs:
Copy link
Contributor

@rayluo rayluo Oct 30, 2025

Choose a reason for hiding this comment

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

@bgavrilMS , @vi7us ,

I was under the impression that this PR makes the usage of SHA-1 thumbprint parameter optional, by automatically calculating an SHA-1 thumbprint. But it ends up implicitly change the thumbprint-less code path to calculate an SHA256 instead.

  • Before this PR, the Subject Name / Issuer (SNI) code path sets only sha1_thrumbprint therefore @vi7us was NOT hitting this sha256_thumbprint code path here.

  • After @vi7us 's first commit with the new _extract_cert_and_thumbprints() helper calculating both sha1 and sha256, I believe this sha256_thumbprint code path becomes activated. This is a subtle behavior change, but not necessarily a bad thing. Previously, I wasn't sure whether/when Entra ID fully supports sha256, now @vi7us made the change and started using the sha256 thumbprint code path successfully, we can infer that Entra ID indeed fully supports {"algorithm": "PS256", "sha256_thumbprint": sha256_thumbprint} now.

Therefore, I refactored this PR so that it becomes clear that (1) when thumbprint parameter is used, it expects an SHA1 thumbprint (for backward compatibility and for ADFS scenario); (2) when the thumbprint parameter is absent, MSAL Python will use an SHA256 (rather than SHA1) thumbprint.

@vi7us , if at all possible, please test this now-rebased feature branch (you can back up your original feature branch if desirable). If there is no issue reported from your side, I'll merge in this refactored PR and ship it in our next release.

Choose a reason for hiding this comment

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

Previously, I wasn't sure whether/when Entra ID fully supports sha256... (1) when thumbprint parameter is used, it expects an SHA1 thumbprint (for backward compatibility and for ADFS scenario); (2) when the thumbprint parameter is absent, MSAL Python will use an SHA256 (rather than SHA1) thumbprint.

In case there were still any doubts, this is how Java and .NET currently work as well (SHA1 for ADFS, SHA256 for everything else):
AzureAD/microsoft-authentication-library-for-dotnet#4616
AzureAD/microsoft-authentication-library-for-java#840

@rayluo rayluo force-pushed the vitcurda/20250624/cert-thumbprint-made-optional branch from b7bfcff to 6cd9ebd Compare October 30, 2025 21:48
@rayluo rayluo force-pushed the vitcurda/20250624/cert-thumbprint-made-optional branch from 6cd9ebd to 433ad4b Compare October 31, 2025 17:57
@rayluo rayluo force-pushed the vitcurda/20250624/cert-thumbprint-made-optional branch 2 times, most recently from 06f137d to 709fea1 Compare October 31, 2025 18:08
)

# Determine thumbprints based on what's provided
if client_credential.get("thumbprint"):

Choose a reason for hiding this comment

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

Are there any tests covering this behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point! A new test file has been added in the modified commit. Please re-review.

@rayluo rayluo force-pushed the vitcurda/20250624/cert-thumbprint-made-optional branch from 709fea1 to 2c50ec4 Compare October 31, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants