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

Allow SP certificates to be OpenSSL::X509::Certificate #726

Open
wants to merge 3 commits into
base: v2.x
Choose a base branch
from

Conversation

tobiasamft
Copy link

@tobiasamft tobiasamft commented Oct 3, 2024

This allows settings to accept instances of OpenSSL::X509::Certificate as service provider (SP) certificates.

Solves #723

Version 1.16.0 was, at least partially, able to handle OpenSSL::X509::Certificate as input for settings.certificate (e.g. when using OneLogin::RubySaml::Response).

Since settings.get_sp_certs is the only interface that is used to access certificates, it should be enough to test that interface with instances of OpenSSL::X509::Certificate. There are 3 ways to insert certs, all of them have been tested:

  • settings.certificate
  • settings.certificate_new
  • settings.sp_cert_multi

Note that both deprecated interfaces settings.get_sp_cert and settings.get_sp_cert_new use settings.get_sp_certs internally. Thus, they are covered as well.

Same approach could be used for SP private key to accept OpenSSL::PKey.
Maybe it's a good idea to make all certificates from settings attr_writer for public and attr_accessor for private access to ensure that certs are accessed via settings.get_sp_certs only (but that would break current interface).

@johnnyshields
Copy link
Collaborator

@tobiasamft can you check if this is solved on the v2.x branch? I think it might be already. If it is, we can close this PR b/c we are releasing v2.x soon.

@tobiasamft
Copy link
Author

@johnnyshields unfortunately v2.x does not solve this. Using OpenSSL::X509::Certificate as SP certificate still crashes with the following:
git/ruby-saml/lib/ruby_saml/settings.rb:377:in 'validate_sp_certs_params!': undefined method 'empty?' for an instance of OpenSSL::X509::Certificate (NoMethodError)

@johnnyshields
Copy link
Collaborator

ok. Can you raise the PR to the v2.x branch then please? I will review it.

@tobiasamft tobiasamft changed the base branch from master to v2.x October 4, 2024 06:42
@tobiasamft tobiasamft changed the base branch from v2.x to master October 4, 2024 06:45
def build_cert_object(cert)
return cert if cert.is_a?(OpenSSL::X509::Certificate)

OneLogin::RubySaml::Utils.build_cert_object(cert)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not adapt directly the Utils.build_cert_object to be able to handle string and OpenSSL::X509::Certificate?

Copy link
Author

@tobiasamft tobiasamft Oct 4, 2024

Choose a reason for hiding this comment

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

Yes, I was thinking about that, too. But then I decided to catch the problem as early as possible. And if it's fixed in Utils, it creates kind of a dependency. Utils would fix problems that come from Settings. Settings would not correctly work on it's own without changing Utils.

This allows settings to accept instances of OpenSSL::X509::Certificate
as service provider (SP) certificates.
@tobiasamft tobiasamft changed the base branch from master to v2.x October 4, 2024 08:17
@tobiasamft tobiasamft force-pushed the allow-openssl-certificate-instances branch from c0b1dd7 to 603f97e Compare October 4, 2024 08:17
@tobiasamft
Copy link
Author

@johnnyshields I've rebased the branch onto v2.x

def build_cert_object(cert)
return cert if cert.is_a?(OpenSSL::X509::Certificate)

OneLogin::RubySaml::Utils.build_cert_object(cert)
Copy link
Collaborator

@johnnyshields johnnyshields Oct 8, 2024

Choose a reason for hiding this comment

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

let's just change this method in OneLogin::RubySaml::Utils to return a cert if one is given as an argument (it should be "idempotent")

Same with RubySaml::Utils.build_private_key_object

Copy link
Author

Choose a reason for hiding this comment

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

👍 Your code, your decision 😄 Will change that.

@johnnyshields
Copy link
Collaborator

@tobiasamft see comment

Return the original certificate from Utils.build_cert_object when an
instance of OpenSSL::X509::Certificate is given. And return the original
key from Utils.build_private_key_object when an instance of
OpenSSL::PKey::PKey is given.
return true if cert.is_a?(OpenSSL::X509::Certificate)

cert && !cert.empty?
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

all changes in this file can be rolled back

Copy link
Author

@tobiasamft tobiasamft Oct 8, 2024

Choose a reason for hiding this comment

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

Without it we get the initial NoMethodError again (because validate_sp_certs_params is called before Utils.build_cert_object):

NoMethodError: undefined method `empty?' for an instance of OpenSSL::X509::Certificate
    lib/ruby_saml/settings.rb:377:in `validate_sp_certs_params!'

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK I will check this later, thanks!

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