2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
2015-04-19 23:55:09 -04:00
|
|
|
* This program is licensed under the same licence as Ruby.
|
2003-07-23 12:12:24 -04:00
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#include "ossl.h"
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
#define NewX509Store(klass) \
|
|
|
|
TypedData_Wrap_Struct((klass), &ossl_x509store_type, 0)
|
|
|
|
#define SetX509Store(obj, st) do { \
|
2011-03-19 23:43:40 -04:00
|
|
|
if (!(st)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \
|
|
|
|
} \
|
2015-05-29 01:55:02 -04:00
|
|
|
RTYPEDDATA_DATA(obj) = (st); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetX509Store(obj, st) do { \
|
2014-12-12 19:06:48 -05:00
|
|
|
TypedData_Get_Struct((obj), X509_STORE, &ossl_x509store_type, (st)); \
|
2011-03-19 23:43:40 -04:00
|
|
|
if (!(st)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
#define NewX509StCtx(klass) \
|
|
|
|
TypedData_Wrap_Struct((klass), &ossl_x509stctx_type, 0)
|
|
|
|
#define SetX509StCtx(obj, ctx) do { \
|
2011-03-19 23:43:40 -04:00
|
|
|
if (!(ctx)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "STORE_CTX wasn't initialized!"); \
|
|
|
|
} \
|
2015-05-29 01:55:02 -04:00
|
|
|
RTYPEDDATA_DATA(obj) = (ctx); \
|
2003-07-23 12:12:24 -04:00
|
|
|
} while (0)
|
|
|
|
#define GetX509StCtx(obj, ctx) do { \
|
2014-12-12 19:06:54 -05:00
|
|
|
TypedData_Get_Struct((obj), X509_STORE_CTX, &ossl_x509stctx_type, (ctx)); \
|
2011-03-19 23:43:40 -04:00
|
|
|
if (!(ctx)) { \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "STORE_CTX is out of scope!"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
/*
|
|
|
|
* Verify callback stuff
|
|
|
|
*/
|
|
|
|
static int stctx_ex_verify_cb_idx, store_ex_verify_cb_idx;
|
|
|
|
static VALUE ossl_x509stctx_new(X509_STORE_CTX *);
|
|
|
|
|
|
|
|
struct ossl_verify_cb_args {
|
|
|
|
VALUE proc;
|
|
|
|
VALUE preverify_ok;
|
|
|
|
VALUE store_ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
call_verify_cb_proc(struct ossl_verify_cb_args *args)
|
|
|
|
{
|
|
|
|
return rb_funcall(args->proc, rb_intern("call"), 2,
|
|
|
|
args->preverify_ok, args->store_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ossl_verify_cb_call(VALUE proc, int ok, X509_STORE_CTX *ctx)
|
|
|
|
{
|
|
|
|
VALUE rctx, ret;
|
|
|
|
struct ossl_verify_cb_args args;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
if (NIL_P(proc))
|
|
|
|
return ok;
|
|
|
|
|
|
|
|
ret = Qfalse;
|
|
|
|
rctx = rb_protect((VALUE(*)(VALUE))ossl_x509stctx_new, (VALUE)ctx, &state);
|
|
|
|
if (state) {
|
|
|
|
rb_set_errinfo(Qnil);
|
|
|
|
rb_warn("StoreContext initialization failure");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
args.proc = proc;
|
|
|
|
args.preverify_ok = ok ? Qtrue : Qfalse;
|
|
|
|
args.store_ctx = rctx;
|
|
|
|
ret = rb_protect((VALUE(*)(VALUE))call_verify_cb_proc, (VALUE)&args, &state);
|
|
|
|
if (state) {
|
|
|
|
rb_set_errinfo(Qnil);
|
|
|
|
rb_warn("exception in verify_callback is ignored");
|
|
|
|
}
|
|
|
|
RTYPEDDATA_DATA(rctx) = NULL;
|
|
|
|
}
|
|
|
|
if (ret == Qtrue) {
|
|
|
|
X509_STORE_CTX_set_error(ctx, X509_V_OK);
|
|
|
|
ok = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (X509_STORE_CTX_get_error(ctx) == X509_V_OK)
|
|
|
|
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REJECTED);
|
|
|
|
ok = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cX509Store;
|
|
|
|
VALUE cX509StoreContext;
|
|
|
|
VALUE eX509StoreError;
|
|
|
|
|
2014-12-12 19:06:48 -05:00
|
|
|
static void
|
|
|
|
ossl_x509store_free(void *ptr)
|
|
|
|
{
|
|
|
|
X509_STORE_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_data_type_t ossl_x509store_type = {
|
|
|
|
"OpenSSL/X509/STORE",
|
|
|
|
{
|
|
|
|
0, ossl_x509store_free,
|
|
|
|
},
|
|
|
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
};
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
X509_STORE *
|
|
|
|
GetX509StorePtr(VALUE obj)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
GetX509Store(obj, store);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private functions
|
|
|
|
*/
|
2016-08-29 01:47:09 -04:00
|
|
|
static int
|
|
|
|
x509store_verify_cb(int ok, X509_STORE_CTX *ctx)
|
|
|
|
{
|
|
|
|
VALUE proc;
|
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
proc = (VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx);
|
2016-08-29 01:47:09 -04:00
|
|
|
if (!proc)
|
2016-11-30 09:41:46 -05:00
|
|
|
proc = (VALUE)X509_STORE_get_ex_data(X509_STORE_CTX_get0_store(ctx),
|
|
|
|
store_ex_verify_cb_idx);
|
2016-08-29 01:47:09 -04:00
|
|
|
if (!proc)
|
|
|
|
return ok;
|
|
|
|
|
|
|
|
return ossl_verify_cb_call(proc, ok, ctx);
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509store_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewX509Store(klass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if((store = X509_STORE_new()) == NULL){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetX509Store(obj, store);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General callback for OpenSSL verify
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
|
|
|
|
GetX509Store(self, store);
|
2016-11-30 09:41:46 -05:00
|
|
|
X509_STORE_set_ex_data(store, store_ex_verify_cb_idx, (void *)cb);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_iv_set(self, "@verify_callback", cb);
|
|
|
|
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
2007-04-05 15:03:28 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* X509::Store.new => store
|
|
|
|
*
|
2016-08-29 01:47:09 -04:00
|
|
|
* Creates a new X509::Store.
|
2007-04-05 15:03:28 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
|
2007-04-05 15:03:28 -04:00
|
|
|
/* BUG: This method takes any number of arguments but appears to ignore them. */
|
2003-07-23 12:12:24 -04:00
|
|
|
GetX509Store(self, store);
|
2016-06-05 11:35:12 -04:00
|
|
|
#if !defined(HAVE_OPAQUE_OPENSSL)
|
|
|
|
/* [Bug #405] [Bug #1678] [Bug #3000]; already fixed? */
|
2010-03-26 10:01:24 -04:00
|
|
|
store->ex_data.sk = NULL;
|
2016-06-05 11:35:12 -04:00
|
|
|
#endif
|
2016-08-29 01:47:09 -04:00
|
|
|
X509_STORE_set_verify_cb(store, x509store_verify_cb);
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509store_set_vfy_cb(self, Qnil);
|
|
|
|
|
|
|
|
/* last verification status */
|
|
|
|
rb_iv_set(self, "@error", Qnil);
|
|
|
|
rb_iv_set(self, "@error_string", Qnil);
|
|
|
|
rb_iv_set(self, "@chain", Qnil);
|
2005-08-22 16:47:55 -04:00
|
|
|
rb_iv_set(self, "@time", Qnil);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2017-09-03 08:35:27 -04:00
|
|
|
* store.flags = flags
|
2016-08-29 01:47:09 -04:00
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Sets _flags_ to the Store. _flags_ consists of zero or more of the constants
|
2016-08-29 01:47:09 -04:00
|
|
|
* defined in with name V_FLAG_* or'ed together.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_set_flags(VALUE self, VALUE flags)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
2004-12-15 01:35:55 -05:00
|
|
|
long f = NUM2LONG(flags);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509Store(self, store);
|
2004-12-15 01:35:55 -05:00
|
|
|
X509_STORE_set_flags(store, f);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.purpose = purpose
|
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Sets the store's purpose to _purpose_. If specified, the verifications on
|
2016-08-29 01:47:09 -04:00
|
|
|
* the store will check every untrusted certificate's extensions are consistent
|
|
|
|
* with the purpose. The purpose is specified by constants:
|
|
|
|
*
|
|
|
|
* * X509::PURPOSE_SSL_CLIENT
|
|
|
|
* * X509::PURPOSE_SSL_SERVER
|
|
|
|
* * X509::PURPOSE_NS_SSL_SERVER
|
|
|
|
* * X509::PURPOSE_SMIME_SIGN
|
|
|
|
* * X509::PURPOSE_SMIME_ENCRYPT
|
|
|
|
* * X509::PURPOSE_CRL_SIGN
|
|
|
|
* * X509::PURPOSE_ANY
|
|
|
|
* * X509::PURPOSE_OCSP_HELPER
|
|
|
|
* * X509::PURPOSE_TIMESTAMP_SIGN
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_set_purpose(VALUE self, VALUE purpose)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
2011-03-24 00:49:18 -04:00
|
|
|
int p = NUM2INT(purpose);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetX509Store(self, store);
|
2004-12-15 01:35:55 -05:00
|
|
|
X509_STORE_set_purpose(store, p);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return purpose;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.trust = trust
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_set_trust(VALUE self, VALUE trust)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
2011-03-24 00:49:18 -04:00
|
|
|
int t = NUM2INT(trust);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509Store(self, store);
|
2004-12-15 01:35:55 -05:00
|
|
|
X509_STORE_set_trust(store, t);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return trust;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.time = time
|
|
|
|
*
|
|
|
|
* Sets the time to be used in verifications.
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2004-10-15 05:16:19 -04:00
|
|
|
ossl_x509store_set_time(VALUE self, VALUE time)
|
|
|
|
{
|
|
|
|
rb_iv_set(self, "@time", time);
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2012-10-02 15:36:26 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2016-08-29 01:47:09 -04:00
|
|
|
* store.add_file(file) -> self
|
2012-10-02 15:36:26 -04:00
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Adds the certificates in _file_ to the certificate store. _file_ is the path
|
|
|
|
* to the file, and the file contains one or more certificates in PEM format
|
|
|
|
* concatenated together.
|
2012-10-02 15:36:26 -04:00
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509store_add_file(VALUE self, VALUE file)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
X509_LOOKUP *lookup;
|
|
|
|
char *path = NULL;
|
|
|
|
|
|
|
|
if(file != Qnil){
|
2016-05-23 07:40:07 -04:00
|
|
|
rb_check_safe_obj(file);
|
|
|
|
path = StringValueCStr(file);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
GetX509Store(self, store);
|
|
|
|
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
|
|
|
|
if(lookup == NULL) ossl_raise(eX509StoreError, NULL);
|
|
|
|
if(X509_LOOKUP_load_file(lookup, path, X509_FILETYPE_PEM) != 1){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2017-06-14 05:49:09 -04:00
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x10101000 || defined(LIBRESSL_VERSION_NUMBER)
|
|
|
|
/*
|
|
|
|
* X509_load_cert_crl_file() which is called from X509_LOOKUP_load_file()
|
|
|
|
* did not check the return value of X509_STORE_add_{cert,crl}(), leaking
|
|
|
|
* "cert already in hash table" errors on the error queue, if duplicate
|
|
|
|
* certificates are found. This will be fixed by OpenSSL 1.1.1.
|
|
|
|
*/
|
|
|
|
ossl_clear_error();
|
|
|
|
#endif
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.add_path(path) -> self
|
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Adds _path_ as the hash dir to be looked up by the store.
|
2016-08-29 01:47:09 -04:00
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509store_add_path(VALUE self, VALUE dir)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
X509_LOOKUP *lookup;
|
|
|
|
char *path = NULL;
|
|
|
|
|
|
|
|
if(dir != Qnil){
|
2016-05-23 07:40:07 -04:00
|
|
|
rb_check_safe_obj(dir);
|
|
|
|
path = StringValueCStr(dir);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
GetX509Store(self, store);
|
|
|
|
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
|
|
|
|
if(lookup == NULL) ossl_raise(eX509StoreError, NULL);
|
|
|
|
if(X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-10-02 15:36:26 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2013-04-15 22:24:09 -04:00
|
|
|
* store.set_default_paths
|
2012-10-02 15:36:26 -04:00
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Configures _store_ to look up CA certificates from the system default
|
2016-08-29 01:47:09 -04:00
|
|
|
* certificate store as needed basis. The location of the store can usually be
|
2012-10-02 15:36:26 -04:00
|
|
|
* determined by:
|
|
|
|
*
|
2016-08-29 01:47:09 -04:00
|
|
|
* * OpenSSL::X509::DEFAULT_CERT_FILE
|
|
|
|
* * OpenSSL::X509::DEFAULT_CERT_DIR
|
2012-10-02 15:36:26 -04:00
|
|
|
*/
|
2005-02-11 03:42:57 -05:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_set_default_paths(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
|
|
|
|
GetX509Store(self, store);
|
2005-08-22 16:47:55 -04:00
|
|
|
if (X509_STORE_set_default_paths(store) != 1){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2005-02-11 03:42:57 -05:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2012-10-02 15:36:26 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.add_cert(cert)
|
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Adds the OpenSSL::X509::Certificate _cert_ to the certificate store.
|
2012-10-02 15:36:26 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_add_cert(VALUE self, VALUE arg)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
X509 *cert;
|
|
|
|
|
|
|
|
cert = GetX509CertPtr(arg); /* NO NEED TO DUP */
|
|
|
|
GetX509Store(self, store);
|
2005-08-22 16:47:55 -04:00
|
|
|
if (X509_STORE_add_cert(store, cert) != 1){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.add_crl(crl) -> self
|
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Adds the OpenSSL::X509::CRL _crl_ to the store.
|
2016-08-29 01:47:09 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509store_add_crl(VALUE self, VALUE arg)
|
|
|
|
{
|
|
|
|
X509_STORE *store;
|
|
|
|
X509_CRL *crl;
|
|
|
|
|
|
|
|
crl = GetX509CRLPtr(arg); /* NO NEED TO DUP */
|
|
|
|
GetX509Store(self, store);
|
2005-08-22 16:47:55 -04:00
|
|
|
if (X509_STORE_add_crl(store, crl) != 1){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE ossl_x509stctx_get_err(VALUE);
|
|
|
|
static VALUE ossl_x509stctx_get_err_string(VALUE);
|
|
|
|
static VALUE ossl_x509stctx_get_chain(VALUE);
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* store.verify(cert, chain = nil) -> true | false
|
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* Performs a certificate verification on the OpenSSL::X509::Certificate _cert_.
|
2016-08-29 01:47:09 -04:00
|
|
|
*
|
2017-09-03 08:35:27 -04:00
|
|
|
* _chain_ can be an array of OpenSSL::X509::Certificate that is used to
|
2016-08-29 01:47:09 -04:00
|
|
|
* construct the certificate chain.
|
|
|
|
*
|
|
|
|
* If a block is given, it overrides the callback set by #verify_callback=.
|
|
|
|
*
|
|
|
|
* After finishing the verification, the error information can be retrieved by
|
2017-09-03 08:35:27 -04:00
|
|
|
* #error, #error_string, and the resulting complete certificate chain can be
|
2016-08-29 01:47:09 -04:00
|
|
|
* retrieved by #chain.
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509store_verify(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE cert, chain;
|
|
|
|
VALUE ctx, proc, result;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &cert, &chain);
|
|
|
|
ctx = rb_funcall(cX509StoreContext, rb_intern("new"), 3, self, cert, chain);
|
|
|
|
proc = rb_block_given_p() ? rb_block_proc() :
|
|
|
|
rb_iv_get(self, "@verify_callback");
|
|
|
|
rb_iv_set(ctx, "@verify_callback", proc);
|
|
|
|
result = rb_funcall(ctx, rb_intern("verify"), 0);
|
|
|
|
|
|
|
|
rb_iv_set(self, "@error", ossl_x509stctx_get_err(ctx));
|
|
|
|
rb_iv_set(self, "@error_string", ossl_x509stctx_get_err_string(ctx));
|
|
|
|
rb_iv_set(self, "@chain", ossl_x509stctx_get_chain(ctx));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public Functions
|
|
|
|
*/
|
2014-12-12 19:06:54 -05:00
|
|
|
static void ossl_x509stctx_free(void*);
|
|
|
|
|
|
|
|
|
|
|
|
static const rb_data_type_t ossl_x509stctx_type = {
|
|
|
|
"OpenSSL/X509/STORE_CTX",
|
|
|
|
{
|
|
|
|
0, ossl_x509stctx_free,
|
|
|
|
},
|
|
|
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
|
|
|
};
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* Private functions
|
|
|
|
*/
|
|
|
|
static void
|
2014-12-12 19:06:54 -05:00
|
|
|
ossl_x509stctx_free(void *ptr)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
2014-12-12 19:06:54 -05:00
|
|
|
X509_STORE_CTX *ctx = ptr;
|
2016-06-05 11:35:12 -04:00
|
|
|
if (X509_STORE_CTX_get0_untrusted(ctx))
|
|
|
|
sk_X509_pop_free(X509_STORE_CTX_get0_untrusted(ctx), X509_free);
|
|
|
|
if (X509_STORE_CTX_get0_cert(ctx))
|
|
|
|
X509_free(X509_STORE_CTX_get0_cert(ctx));
|
2003-07-23 12:12:24 -04:00
|
|
|
X509_STORE_CTX_free(ctx);
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509stctx_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
VALUE obj;
|
|
|
|
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewX509StCtx(klass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if((ctx = X509_STORE_CTX_new()) == NULL){
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetX509StCtx(obj, ctx);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_new(X509_STORE_CTX *ctx)
|
|
|
|
{
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
obj = NewX509StCtx(cX509StoreContext);
|
|
|
|
SetX509StCtx(obj, ctx);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2004-10-15 05:16:19 -04:00
|
|
|
static VALUE ossl_x509stctx_set_flags(VALUE, VALUE);
|
|
|
|
static VALUE ossl_x509stctx_set_purpose(VALUE, VALUE);
|
|
|
|
static VALUE ossl_x509stctx_set_trust(VALUE, VALUE);
|
|
|
|
static VALUE ossl_x509stctx_set_time(VALUE, VALUE);
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* StoreContext.new(store, cert = nil, chain = nil)
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
2005-05-27 16:20:29 -04:00
|
|
|
VALUE store, cert, chain, t;
|
2003-07-23 12:12:24 -04:00
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
X509_STORE *x509st;
|
|
|
|
X509 *x509 = NULL;
|
|
|
|
STACK_OF(X509) *x509s = NULL;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "12", &store, &cert, &chain);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetX509StCtx(self, ctx);
|
2017-09-03 08:35:27 -04:00
|
|
|
GetX509Store(store, x509st);
|
2003-07-23 12:12:24 -04:00
|
|
|
if(!NIL_P(cert)) x509 = DupX509CertPtr(cert); /* NEED TO DUP */
|
|
|
|
if(!NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
|
|
|
|
if(X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
|
|
|
|
sk_X509_pop_free(x509s, X509_free);
|
|
|
|
ossl_raise(eX509StoreError, NULL);
|
|
|
|
}
|
2005-05-27 16:20:29 -04:00
|
|
|
if (!NIL_P(t = rb_iv_get(store, "@time")))
|
|
|
|
ossl_x509stctx_set_time(self, t);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_iv_set(self, "@verify_callback", rb_iv_get(store, "@verify_callback"));
|
|
|
|
rb_iv_set(self, "@cert", cert);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.verify -> true | false
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_verify(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
2016-11-30 09:41:46 -05:00
|
|
|
X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx,
|
2016-05-18 00:07:47 -04:00
|
|
|
(void *)rb_iv_get(self, "@verify_callback"));
|
|
|
|
|
|
|
|
switch (X509_verify_cert(ctx)) {
|
|
|
|
case 1:
|
|
|
|
return Qtrue;
|
|
|
|
case 0:
|
|
|
|
ossl_clear_error();
|
|
|
|
return Qfalse;
|
|
|
|
default:
|
|
|
|
ossl_raise(eX509CertError, NULL);
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.chain -> Array of X509::Certificate
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_get_chain(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
STACK_OF(X509) *chain;
|
|
|
|
X509 *x509;
|
|
|
|
int i, num;
|
|
|
|
VALUE ary;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
2016-06-05 11:35:12 -04:00
|
|
|
if((chain = X509_STORE_CTX_get0_chain(ctx)) == NULL){
|
2003-07-23 12:12:24 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
if((num = sk_X509_num(chain)) < 0){
|
|
|
|
OSSL_Debug("certs in chain < 0???");
|
|
|
|
return rb_ary_new();
|
|
|
|
}
|
|
|
|
ary = rb_ary_new2(num);
|
|
|
|
for(i = 0; i < num; i++) {
|
|
|
|
x509 = sk_X509_value(chain, i);
|
|
|
|
rb_ary_push(ary, ossl_x509_new(x509));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.error -> Integer
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509stctx_get_err(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
return INT2NUM(X509_STORE_CTX_get_error(ctx));
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.error = error_code
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_set_error(VALUE self, VALUE err)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
2008-05-29 13:41:56 -04:00
|
|
|
X509_STORE_CTX_set_error(ctx, NUM2INT(err));
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.error_string -> String
|
|
|
|
*
|
|
|
|
* Returns the error string corresponding to the error code retrieved by #error.
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509stctx_get_err_string(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
long err;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
|
|
|
err = X509_STORE_CTX_get_error(ctx);
|
|
|
|
|
|
|
|
return rb_str_new2(X509_verify_cert_error_string(err));
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.error_depth -> Integer
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509stctx_get_err_depth(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
return INT2NUM(X509_STORE_CTX_get_error_depth(ctx));
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.current_cert -> X509::Certificate
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
static VALUE
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_x509stctx_get_curr_cert(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
|
|
|
|
|
|
|
return ossl_x509_new(X509_STORE_CTX_get_current_cert(ctx));
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.current_crl -> X509::CRL
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_get_curr_crl(VALUE self)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *ctx;
|
2016-06-05 11:35:12 -04:00
|
|
|
X509_CRL *crl;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509StCtx(self, ctx);
|
2016-06-05 11:35:12 -04:00
|
|
|
crl = X509_STORE_CTX_get0_current_crl(ctx);
|
|
|
|
if (!crl)
|
|
|
|
return Qnil;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2016-06-05 11:35:12 -04:00
|
|
|
return ossl_x509crl_new(crl);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.flags = flags
|
|
|
|
*
|
|
|
|
* Sets the verification flags to the context. See Store#flags=.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_set_flags(VALUE self, VALUE flags)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *store;
|
2004-12-15 01:35:55 -05:00
|
|
|
long f = NUM2LONG(flags);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509StCtx(self, store);
|
2004-12-15 01:35:55 -05:00
|
|
|
X509_STORE_CTX_set_flags(store, f);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.purpose = purpose
|
|
|
|
*
|
|
|
|
* Sets the purpose of the context. See Store#purpose=.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_set_purpose(VALUE self, VALUE purpose)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *store;
|
2011-03-24 00:49:18 -04:00
|
|
|
int p = NUM2INT(purpose);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509StCtx(self, store);
|
2004-12-15 01:35:55 -05:00
|
|
|
X509_STORE_CTX_set_purpose(store, p);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return purpose;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* stctx.trust = trust
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_set_trust(VALUE self, VALUE trust)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *store;
|
2011-03-24 00:49:18 -04:00
|
|
|
int t = NUM2INT(trust);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
GetX509StCtx(self, store);
|
2004-12-15 01:35:55 -05:00
|
|
|
X509_STORE_CTX_set_trust(store, t);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return trust;
|
|
|
|
}
|
|
|
|
|
2007-04-05 15:03:28 -04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2016-08-29 01:47:09 -04:00
|
|
|
* stctx.time = time
|
|
|
|
*
|
|
|
|
* Sets the time used in the verification. If not set, the current time is used.
|
2007-04-05 15:03:28 -04:00
|
|
|
*/
|
2004-10-15 05:16:19 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_x509stctx_set_time(VALUE self, VALUE time)
|
|
|
|
{
|
|
|
|
X509_STORE_CTX *store;
|
2005-05-27 16:20:29 -04:00
|
|
|
long t;
|
2004-10-15 05:16:19 -04:00
|
|
|
|
2005-05-27 16:20:29 -04:00
|
|
|
t = NUM2LONG(rb_Integer(time));
|
|
|
|
GetX509StCtx(self, store);
|
|
|
|
X509_STORE_CTX_set_time(store, 0, t);
|
2004-10-15 05:16:19 -04:00
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
2010-04-22 04:04:13 -04:00
|
|
|
void
|
2014-09-30 01:25:32 -04:00
|
|
|
Init_ossl_x509store(void)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
2018-02-16 03:39:48 -05:00
|
|
|
#undef rb_intern
|
2012-02-02 17:54:10 -05:00
|
|
|
#if 0
|
2016-08-29 01:47:09 -04:00
|
|
|
mOSSL = rb_define_module("OpenSSL");
|
|
|
|
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
2012-02-02 17:54:10 -05:00
|
|
|
mX509 = rb_define_module_under(mOSSL, "X509");
|
|
|
|
#endif
|
|
|
|
|
2016-11-30 09:41:46 -05:00
|
|
|
/* Register ext_data slot for verify callback Proc */
|
|
|
|
stctx_ex_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, (void *)"stctx_ex_verify_cb_idx", 0, 0, 0);
|
|
|
|
if (stctx_ex_verify_cb_idx < 0)
|
|
|
|
ossl_raise(eOSSLError, "X509_STORE_CTX_get_ex_new_index");
|
|
|
|
store_ex_verify_cb_idx = X509_STORE_get_ex_new_index(0, (void *)"store_ex_verify_cb_idx", 0, 0, 0);
|
|
|
|
if (store_ex_verify_cb_idx < 0)
|
|
|
|
ossl_raise(eOSSLError, "X509_STORE_get_ex_new_index");
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
eX509StoreError = rb_define_class_under(mX509, "StoreError", eOSSLError);
|
|
|
|
|
2012-02-02 17:54:10 -05:00
|
|
|
/* Document-class: OpenSSL::X509::Store
|
|
|
|
*
|
|
|
|
* The X509 certificate store holds trusted CA certificates used to verify
|
|
|
|
* peer certificates.
|
|
|
|
*
|
|
|
|
* The easiest way to create a useful certificate store is:
|
|
|
|
*
|
|
|
|
* cert_store = OpenSSL::X509::Store.new
|
|
|
|
* cert_store.set_default_paths
|
|
|
|
*
|
|
|
|
* This will use your system's built-in certificates.
|
|
|
|
*
|
2016-08-29 01:47:09 -04:00
|
|
|
* If your system does not have a default set of certificates you can obtain
|
|
|
|
* a set extracted from Mozilla CA certificate store by cURL maintainers
|
|
|
|
* here: https://curl.haxx.se/docs/caextract.html (You may wish to use the
|
|
|
|
* firefox-db2pem.sh script to extract the certificates from a local install
|
|
|
|
* to avoid man-in-the-middle attacks.)
|
2012-02-02 17:54:10 -05:00
|
|
|
*
|
|
|
|
* After downloading or generating a cacert.pem from the above link you
|
|
|
|
* can create a certificate store from the pem file like this:
|
|
|
|
*
|
|
|
|
* cert_store = OpenSSL::X509::Store.new
|
|
|
|
* cert_store.add_file 'cacert.pem'
|
|
|
|
*
|
|
|
|
* The certificate store can be used with an SSLSocket like this:
|
|
|
|
*
|
|
|
|
* ssl_context = OpenSSL::SSL::SSLContext.new
|
2016-08-29 01:47:09 -04:00
|
|
|
* ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
2012-02-02 17:54:10 -05:00
|
|
|
* ssl_context.cert_store = cert_store
|
|
|
|
*
|
|
|
|
* tcp_socket = TCPSocket.open 'example.com', 443
|
|
|
|
*
|
|
|
|
* ssl_socket = OpenSSL::SSL::SSLSocket.new tcp_socket, ssl_context
|
|
|
|
*/
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
cX509Store = rb_define_class_under(mX509, "Store", rb_cObject);
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* The callback for additional certificate verification. It is invoked for
|
|
|
|
* each untrusted certificate in the chain.
|
|
|
|
*
|
|
|
|
* The callback is invoked with two values, a boolean that indicates if the
|
|
|
|
* pre-verification by OpenSSL has succeeded or not, and the StoreContext in
|
|
|
|
* use. The callback must return either true or false.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_attr(cX509Store, rb_intern("verify_callback"), 1, 0, Qfalse);
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* The error code set by the last call of #verify.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_attr(cX509Store, rb_intern("error"), 1, 0, Qfalse);
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* The description for the error code set by the last call of #verify.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_attr(cX509Store, rb_intern("error_string"), 1, 0, Qfalse);
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* The certificate chain constructed by the last call of #verify.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_attr(cX509Store, rb_intern("chain"), 1, 0, Qfalse);
|
|
|
|
rb_define_alloc_func(cX509Store, ossl_x509store_alloc);
|
|
|
|
rb_define_method(cX509Store, "initialize", ossl_x509store_initialize, -1);
|
2016-08-29 01:47:09 -04:00
|
|
|
rb_undef_method(cX509Store, "initialize_copy");
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cX509Store, "verify_callback=", ossl_x509store_set_vfy_cb, 1);
|
|
|
|
rb_define_method(cX509Store, "flags=", ossl_x509store_set_flags, 1);
|
|
|
|
rb_define_method(cX509Store, "purpose=", ossl_x509store_set_purpose, 1);
|
|
|
|
rb_define_method(cX509Store, "trust=", ossl_x509store_set_trust, 1);
|
2004-10-15 05:16:19 -04:00
|
|
|
rb_define_method(cX509Store, "time=", ossl_x509store_set_time, 1);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cX509Store, "add_path", ossl_x509store_add_path, 1);
|
|
|
|
rb_define_method(cX509Store, "add_file", ossl_x509store_add_file, 1);
|
2005-02-11 03:42:57 -05:00
|
|
|
rb_define_method(cX509Store, "set_default_paths", ossl_x509store_set_default_paths, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cX509Store, "add_cert", ossl_x509store_add_cert, 1);
|
|
|
|
rb_define_method(cX509Store, "add_crl", ossl_x509store_add_crl, 1);
|
|
|
|
rb_define_method(cX509Store, "verify", ossl_x509store_verify, -1);
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* Document-class: OpenSSL::X509::StoreContext
|
|
|
|
*
|
|
|
|
* A StoreContext is used while validating a single certificate and holds
|
|
|
|
* the status involved.
|
|
|
|
*/
|
|
|
|
cX509StoreContext = rb_define_class_under(mX509,"StoreContext", rb_cObject);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_alloc_func(cX509StoreContext, ossl_x509stctx_alloc);
|
2016-08-29 01:47:09 -04:00
|
|
|
rb_define_method(cX509StoreContext, "initialize", ossl_x509stctx_initialize, -1);
|
|
|
|
rb_undef_method(cX509StoreContext, "initialize_copy");
|
|
|
|
rb_define_method(cX509StoreContext, "verify", ossl_x509stctx_verify, 0);
|
|
|
|
rb_define_method(cX509StoreContext, "chain", ossl_x509stctx_get_chain,0);
|
|
|
|
rb_define_method(cX509StoreContext, "error", ossl_x509stctx_get_err, 0);
|
|
|
|
rb_define_method(cX509StoreContext, "error=", ossl_x509stctx_set_error, 1);
|
|
|
|
rb_define_method(cX509StoreContext, "error_string", ossl_x509stctx_get_err_string,0);
|
|
|
|
rb_define_method(cX509StoreContext, "error_depth", ossl_x509stctx_get_err_depth, 0);
|
|
|
|
rb_define_method(cX509StoreContext, "current_cert", ossl_x509stctx_get_curr_cert, 0);
|
|
|
|
rb_define_method(cX509StoreContext, "current_crl", ossl_x509stctx_get_curr_crl, 0);
|
|
|
|
rb_define_method(cX509StoreContext, "flags=", ossl_x509stctx_set_flags, 1);
|
|
|
|
rb_define_method(cX509StoreContext, "purpose=", ossl_x509stctx_set_purpose, 1);
|
|
|
|
rb_define_method(cX509StoreContext, "trust=", ossl_x509stctx_set_trust, 1);
|
|
|
|
rb_define_method(cX509StoreContext, "time=", ossl_x509stctx_set_time, 1);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|