13 #define WrapX509Ext(klass, obj, ext) do { \
15 ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
17 (obj) = Data_Wrap_Struct((klass), 0, X509_EXTENSION_free, (ext)); \
19 #define GetX509Ext(obj, ext) do { \
20 Data_Get_Struct((obj), X509_EXTENSION, (ext)); \
22 ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \
25 #define SafeGetX509Ext(obj, ext) do { \
26 OSSL_Check_Kind((obj), cX509Ext); \
27 GetX509Ext((obj), (ext)); \
29 #define MakeX509ExtFactory(klass, obj, ctx) do { \
30 if (!((ctx) = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
31 ossl_raise(rb_eRuntimeError, "CTX wasn't allocated!"); \
32 X509V3_set_ctx((ctx), NULL, NULL, NULL, NULL, 0); \
33 (obj) = Data_Wrap_Struct((klass), 0, ossl_x509extfactory_free, (ctx)); \
35 #define GetX509ExtFactory(obj, ctx) do { \
36 Data_Get_Struct((obj), X509V3_CTX, (ctx)); \
38 ossl_raise(rb_eRuntimeError, "CTX wasn't initialized!"); \
59 new = X509_EXTENSION_new();
61 new = X509_EXTENSION_dup(ext);
84 X509_EXTENSION *ext, *
new;
87 if (!(
new = X509_EXTENSION_dup(ext))) {
124 rb_iv_set(
self,
"@issuer_certificate", cert);
136 rb_iv_set(
self,
"@subject_certificate", cert);
148 rb_iv_set(
self,
"@subject_request", req);
166 #ifdef HAVE_X509V3_SET_NCONF
176 X509V3_set_nconf(ctx, conf);
181 #define ossl_x509extfactory_set_config rb_f_notimplement
188 VALUE issuer_cert, subject_cert, subject_req, crl;
193 &issuer_cert, &subject_cert, &subject_req, &crl);
194 if (!
NIL_P(issuer_cert))
196 if (!
NIL_P(subject_cert))
198 if (!
NIL_P(subject_req))
219 VALUE oid, value, critical, valstr, obj;
221 #ifdef HAVE_X509V3_EXT_NCONF_NID
225 static LHASH *empty_lhash;
228 rb_scan_args(argc, argv,
"21", &oid, &value, &critical);
239 #ifdef HAVE_X509V3_EXT_NCONF_NID
242 ext = X509V3_EXT_nconf_nid(conf, ctx, nid,
RSTRING_PTR(valstr));
244 if (!empty_lhash) empty_lhash = lh_new(
NULL,
NULL);
245 ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid,
RSTRING_PTR(valstr));
265 if(!(ext = X509_EXTENSION_new())){
288 VALUE oid, value, critical;
289 const unsigned char *
p;
290 X509_EXTENSION *ext, *x;
293 if(
rb_scan_args(argc, argv,
"12", &oid, &value, &critical) == 1){
297 x = d2i_X509_EXTENSION(&ext, &p,
RSTRING_LEN(oid));
318 obj = OBJ_txt2obj(s, 0);
319 if(!obj) obj = OBJ_txt2obj(s, 1);
322 X509_EXTENSION_set_object(ext, obj);
331 ASN1_OCTET_STRING *asn1s;
339 if(!(asn1s = ASN1_OCTET_STRING_new())){
345 ASN1_OCTET_STRING_free(asn1s);
350 X509_EXTENSION_set_data(ext, asn1s);
361 X509_EXTENSION_set_critical(ext,
RTEST(flag) ? 1 : 0);
376 extobj = X509_EXTENSION_get_object(ext);
377 if ((nid = OBJ_obj2nid(extobj)) != NID_undef)
380 if (!(out = BIO_new(BIO_s_mem())))
382 i2a_ASN1_OBJECT(out, extobj);
397 if (!(out = BIO_new(BIO_s_mem())))
399 if (!X509V3_EXT_print(out, ext, 0, 0))
400 M_ASN1_OCTET_STRING_print(out, ext->value);
412 return X509_EXTENSION_get_critical(ext) ?
Qtrue :
Qfalse;
424 if((len = i2d_X509_EXTENSION(ext,
NULL)) <= 0)
428 if(i2d_X509_EXTENSION(ext, &p) < 0)
static VALUE ossl_x509ext_get_value(VALUE obj)
VALUE rb_iv_set(VALUE, const char *, VALUE)
static VALUE ossl_x509extfactory_set_subject_req(VALUE self, VALUE req)
#define SafeGetX509Ext(obj, ext)
#define ossl_str_adjust(str, p)
X509_EXTENSION * DupX509ExtPtr(VALUE obj)
static VALUE ossl_x509extfactory_alloc(VALUE klass)
VALUE rb_iv_get(VALUE, const char *)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
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.
VALUE ossl_membio2str(BIO *bio)
VALUE rb_str_append(VALUE, VALUE)
#define GetX509ExtFactory(obj, ctx)
static VALUE ossl_x509ext_get_critical(VALUE obj)
static VALUE ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
#define ossl_x509extfactory_set_config
X509 * GetX509CertPtr(VALUE)
VALUE ossl_to_der_if_possible(VALUE obj)
X509_EXTENSION * GetX509ExtPtr(VALUE obj)
#define StringValuePtr(v)
static VALUE ossl_x509ext_to_der(VALUE obj)
VALUE ossl_x509ext_new(X509_EXTENSION *ext)
static VALUE ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
static VALUE ossl_x509extfactory_set_issuer_cert(VALUE self, VALUE cert)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_attr(VALUE, ID, int, int, int)
static VALUE ossl_x509extfactory_set_subject_cert(VALUE self, VALUE cert)
static VALUE ossl_x509ext_get_oid(VALUE obj)
CONF * GetConfigPtr(VALUE obj)
#define WrapX509Ext(klass, obj, ext)
#define MakeX509ExtFactory(klass, obj, ctx)
static VALUE ossl_x509extfactory_initialize(int argc, VALUE *argv, VALUE self)
static VALUE ossl_x509ext_alloc(VALUE klass)
static VALUE ossl_x509ext_set_value(VALUE self, VALUE data)
RUBY_EXTERN VALUE rb_cObject
void ossl_raise(VALUE exc, const char *fmt,...)
#define RSTRING_LENINT(str)
VALUE rb_str_new(const char *, long)
static VALUE ossl_x509extfactory_set_crl(VALUE self, VALUE crl)
X509_CRL * GetX509CRLPtr(VALUE)
static VALUE ossl_x509ext_set_oid(VALUE self, VALUE oid)
X509_REQ * GetX509ReqPtr(VALUE)
static VALUE ossl_x509ext_set_critical(VALUE self, VALUE flag)
static void ossl_x509extfactory_free(X509V3_CTX *ctx)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define GetX509Ext(obj, ext)