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

Add Marshal support to X509 objects #281

Merged
merged 1 commit into from
Oct 29, 2019
Merged

Conversation

bdewater
Copy link
Contributor

@bdewater bdewater commented Oct 26, 2019

This allows for example to use Rails' cache to store these objects. Without this patch you'd get errors like TypeError (no _dump_data is defined for class OpenSSL::X509::Certificate).

Note that the X509::Revoked class doesn't need the newly introduced modules as the DER output of X509::CRL already includes these.

https://ruby-doc.org/core-2.6.5/Marshal.html

@ioquatix
Copy link
Member

Rather than tacking the specs onto existing ones, do you think it would be a good idea to make them separate? I don't really mind, just back at you - what do you think?

@bdewater
Copy link
Contributor Author

You're right, that is cleaner (and was a bit lazy on my part). Changed it!

@ioquatix
Copy link
Member

I only have one other question. Is it canonical to use two separate modules to do this? Are there any other examples of Ruby code which do the same thing?

@@ -151,6 +151,11 @@ def test_eq
assert_equal false, req1 == req3
end

def test_marshal
req = issue_csr(0, @dn, @rsa1024, "sha256")
assert_equal req, Marshal.load(Marshal.dump(req))
Copy link

@grzuy grzuy Oct 28, 2019

Choose a reason for hiding this comment

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

Most tests are only testing that dump and load are reverse operations.

Would it help to have a test actually testing that it dumps to a string?
If not, you would have green tests by changing the implementation to anything that keeps operations reverse, like both being the "identity" operation e.g., right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it help to have a test actually testing that it dumps to a string?

Maybe I'm misunderstanding but I don't think we really care about the intermediate format, but more about the fact that the deserialized object is equal to the one we had before serializing it. The current way relies on the equality tests covering that, but I can add some of that to the marshal tests as an extra sanity check.

Copy link

Choose a reason for hiding this comment

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

Fair enough 👍

@bdewater
Copy link
Contributor Author

I only have one other question. Is it canonical to use two separate modules to do this? Are there any other examples of Ruby code which do the same thing?

_load needs to be a class method, but I can change it to this as well so it's a single include line:

module Marshal
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    def _load(string)
      new(string)
    end
  end

  def _dump(_level)
    to_der
  end
end

@bdewater
Copy link
Contributor Author

Addressed both bits of feedback.

This allows for example to use Rails' cache to store these objects. Without this patch you'd get errors like "TypeError (no _dump_data is defined for class OpenSSL::X509::Certificate)"

Note that the X509::Revoked class doesn't need the newly introduced modules as the DER output of X509::CRL already includes these.
@ioquatix ioquatix merged commit feb6d2c into ruby:master Oct 29, 2019
@bdewater bdewater deleted the marshal-x509 branch November 1, 2019 02:40
@mperham
Copy link

mperham commented Apr 18, 2020

Is there a way to tell which Ruby versions have a given OpenSSL PR like this one?

mperham pushed a commit to sidekiq/sidekiq that referenced this pull request Apr 18, 2020
#4532)

In 3f9c4bf the Redis connection options began to be cloned (via dumping
and re-marshalling) to avoid issues with password redaction in logging
altering the connection options and breaking authentication with Sentinels.

Unfortunately, this change caused an exception on boot for users of
Redis over SSL. The `OpenSSL::X509::Store` object used for SSL certs is
not yet dumpable in the bundled OpenSSL wrapper for current Rubies
(although it does in master as of ruby/openssl#281).

The fix here prunes the `ssl_params` options out of the Redis
configuration options before the dumping and marshalling. It's probably
better not to include those in logging anyway for privacy purposes.

Fix #4531
@bdewater
Copy link
Contributor Author

bdewater commented Apr 18, 2020

@mperham this is in 2.8.0 trunk AFAIK, gem version 2.2.0 hasn't been released yet. I think a defined?(OpenSSL::X509::Marshal) ought to do the trick so you're not dependant on a version number?

@mperham
Copy link

mperham commented Apr 18, 2020 via email

@bdewater
Copy link
Contributor Author

Not right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants