13 #define WrapX509Store(klass, obj, st) do { \ 15 ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \ 17 (obj) = Data_Wrap_Struct((klass), 0, X509_STORE_free, (st)); \ 19 #define GetX509Store(obj, st) do { \ 20 Data_Get_Struct((obj), X509_STORE, (st)); \ 22 ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \ 25 #define SafeGetX509Store(obj, st) do { \ 26 OSSL_Check_Kind((obj), cX509Store); \ 27 GetX509Store((obj), (st)); \ 30 #define WrapX509StCtx(klass, obj, ctx) do { \ 32 ossl_raise(rb_eRuntimeError, "STORE_CTX wasn't initialized!"); \ 34 (obj) = Data_Wrap_Struct((klass), 0, ossl_x509stctx_free, (ctx)); \ 36 #define GetX509StCtx(obj, ctx) do { \ 37 Data_Get_Struct((obj), X509_STORE_CTX, (ctx)); \ 39 ossl_raise(rb_eRuntimeError, "STORE_CTX is out of scope!"); \ 42 #define SafeGetX509StCtx(obj, storep) do { \ 43 OSSL_Check_Kind((obj), cX509StoreContext); \ 44 GetX509Store((obj), (ctx)); \ 83 CRYPTO_add(&store->references, 1, CRYPTO_LOCK_X509_STORE);
97 if((store = X509_STORE_new()) ==
NULL){
133 store->ex_data.sk =
NULL;
137 #if (OPENSSL_VERSION_NUMBER < 0x00907000L) 155 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 160 X509_STORE_set_flags(store,
f);
171 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 176 X509_STORE_set_purpose(store,
p);
187 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 192 X509_STORE_set_trust(store, t);
228 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
230 if(X509_LOOKUP_load_file(lookup, path, X509_FILETYPE_PEM) != 1){
249 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
251 if(X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1){
274 if (X509_STORE_set_default_paths(store) != 1){
296 if (X509_STORE_add_cert(store, cert) != 1){
311 if (X509_STORE_add_crl(store, crl) != 1){
332 rb_iv_set(ctx,
"@verify_callback", proc);
373 sk_X509_pop_free(ctx->untrusted, X509_free);
375 X509_free(ctx->cert);
376 X509_STORE_CTX_free(ctx);
385 if((ctx = X509_STORE_CTX_new()) ==
NULL){
401 VALUE store, cert, chain, t;
411 if(!
NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
412 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 413 if(X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
414 sk_X509_pop_free(x509s, X509_free);
418 X509_STORE_CTX_init(ctx, x509st, x509, x509s);
439 (
void*)
rb_iv_get(
self,
"@verify_callback"));
440 result = X509_verify_cert(ctx);
455 if((chain = X509_STORE_CTX_get_chain(ctx)) ==
NULL){
458 if((num = sk_X509_num(chain)) < 0){
463 for(
i = 0;
i < num;
i++) {
464 x509 = sk_X509_value(chain,
i);
478 return INT2FIX(X509_STORE_CTX_get_error(ctx));
499 err = X509_STORE_CTX_get_error(ctx);
511 return INT2FIX(X509_STORE_CTX_get_error_depth(ctx));
527 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L) 531 if(!ctx->current_crl)
return Qnil;
542 X509_STORE_CTX *store;
546 X509_STORE_CTX_set_flags(store,
f);
554 X509_STORE_CTX *store;
558 X509_STORE_CTX_set_purpose(store,
p);
566 X509_STORE_CTX *store;
570 X509_STORE_CTX_set_trust(store, t);
582 X509_STORE_CTX *store;
587 X509_STORE_CTX_set_time(store, 0, t);
VALUE ossl_x509crl_new(X509_CRL *)
static VALUE ossl_x509stctx_set_flags(VALUE, VALUE)
static VALUE ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
static VALUE ossl_x509stctx_set_purpose(VALUE, VALUE)
static VALUE ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define GetX509Store(obj, st)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
STACK_OF(X509) *ossl_x509_ary2sk0(VALUE)
static VALUE ossl_x509stctx_get_err(VALUE)
static VALUE ossl_x509stctx_set_time(VALUE, VALUE)
static VALUE ossl_x509store_add_path(VALUE self, VALUE dir)
void Init_ossl_x509store()
static VALUE ossl_x509store_set_trust(VALUE self, VALUE trust)
static VALUE ossl_x509store_add_crl(VALUE self, VALUE arg)
X509 * GetX509CertPtr(VALUE)
#define SafeGetX509Store(obj, st)
int rb_block_given_p(void)
static VALUE ossl_x509stctx_set_error(VALUE self, VALUE err)
#define GetX509StCtx(obj, ctx)
RUBY_EXTERN VALUE rb_cObject
static VALUE ossl_x509stctx_set_trust(VALUE, VALUE)
void rb_attr(VALUE, ID, int, int, int)
static VALUE ossl_x509store_add_file(VALUE self, VALUE file)
VALUE rb_iv_get(VALUE, const char *)
#define WrapX509StCtx(klass, obj, ctx)
static VALUE ossl_x509store_verify(int argc, VALUE *argv, VALUE self)
VALUE ossl_x509_new(X509 *)
static VALUE ossl_x509store_set_time(VALUE self, VALUE time)
#define WrapX509Store(klass, obj, st)
X509_STORE * DupX509StorePtr(VALUE obj)
static VALUE ossl_x509stctx_get_curr_crl(VALUE self)
static VALUE ossl_x509store_alloc(VALUE klass)
X509_STORE * GetX509StorePtr(VALUE obj)
static VALUE ossl_x509store_set_flags(VALUE self, VALUE flags)
static VALUE ossl_x509stctx_get_err_string(VALUE)
VALUE rb_iv_set(VALUE, const char *, VALUE)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
int X509_STORE_set_ex_data(X509_STORE *str, int idx, void *data)
VALUE rb_define_module_under(VALUE outer, const char *name)
static VALUE ossl_x509stctx_get_curr_cert(VALUE self)
VALUE ossl_x509stctx_clear_ptr(VALUE obj)
static void ossl_x509stctx_free(X509_STORE_CTX *)
VALUE rb_block_proc(void)
static VALUE ossl_x509store_add_cert(VALUE self, VALUE arg)
#define OSSL_Check_Kind(obj, klass)
static VALUE ossl_x509stctx_get_err_depth(VALUE self)
void ossl_raise(VALUE exc, const char *fmt,...)
#define SafeStringValue(v)
X509 * DupX509CertPtr(VALUE)
VALUE rb_ary_new2(long capa)
static VALUE ossl_x509stctx_verify(VALUE self)
static VALUE ossl_x509store_set_purpose(VALUE self, VALUE purpose)
static VALUE ossl_x509stctx_get_chain(VALUE)
static VALUE ossl_x509stctx_alloc(VALUE klass)
VALUE ossl_x509store_new(X509_STORE *store)
VALUE rb_define_module(const char *name)
VALUE ossl_x509stctx_new(X509_STORE_CTX *ctx)
X509_CRL * GetX509CRLPtr(VALUE)
static VALUE ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new2(const char *)
static VALUE ossl_x509store_set_default_paths(VALUE self)
int ossl_verify_cb(int ok, X509_STORE_CTX *ctx)