Skip to content

Commit 9bcc630

Browse files
POC for certificates/CRLs
1 parent b1c44db commit 9bcc630

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/openssl/ossl_x509store.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
224224
rb_iv_set(self, "@error_string", Qnil);
225225
rb_iv_set(self, "@chain", Qnil);
226226

227+
/* added certificate/CRL references */
228+
rb_iv_set(self, "@certificates", rb_ary_new());
229+
rb_iv_set(self, "@crls", rb_ary_new());
230+
227231
return self;
228232
}
229233

@@ -449,13 +453,20 @@ ossl_x509store_add_cert(VALUE self, VALUE arg)
449453
{
450454
X509_STORE *store;
451455
X509 *cert;
456+
VALUE certificates;
452457

453458
rb_check_frozen(self);
459+
454460
cert = GetX509CertPtr(arg); /* NO NEED TO DUP */
455461
GetX509Store(self, store);
456462
if (X509_STORE_add_cert(store, cert) != 1)
457463
ossl_raise(eX509StoreError, "X509_STORE_add_cert");
458464

465+
certificates = rb_iv_get(self, "@certificates");
466+
467+
if(!RTEST(rb_funcall(certificates, rb_intern("include?"), 1, arg)))
468+
rb_ary_push(certificates, arg);
469+
459470
return self;
460471
}
461472

@@ -472,13 +483,20 @@ ossl_x509store_add_crl(VALUE self, VALUE arg)
472483
{
473484
X509_STORE *store;
474485
X509_CRL *crl;
486+
VALUE crls;
475487

476488
rb_check_frozen(self);
489+
477490
crl = GetX509CRLPtr(arg); /* NO NEED TO DUP */
478491
GetX509Store(self, store);
479492
if (X509_STORE_add_crl(store, crl) != 1)
480493
ossl_raise(eX509StoreError, "X509_STORE_add_crl");
481494

495+
crls = rb_iv_get(self, "@crls");
496+
497+
if(!RTEST(rb_funcall(crls, rb_intern("include?"), 1, arg)))
498+
rb_ary_push(crls, arg);
499+
482500
return self;
483501
}
484502

lib/openssl/x509.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ def ==(other)
333333
end
334334
end
335335

336+
class Store
337+
def freeze
338+
super
339+
@certificates.each(&:freeze)
340+
@crls.each(&:freeze)
341+
end
342+
end
343+
336344
class StoreContext
337345
def cleanup
338346
warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE

0 commit comments

Comments
 (0)