Skip to content

Commit 85ce82d

Browse files
authored
Merge pull request #919 from rhenium/ky/x509store-storectx-current-cert-nil
x509store: fix StoreContext#current_cert
2 parents f7114e9 + 4149b43 commit 85ce82d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/openssl/ossl_x509store.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,14 @@ static VALUE
735735
ossl_x509stctx_get_curr_cert(VALUE self)
736736
{
737737
X509_STORE_CTX *ctx;
738+
X509 *x509;
738739

739740
GetX509StCtx(self, ctx);
741+
x509 = X509_STORE_CTX_get_current_cert(ctx);
742+
if (!x509)
743+
return Qnil;
740744

741-
return ossl_x509_new(X509_STORE_CTX_get_current_cert(ctx));
745+
return ossl_x509_new(x509);
742746
}
743747

744748
/*

test/openssl/test_x509store.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ def test_verify_simple
9191
assert_match(/ok/i, store.error_string)
9292
assert_equal(OpenSSL::X509::V_OK, store.error)
9393
assert_equal([ee1_cert, ca2_cert, ca1_cert], store.chain)
94+
95+
# Manually instantiated StoreContext
96+
# Nothing trusted
97+
store = OpenSSL::X509::Store.new
98+
ctx = OpenSSL::X509::StoreContext.new(store, ee1_cert)
99+
assert_nil(ctx.current_cert)
100+
assert_nil(ctx.current_crl)
101+
assert_equal(false, ctx.verify)
102+
assert_equal(OpenSSL::X509::V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, ctx.error)
103+
assert_equal(0, ctx.error_depth)
104+
assert_equal([ee1_cert], ctx.chain)
105+
assert_equal(ee1_cert, ctx.current_cert)
94106
end
95107

96108
def test_verify_callback

0 commit comments

Comments
 (0)