Skip to content

Validate signature algorithm correctly#130

Merged
Sgtpluck merged 4 commits intomainfrom
dmm/simplify-validation
Jan 13, 2025
Merged

Validate signature algorithm correctly#130
Sgtpluck merged 4 commits intomainfrom
dmm/simplify-validation

Conversation

@Sgtpluck
Copy link
Copy Markdown

@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
Copy Markdown

@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
Copy Markdown
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:))
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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(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 }
Copy link
Copy Markdown

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
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated in 243163a

end

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

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
@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