Skip to content

Commit

Permalink
POC for certificates/CRLs
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed Nov 8, 2024
1 parent b1c44db commit 9bcc630
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ext/openssl/ossl_x509store.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
rb_iv_set(self, "@error_string", Qnil);
rb_iv_set(self, "@chain", Qnil);

/* added certificate/CRL references */
rb_iv_set(self, "@certificates", rb_ary_new());
rb_iv_set(self, "@crls", rb_ary_new());

return self;
}

Expand Down Expand Up @@ -449,13 +453,20 @@ ossl_x509store_add_cert(VALUE self, VALUE arg)
{
X509_STORE *store;
X509 *cert;
VALUE certificates;

rb_check_frozen(self);

cert = GetX509CertPtr(arg); /* NO NEED TO DUP */
GetX509Store(self, store);
if (X509_STORE_add_cert(store, cert) != 1)
ossl_raise(eX509StoreError, "X509_STORE_add_cert");

certificates = rb_iv_get(self, "@certificates");

if(!RTEST(rb_funcall(certificates, rb_intern("include?"), 1, arg)))
rb_ary_push(certificates, arg);

return self;
}

Expand All @@ -472,13 +483,20 @@ ossl_x509store_add_crl(VALUE self, VALUE arg)
{
X509_STORE *store;
X509_CRL *crl;
VALUE crls;

rb_check_frozen(self);

crl = GetX509CRLPtr(arg); /* NO NEED TO DUP */
GetX509Store(self, store);
if (X509_STORE_add_crl(store, crl) != 1)
ossl_raise(eX509StoreError, "X509_STORE_add_crl");

crls = rb_iv_get(self, "@crls");

if(!RTEST(rb_funcall(crls, rb_intern("include?"), 1, arg)))
rb_ary_push(crls, arg);

return self;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/openssl/x509.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ def ==(other)
end
end

class Store
def freeze
super
@certificates.each(&:freeze)
@crls.each(&:freeze)
end
end

class StoreContext
def cleanup
warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE
Expand Down

0 comments on commit 9bcc630

Please sign in to comment.