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

Set time directly on the x509 store #770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

segiddins
Copy link
Contributor

Instead of an ivar, so other ossl functions that take a store (such as OpenSSL::Timestamp::Response#verify) will use the correct time when verifying

@segiddins segiddins force-pushed the segiddins/set-time-directly-on-the-x509-store branch from b4ae6c4 to dca2ee8 Compare June 25, 2024 18:51
@segiddins segiddins marked this pull request as ready for review June 25, 2024 19:01
@segiddins segiddins force-pushed the segiddins/set-time-directly-on-the-x509-store branch 2 times, most recently from a508d5c to 2679889 Compare June 25, 2024 21:00
segiddins added a commit to sigstore/sigstore-ruby that referenced this pull request Jun 26, 2024
@segiddins
Copy link
Contributor Author

Unsure why that one build failed, @rhenium mind restarting it? Everything was green earlier

#if !HAVE_X509_STORE_GET0_PARAM
if (!X509_STORE_set1_param(store, param))
{
X509_VERIFY_PARAM_free(param);

Choose a reason for hiding this comment

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

JFYI; you may want to unconditionally call X509_VERIFY_PARAM_free, since X509_STORE_set1_param appears to perform a state copy rather than transfering ownership of the param that gets passed in. Consequently you may end up leaking memory in the "happy" case here.

(OpenSSL's docs are unclear on this, unfortunately -- this is from me tracing OpenSSL's x509_lu.c by hand.)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in OpenSSL's convension set0 is used for functions that transfer ownership, and set1 is used for those that copy contents or increment a reference counter.

#if HAVE_X509_STORE_GET0_PARAM
param = X509_STORE_get0_param(store);
#else
param = X509_VERIFY_PARAM_new();
Copy link
Member

Choose a reason for hiding this comment

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

Struct fields on X509_STORE (and in general) were part of public API in OpenSSL 1.0.2.

Suggested change
param = X509_VERIFY_PARAM_new();
param = store->param;

The X509_STORE_set1_param() call later will become unnecessary with this.

@@ -599,8 +614,6 @@ ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
sk_X509_pop_free(x509s, X509_free);
ossl_raise(eX509StoreError, "X509_STORE_CTX_init");
}
if (!NIL_P(t = rb_iv_get(store, "@time")))
ossl_x509stctx_set_time(self, t);
Copy link
Member

Choose a reason for hiding this comment

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

With this line removed, you can also remove the function prototype for ossl_x509stctx_set_time() above.

Instead of an ivar, so other ossl functions that take a store will use the correct time when verifying
@segiddins segiddins force-pushed the segiddins/set-time-directly-on-the-x509-store branch from 2679889 to 69c57f6 Compare June 27, 2024 18:21
@segiddins
Copy link
Contributor Author

@rhenium done!

segiddins added a commit to sigstore/sigstore-ruby that referenced this pull request Jun 27, 2024
Depends on ruby/openssl#770

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
segiddins added a commit to sigstore/sigstore-ruby that referenced this pull request Jun 28, 2024
Depends on ruby/openssl#770

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
segiddins added a commit to sigstore/sigstore-ruby that referenced this pull request Jun 28, 2024
Depends on ruby/openssl#770

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
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.

None yet

3 participants