-
-
Notifications
You must be signed in to change notification settings - Fork 566
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
base: v2.x
Are you sure you want to change the base?
Allow SP certificates to be OpenSSL::X509::Certificate #726
Conversation
@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. |
@johnnyshields unfortunately v2.x does not solve this. Using |
ok. Can you raise the PR to the v2.x branch then please? I will review it. |
lib/onelogin/ruby-saml/settings.rb
Outdated
def build_cert_object(cert) | ||
return cert if cert.is_a?(OpenSSL::X509::Certificate) | ||
|
||
OneLogin::RubySaml::Utils.build_cert_object(cert) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
c0b1dd7
to
603f97e
Compare
@johnnyshields I've rebased the branch onto v2.x |
lib/ruby_saml/settings.rb
Outdated
def build_cert_object(cert) | ||
return cert if cert.is_a?(OpenSSL::X509::Certificate) | ||
|
||
OneLogin::RubySaml::Utils.build_cert_object(cert) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!'
There was a problem hiding this comment.
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!
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 usingOneLogin::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 ofOpenSSL::X509::Certificate
. There are 3 ways to insert certs, all of them have been tested:Note that both deprecated interfaces
settings.get_sp_cert
andsettings.get_sp_cert_new
usesettings.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 andattr_accessor
for private access to ensure that certs are accessed viasettings.get_sp_certs
only (but that would break current interface).