Skip to content

Commit 440618c

Browse files
POC for certificates/CRLs
1 parent b1c44db commit 440618c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ext/openssl/ossl_x509store.c

Lines changed: 23 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,23 @@ 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+
460+
certificates = rb_iv_get(self, "@certificates");
461+
462+
463+
if(RTEST(rb_funcall(certificates, rb_intern("include?"), 1, arg)))
464+
return self;
465+
454466
cert = GetX509CertPtr(arg); /* NO NEED TO DUP */
455467
GetX509Store(self, store);
456468
if (X509_STORE_add_cert(store, cert) != 1)
457469
ossl_raise(eX509StoreError, "X509_STORE_add_cert");
458470

471+
rb_ary_push(certificates, arg);
472+
459473
return self;
460474
}
461475

@@ -472,13 +486,22 @@ ossl_x509store_add_crl(VALUE self, VALUE arg)
472486
{
473487
X509_STORE *store;
474488
X509_CRL *crl;
489+
VALUE crls;
475490

476491
rb_check_frozen(self);
492+
493+
crls = rb_iv_get(self, "@crls");
494+
495+
if(RTEST(rb_funcall(crls, rb_intern("include?"), 1, arg)))
496+
return self;
497+
477498
crl = GetX509CRLPtr(arg); /* NO NEED TO DUP */
478499
GetX509Store(self, store);
479500
if (X509_STORE_add_crl(store, crl) != 1)
480501
ossl_raise(eX509StoreError, "X509_STORE_add_crl");
481502

503+
rb_ary_push(crls, arg);
504+
482505
return self;
483506
}
484507

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)