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

Validate signature algorithm correctly #130

Merged
merged 4 commits into from
Jan 13, 2025
Merged

Conversation

Sgtpluck
Copy link
Member

@Sgtpluck Sgtpluck commented Jan 2, 2025

This change is the follow-up to several weeks of tracking whether this change will impact any existing integrations. Running a query for the certs_different value does not produce any results, so it feels safe to move forward.

This change:

  • Updates the validate path in the XmlSecurity class to stop messing around with trying to match digests; since we have the certs saved in the database, we can just compare those certs to the request cert.
  • Allows the ValidationError for the wrong signature algorithm to be returned, rather than getting a more vague fingerprint_mismatch error.
  • Eliminates some code that has become redundant based on the changes


cert, error = valid_cert(cert_text)
if error.present?
def validate(idp_certificate, options = {}, soft: true)
Copy link

@zachmargolis zachmargolis Jan 2, 2025

Choose a reason for hiding this comment

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

In general, I think changing the type (fingerprint to certificate) of an argument is risky! Like if this was a public API we'd want to like bump a major version, etc etc

For this gem where we tightly control the usage, it's probably fine

Copy link
Member Author

Choose a reason for hiding this comment

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

oh agreed -- nothing that is called external to the gem actually changes (the XMLSecurity class is not called directly from the IdP -- IdP changes are all just updating the tests/removing the analytics code).

I thought about just ditching the validate method and updating the code to use validate_with_sha256 to avoid changing the type of an argument, but like you said, we control the usage, so it felt okay to do it this way.

Array(service_provider.certs).find do |cert|
document.valid_sig_with_sha256?(cert, options)
rescue SamlIdp::XMLSecurity::SignedDocument::ValidationError
document.valid_signature?(cert, options.merge(cert:))

Choose a reason for hiding this comment

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

we probably no longer need to pass in cert: as an option right?

Copy link
Member Author

@Sgtpluck Sgtpluck Jan 2, 2025

Choose a reason for hiding this comment

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

oh, yes, i think we don't need it any longer, since we're no longer using it as a backup

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 243163a

lib/saml_idp.rb Outdated
def gather_errors(fingerprint, options = {})
signed_document.validate(fingerprint, false, options)
def gather_errors(cert, options = {})
signed_document.validate(cert, options, soft: false)
rescue SamlIdp::XMLSecurity::SignedDocument::ValidationError => e
{ cert: options[:cert].serial.to_s, error_code: e.error_code }

Choose a reason for hiding this comment

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

if we remove passing in options[:cert] we can probably change this to be cert right?

Suggested change
{ cert: options[:cert].serial.to_s, error_code: e.error_code }
{ cert: cert.serial.to_s, error_code: e.error_code }

Copy link
Member Author

Choose a reason for hiding this comment

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

updated in 243163a


attr_accessor :document

def initialize(response)
@document = Nokogiri.XML(response)
end

def validate(idp_cert_fingerprint, soft = true, options = {})
log 'Validate the fingerprint'

Choose a reason for hiding this comment

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

Minor, but glad to see somewhat noisy log items going away

@Sgtpluck Sgtpluck merged commit bdf8e1f into main Jan 13, 2025
1 check passed
@Sgtpluck Sgtpluck deleted the dmm/simplify-validation branch January 13, 2025 14:41
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.

3 participants