Skip to content

Commit a9fb14e

Browse files
CopilotbgavrilMS
andcommitted
Add dSTS support - use SHA1 for dSTS authorities
- Update comments to explicitly mention dSTS as part of OIDC generic - Add test for dSTS authority to verify SHA1 is used - dSTS is already handled correctly as it's treated as OIDC authority - All 13 tests passing Co-authored-by: bgavrilMS <12273384+bgavrilMS@users.noreply.github.com>
1 parent 0a8d2be commit a9fb14e

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

msal/application.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,14 +855,14 @@ def _build_client(self, client_credential, authority, skip_regional_client=False
855855
# - ADFS: authority.is_adfs
856856
# - B2C: authority._is_b2c (and not OIDC)
857857
# - CIAM: authority._is_b2c (and not OIDC)
858-
# - OIDC generic: authority._is_oidc
858+
# - OIDC generic: authority._is_oidc (includes dSTS)
859859
# - AAD: everything else
860-
# Use SHA256 for AAD, B2C, CIAM; use SHA1 for ADFS and OIDC generic
860+
# Use SHA256 for AAD, B2C, CIAM; use SHA1 for ADFS, OIDC generic, and dSTS
861861
use_sha256 = False
862862
if sha256_thumbprint and sha1_thumbprint:
863863
# Both thumbprints provided - choose based on authority type
864864
is_oidc = getattr(authority, '_is_oidc', False)
865-
# Use SHA1 for ADFS and OIDC generic; SHA256 for everything else (AAD, B2C, CIAM)
865+
# Use SHA1 for ADFS, OIDC generic (including dSTS); SHA256 for everything else (AAD, B2C, CIAM)
866866
use_sha256 = not authority.is_adfs and not is_oidc
867867
elif sha256_thumbprint:
868868
# Only SHA256 provided

tests/test_optional_thumbprint.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,36 @@ def test_pem_with_both_thumbprints_generic_uses_sha1(
375375
expected_thumbprint_value=self.test_sha1_thumbprint
376376
)
377377

378+
def test_pem_with_both_thumbprints_dsts_uses_sha1(
379+
self, mock_jwt_creator_class, mock_authority_class):
380+
"""Test that with both thumbprints, dSTS authority uses SHA-1"""
381+
authority = "https://test-instance1-dsts.dsts.core.azure-test.net/dstsv2/common"
382+
mock_authority = self._setup_mocks(mock_authority_class, authority)
383+
384+
# Set up as a dSTS authority (dSTS is treated as OIDC)
385+
mock_authority.is_adfs = False
386+
mock_authority._is_b2c = True # OIDC sets this but it's not truly B2C
387+
mock_authority._is_oidc = True # dSTS is treated as OIDC generic
388+
389+
# Create app with BOTH thumbprints for dSTS authority
390+
app = ConfidentialClientApplication(
391+
client_id="my_client_id",
392+
client_credential={
393+
"private_key": self.test_private_key,
394+
"thumbprint": self.test_sha1_thumbprint,
395+
"thumbprint_sha256": self.test_sha256_thumbprint,
396+
},
397+
authority=authority
398+
)
399+
400+
# For dSTS authorities, should use SHA-1 when both are provided
401+
self._verify_assertion_params(
402+
mock_jwt_creator_class,
403+
expected_algorithm='RS256',
404+
expected_thumbprint_type='sha1',
405+
expected_thumbprint_value=self.test_sha1_thumbprint
406+
)
407+
378408
def test_pem_with_both_thumbprints_unknown_aad_uses_sha256(
379409
self, mock_jwt_creator_class, mock_authority_class):
380410
"""Test that with both thumbprints, unknown AAD authority (e.g., sovereign cloud) uses SHA-256"""

0 commit comments

Comments
 (0)