Hi,
For SP initiated SSO, I’ve built an IdP app to process the Auth Request and send back the SAML assertion as response. However when process the Auth Request by following the steps below, but failed to verify the signature.
- Receive the authn request over HTTP-Redirect.
- Identify the SP from the issuer field in the authn request.
- Verify the HTTP-Redirect signature.
From IdP app:
X509Certificate2 spCertificate = LoadCertificate(spCertPath, spPassword);
HTTPRedirectBinding.ReceiveRequest(Request, out authnRequestXml, out relayState, out signatureAlgorithm, out signature);
string issuerName = Issuer.GetIssuerName(authnRequestXml);
HTTPRedirectBinding.VerifyRequestSignature(Request, signatureAlgorithm, signature, publicKey);
From the SP side, I’ve implemented the following method to sign the query string:
private static string SignQueryString(string queryString, AsymmetricAlgorithm key, string signatureAlgorithm)
{
byte[] dataToSign = Encoding.UTF8.GetBytes(queryString);
HashAlgorithmName hashAlgorithm = GetHashAlgorithmName(signatureAlgorithm);
byte[] hash;
using (var hasher = HashAlgorithm.Create(hashAlgorithm.Name))
{
hash = hasher?.ComputeHash(dataToSign);
}
if (key is RSA rsa)
{
byte[] signature = rsa.SignHash(hash, hashAlgorithm, RSASignaturePadding.Pkcs1);
return Convert.ToBase64String(signature);
}
throw new InvalidOperationException("Unsupported key type for RSA signing.");
}
I am getting the failed to verify signature on HTTP redirect message.
[SAMLSignatureException: Failed to verify signature on HTTP redirect message.]
ComponentSpace.SAML2.Bindings.HTTPRedirectBinding.CheckSignature(String redirectURL, String encodedSignature, String messageQueryName, AsymmetricAlgorithm key, String signatureAlgorithm) in C:\Sandboxes\ComponentSpace\SAMLv20\Library\Bindings\HTTPRedirectBinding.cs:568
ComponentSpace.SAML2.Bindings.HTTPRedirectBinding.VerifyRequestSignature(HttpRequestBase httpRequest, String signatureAlgorithm, String signature, AsymmetricAlgorithm key) in C:\Sandboxes\ComponentSpace\SAMLv20\Library\Bindings\HTTPRedirectBinding.cs:1096
I’ve checked the signature, after urldecode(), it matches to the one generated on SP side and use the public key from SP certificate to verify the signature. What could be the issue in here? What else can I check?