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);
219 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
221 if(X509_LOOKUP_load_file(lookup, path, X509_FILETYPE_PEM) != 1){
240 lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
242 if(X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1){
255 if (X509_STORE_set_default_paths(store) != 1){
270 if (X509_STORE_add_cert(store, cert) != 1){
285 if (X509_STORE_add_crl(store, crl) != 1){
306 rb_iv_set(ctx,
"@verify_callback", proc);
347 sk_X509_pop_free(ctx->untrusted, X509_free);
349 X509_free(ctx->cert);
350 X509_STORE_CTX_free(ctx);
359 if((ctx = X509_STORE_CTX_new()) ==
NULL){
375 VALUE store, cert, chain, t;
385 if(!
NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
386 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
387 if(X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
388 sk_X509_pop_free(x509s, X509_free);
392 X509_STORE_CTX_init(ctx, x509st, x509, x509s);
413 (
void*)
rb_iv_get(
self,
"@verify_callback"));
414 result = X509_verify_cert(ctx);
429 if((chain = X509_STORE_CTX_get_chain(ctx)) ==
NULL){
432 if((num = sk_X509_num(chain)) < 0){
437 for(i = 0; i < num; i++) {
438 x509 = sk_X509_value(chain, i);
452 return INT2FIX(X509_STORE_CTX_get_error(ctx));
461 X509_STORE_CTX_set_error(ctx,
NUM2INT(err));
473 err = X509_STORE_CTX_get_error(ctx);
475 return rb_str_new2(X509_verify_cert_error_string(err));
485 return INT2FIX(X509_STORE_CTX_get_error_depth(ctx));
501 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
505 if(!ctx->current_crl)
return Qnil;
516 X509_STORE_CTX *store;
520 X509_STORE_CTX_set_flags(store, f);
528 X509_STORE_CTX *store;
532 X509_STORE_CTX_set_purpose(store, p);
540 X509_STORE_CTX *store;
544 X509_STORE_CTX_set_trust(store, t);
556 X509_STORE_CTX *store;
561 X509_STORE_CTX_set_time(store, 0, t);
static long NUM2LONG(VALUE x)
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)
static VALUE INT2NUM(int v)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#define RSTRING_PTR(string)
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)
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)
STACK_OF(X509)*ossl_x509_ary2sk0(VALUE)
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)
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 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)