What happens when your Token Signing Certificate is about to Expire and how you can recover from the situation.
The infrastructure is similar to the following,
Successful Authentication flow,
Application Authentication page -> Redirects to ADFS Sign page – > Users enters the username and password -> Credentials is validated by ADFS server with the Identity provider -> Issues a SAML token back to the User on Successful verification -> User is then redirected back to the application page with a successful sign in.
The flow works until the SAML is being issued to the web page but Application will fail to validate it with an error message SAML_RESPONSE_INVALID
Token signing certificate
Some application responded may respond with the error SAML_RESPONSE_INVALID or some of them just ask the user for the credentials.
At this point we can confirm that SAML issued is invalid or wrong.
You might find on the internal ADFS servers Two certificates (Primary and secondary)
If your ADFS properties shows, (Get-ADFSProperties), the following
What happens is, The Token Signing certificate is set to auto-enroll exactly before 20 days of the existing certificate expiry date. After the generation of the new certificate, it automatically bring the new certificate as primary on the 5th Day.
As per the screenshot,
The certificate set to expire on 10/2/2019. 10/2/2019 – 20 days is 20/1/2019 as per AutoCertificateRollOver ADFS property. On 20th certificate got renewed as per CertificateGenerationThreshold Property. 20/1/2019 + 5 Days, the certificate switch happened as per CertificatePromotionThreshold.
Set the autoenrollment to false by running the cmdlet, Set-ADFSProperties -AutoCertificateRollover $False
From ADFS Console, choose the old certificate as primary by “Set as primary” (“Set as Primary” option is disabled until first step is completed)
NPS extension for MFA helps to make use of Azure MFA for on VPN connectivity. Although the documentation from Microsoft is straight forward to explain how that work and how to configure, we don’t have much information online.
Let’s assume that you have a Radius server as
I have configured Cisoco-ASA to use lab-DCRadius. On NPS server, I have configured CiscoASA as Radius client to access connection
Test the VPN using Cisco AnyConnect to LabVPN.Lab.com
From the following diagram, illustrate the flow. (The above said registry keys play the role of transferring the secondary Auth to Azure MFA)
Once you confirm that VPN is working,
Install the NPS extension from here, there are 2 version 22.214.171.124 & 126.96.36.199 (188.8.131.52 is available but on request to Microsoft)
To make sure Azure MFA accept the request from the NPS server,
Once you install it you have to run the script that comes with the NPS extension
Run Windows PowerShell as an administrator.
cd “C:\Program Files\Microsoft\AzureMfa\Config”
Run the PowerShell script created by the installer.
Sign in to Azure AD as an administrator.
PowerShell prompts for your tenant ID. Use the Directory ID GUID that you copied from the Azure portal in the prerequisites section.
PowerShell shows a success message when the script is finished.
What this does is it
Sets the registry with a some values
Creates a self-signed certificate on your server and uploade the certificate on Azure.
Open MMC -> File- > Add/Remove Snap-in-> Certificate -> Local Computer, Click Ok
Navigate to Certificates -> Personal – >Certificates
You will find a certificate with the tenant Id.
Go to the properties of the certificate, under details tab, look for Thumbprint, Copy it somewhere.
Now open Azure module for Windows PowerShell
Run the command in the screenshot
Copy the value in to a notepad and save it as .cer (if you have more than one cert, you might see more values. You have to copy each one of them in to a separate file and save it as .cer)
Now open the save .cer file.
Now under details tab, look for Thumbprint property.
Computer these 2 thumbprint and make sure they matches.
What if registration fails – This usually happens either if your AD account doesn’t have access to local certificate store or Azure portal (GA admin is the requirement to upload the cert)
How do I disable MFA on one of the NPS server to test it?
You can disable the MFA on NPS server. This is essential to find out when you are troubleshooting to narrow down which NPS server is having the issue. To disable the MFA on a NPS server without de-registering it,
Navigate to the registry key, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Serevice\AuthSrv\Parameters, Empty the following key values
This will stop the NPS to look for Secondary Auth
How to renew the certificate when it expires
The certificate usually has 2 years of validity. You can renew it by simply running AzureMfaNpsExtnConfigSetup.PS1
Recently, I have seen the ver. 184.108.40.206 is causing performance issue. There is a newer version which fixes the problem 220.127.116.11.