Skip to content

Commit eb7bb6d

Browse files
authored
Merge pull request #842 from rhenium/ky/ts-use-TS_VERIFY_CTX_set0_certs
ts: use TS_VERIFY_CTX_set0_{store,certs}() on OpenSSL 3.4
2 parents 6a48f7c + ce37f7d commit eb7bb6d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

ext/openssl/extconf.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ def find_openssl_library
144144
# added in 3.0.0
145145
have_func("SSL_set0_tmp_dh_pkey(NULL, NULL)", ssl_h)
146146
have_func("ERR_get_error_all(NULL, NULL, NULL, NULL, NULL)", "openssl/err.h")
147-
have_func("TS_VERIFY_CTX_set_certs(NULL, NULL)", ts_h)
148147
have_func("SSL_CTX_load_verify_file(NULL, \"\")", ssl_h)
149148
have_func("BN_check_prime(NULL, NULL, NULL)", "openssl/bn.h")
150149
have_func("EVP_MD_CTX_get0_md(NULL)", evp_h)
151150
have_func("EVP_MD_CTX_get_pkey_ctx(NULL)", evp_h)
152151
have_func("EVP_PKEY_eq(NULL, NULL)", evp_h)
153152
have_func("EVP_PKEY_dup(NULL)", evp_h)
154153

154+
# added in 3.4.0
155+
have_func("TS_VERIFY_CTX_set0_certs(NULL, NULL)", ts_h)
156+
155157
Logging::message "=== Checking done. ===\n"
156158

157159
# Append flags from environment variables.

ext/openssl/openssl_missing.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
#include "ruby/config.h"
1414

1515
/* added in 3.0.0 */
16-
#if !defined(HAVE_TS_VERIFY_CTX_SET_CERTS)
17-
# define TS_VERIFY_CTX_set_certs(ctx, crts) TS_VERIFY_CTS_set_certs(ctx, crts)
18-
#endif
19-
2016
#ifndef HAVE_EVP_MD_CTX_GET0_MD
2117
# define EVP_MD_CTX_get0_md(ctx) EVP_MD_CTX_md(ctx)
2218
#endif

ext/openssl/ossl_ts.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,16 +855,26 @@ ossl_ts_resp_verify(int argc, VALUE *argv, VALUE self)
855855
X509_up_ref(cert);
856856
}
857857

858+
if (!X509_STORE_up_ref(x509st)) {
859+
sk_X509_pop_free(x509inter, X509_free);
860+
TS_VERIFY_CTX_free(ctx);
861+
ossl_raise(eTimestampError, "X509_STORE_up_ref");
862+
}
863+
864+
#ifdef HAVE_TS_VERIFY_CTX_SET0_CERTS
865+
TS_VERIFY_CTX_set0_certs(ctx, x509inter);
866+
TS_VERIFY_CTX_set0_store(ctx, x509st);
867+
#else
868+
# if OSSL_OPENSSL_PREREQ(3, 0, 0) || OSSL_IS_LIBRESSL
858869
TS_VERIFY_CTX_set_certs(ctx, x509inter);
859-
TS_VERIFY_CTX_add_flags(ctx, TS_VFY_SIGNATURE);
870+
# else
871+
TS_VERIFY_CTS_set_certs(ctx, x509inter);
872+
# endif
860873
TS_VERIFY_CTX_set_store(ctx, x509st);
874+
#endif
875+
TS_VERIFY_CTX_add_flags(ctx, TS_VFY_SIGNATURE);
861876

862877
ok = TS_RESP_verify_response(ctx, resp);
863-
/*
864-
* TS_VERIFY_CTX_set_store() call above does not increment the reference
865-
* counter, so it must be unset before TS_VERIFY_CTX_free() is called.
866-
*/
867-
TS_VERIFY_CTX_set_store(ctx, NULL);
868878
TS_VERIFY_CTX_free(ctx);
869879

870880
if (!ok)

0 commit comments

Comments
 (0)