Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional ServiceProvider.SigningCertificate #26

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

samunro
Copy link

@samunro samunro commented Apr 5, 2019

I don't have much experience with SAML so please correct me if I have anything wrong.

From what I understand, signing requests that are sent to identity providers is optional (specific identity providers might require it).

The following guard clause in the HttpRedirectBindingBuilder.SigningKey setter seems to back this up - null is allowed.

                // Check if the key is of a supported type. [SAMLBind] sect. 3.4.4.1 specifies this.
                if (!(value is RSACryptoServiceProvider || value is DSA || value == null))
                {
                    throw new ArgumentException("Signing key must be an instance of either RSACryptoServiceProvider or DSA.");
                }

I was getting a null reference exception in this expression within SamlMessage.AuthnRequestForIdp() when I left the ServiceProvider's SigningCertificate property null.

SigningKey = config.ServiceProvider.SigningCertificate.PrivateKey,

My change will result in the SigningKey being set to null if the ServiceProvider's SigningCertificate is null.

The HttpRedirectBindingBuilder.SigningKey setter allows for null values.

                // Check if the key is of a supported type. [SAMLBind] sect. 3.4.4.1 specifies this.
                if (!(value is RSACryptoServiceProvider || value is DSA || value == null))
                {
                    throw new ArgumentException("Signing key must be an instance of either RSACryptoServiceProvider or DSA.");
                }

This expression which is used to assign to that property fails if the ServiceProvider does not have a SigningCertificate.

                    SigningKey = config.ServiceProvider.SigningCertificate.PrivateKey,

Added the Elvis operator to implement this.

                    SigningKey = config.ServiceProvider.SigningCertificate?.PrivateKey,
}
Copy link
Author

@samunro samunro Apr 5, 2019

Choose a reason for hiding this comment

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

Not sure where the newline came from. I even tried to reverse the change but I think that the web interface might add it in by default.

…nseChallengeAsync

The current default is currentUri which does not seem like the best choice if a value for RedirectAfterLogin is available.

I was expecting the browser to be redirected to RedirectAfterLogin post authentication but I actually saw an endless loop of authentications because it was redirecting to currentUri.
…s of type SecurityTokenServiceType and ApplicationServiceType which were not expected. There was a workaround which involved removing those but that also meant that the signature had to be removed. I added types which allows the metadata to be deserialized - even if there is no special handling for them.

The certificates in the SAML response were being passed in a way that the existing code did not expect. They are now parsed successfully.
…se it was a hash of the whole document that was being used instead of one based on just the assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant