You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I understand what happens.
Now, when the certificate has expired we set it to null in the CertificateDescription (this was done when implementing the certificate rotation). But Microsoft.IdentityModel does not accept a null certificate.
Jean-Marc Prieur (@jmprieur) I never tested this functionality before until we're getting close to renewing the decryption cert for one of our services. I was hopping to add the new cert as another decryption cert and switch it in the portal (first-party).
I pulled the new changes in master and I still see the same issue. I am using 2 decryption certificates. One of them is a valid certificate (used to encrypt) and another one that still valid but not used to encrypt the token. I see the API still returning 401 and I don't see any exceptions being logged. I think it's related to this issue with identityModel package that doesn't accept a list of decryption keys.
One of them is a valid decryption cert (where I have the .pfx installed in my local machine) and it can decrypt the token just fine, but when I add another cert (I also have the .pfx installed locally) to the list that's just any other cert the API start returning 401.
Only one cert can be configured in AAD, but I was assuming if we can have 2 certs and it will use the valid one. This can be useful to rotate the decryption certs without any downtime. We can add the new cert to the configuration, replace it in AAD, and remove the the old one from configuration.
Jean-Marc Prieur (@jmprieur) - Yes, this should work in IdentityModel >=6.8.0.
The library will try to decrypt a token using all decryption keys set on TokenValidationParameters.
jennyf19Jean-Marc Prieur (@jmprieur)
I am not sure how this was validated, but I just got a chance to test it because we have a decryption cert expiring in few weeks. I configured the function with a second decryption cert, and it looks like the library only try the first certificate to decrypt the cert! it is not using the second cert if the first one fails.
We have other services where we pass multiple certificates, and identity model will try to all the available keys to decrypt the cert
Activity
jmprieur commentedon Jun 7, 2021
Hussein Koprly (@husseinkorly) are you saying this is a regression?
jmprieur commentedon Jun 7, 2021
I think I understand what happens.
Now, when the certificate has expired we set it to null in the CertificateDescription (this was done when implementing the certificate rotation). But Microsoft.IdentityModel does not accept a null certificate.
We should only do the yield:
microsoft-identity-web/src/Microsoft.Identity.Web/CertificateManagement/DefaultCertificateLoader.cs
Line 307 in 37471e7
when
certDescription.Certificateis not nullhusseinkorly commentedon Jun 7, 2021
Jean-Marc Prieur (@jmprieur) I never tested this functionality before until we're getting close to renewing the decryption cert for one of our services. I was hopping to add the new cert as another decryption cert and switch it in the portal (first-party).
jmprieur commentedon Jun 7, 2021
jennyf19 is working on a fix.
Meanwhile, I think that version 1.9.2 should work fine in your case.
husseinkorly commentedon Jun 7, 2021
Thank you. I tried using version 1.9.2 but the API still failing to decrypt the token.
jmprieur commentedon Jun 7, 2021
Can you tell us more about the exception? https://github.com/AzureAD/microsoft-identity-web/wiki/Logging
husseinkorly commentedon Jun 7, 2021
I pulled the new changes in master and I still see the same issue. I am using 2 decryption certificates. One of them is a valid certificate (used to encrypt) and another one that still valid but not used to encrypt the token. I see the API still returning 401 and I don't see any exceptions being logged. I think it's related to this issue with identityModel package that doesn't accept a list of decryption keys.
jennyf19 commentedon Jun 7, 2021
Hussein Koprly (@husseinkorly) they both have to be decryption certs, not encryption certs. See this page ->
"usage": "Encrypt"if you're using a client credential certificate, like instead of a secret, a cert, it can go in the configuration.
husseinkorly commentedon Jun 7, 2021
Yes. I am only interested in the decryption cert I have both in the configuration like this for example:
One of them is a valid decryption cert (where I have the .pfx installed in my local machine) and it can decrypt the token just fine, but when I add another cert (I also have the .pfx installed locally) to the list that's just any other cert the API start returning 401.
jennyf19 commentedon Jun 7, 2021
Hussein Koprly (@husseinkorly) do both certs work independently? like one at a time, do they both work?
husseinkorly commentedon Jun 7, 2021
Only one cert can be configured in AAD, but I was assuming if we can have 2 certs and it will use the valid one. This can be useful to rotate the decryption certs without any downtime. We can add the new cert to the configuration, replace it in AAD, and remove the the old one from configuration.
jmprieur commentedon Jun 8, 2021
Hussein Koprly (@husseinkorly) : provided they are both decrypt certificates, this should work.
BrentSchmaltz (@brentschmaltz) George Krechar (@GeoK) Maria Furman (@mafurman) : we are using
TokenValidationParameters.TokenDecryptionKeys. Shouldn't it work?microsoft-identity-web/src/Microsoft.Identity.Web/WebApiExtensions/MicrosoftIdentityWebApiAuthenticationBuilderExtensions.cs
Line 222 in 6b506eb
GeoK commentedon Jun 8, 2021
Jean-Marc Prieur (@jmprieur) - Yes, this should work in IdentityModel >=6.8.0.
The library will try to decrypt a token using all decryption keys set on TokenValidationParameters.
jennyf19 commentedon Jun 11, 2021
Fixed in 1.13 release.
but seems to be an issue still with other components. Jean-Marc Prieur (@jmprieur)
jennyf19 commentedon Jun 23, 2021
Included in 1.14 release
husseinkorly commentedon Jan 4, 2022
jennyf19 Jean-Marc Prieur (@jmprieur)
I am not sure how this was validated, but I just got a chance to test it because we have a decryption cert expiring in few weeks. I configured the function with a second decryption cert, and it looks like the library only try the first certificate to decrypt the cert! it is not using the second cert if the first one fails.
We have other services where we pass multiple certificates, and identity model will try to all the available keys to decrypt the cert
I am using version 1.14.0