12 #define NewX509Ext(klass) \ 13 TypedData_Wrap_Struct((klass), &ossl_x509ext_type, 0) 14 #define SetX509Ext(obj, ext) do { \ 16 ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \ 18 RTYPEDDATA_DATA(obj) = (ext); \ 20 #define GetX509Ext(obj, ext) do { \ 21 TypedData_Get_Struct((obj), X509_EXTENSION, &ossl_x509ext_type, (ext)); \ 23 ossl_raise(rb_eRuntimeError, "EXT wasn't initialized!"); \ 26 #define MakeX509ExtFactory(klass, obj, ctx) do { \ 27 (obj) = TypedData_Wrap_Struct((klass), &ossl_x509extfactory_type, 0); \ 28 if (!((ctx) = OPENSSL_malloc(sizeof(X509V3_CTX)))) \ 29 ossl_raise(rb_eRuntimeError, "CTX wasn't allocated!"); \ 30 X509V3_set_ctx((ctx), NULL, NULL, NULL, NULL, 0); \ 31 RTYPEDDATA_DATA(obj) = (ctx); \ 33 #define GetX509ExtFactory(obj, ctx) do { \ 34 TypedData_Get_Struct((obj), X509V3_CTX, &ossl_x509extfactory_type, (ctx)); \ 36 ossl_raise(rb_eRuntimeError, "CTX wasn't initialized!"); \ 48 ossl_x509ext_free(
void *ptr)
50 X509_EXTENSION_free(ptr);
54 "OpenSSL/X509/EXTENSION",
72 new = X509_EXTENSION_new();
74 new = X509_EXTENSION_dup(ext);
101 ossl_x509extfactory_free(
void *ctx)
107 "OpenSSL/X509/EXTENSION/Factory",
109 0, ossl_x509extfactory_free,
115 ossl_x509extfactory_alloc(
VALUE klass)
127 ossl_x509extfactory_set_issuer_cert(
VALUE self,
VALUE cert)
132 rb_iv_set(
self,
"@issuer_certificate", cert);
139 ossl_x509extfactory_set_subject_cert(
VALUE self,
VALUE cert)
144 rb_iv_set(
self,
"@subject_certificate", cert);
151 ossl_x509extfactory_set_subject_req(
VALUE self,
VALUE req)
156 rb_iv_set(
self,
"@subject_request", req);
163 ossl_x509extfactory_set_crl(
VALUE self,
VALUE crl)
178 VALUE issuer_cert, subject_cert, subject_req, crl;
183 &issuer_cert, &subject_cert, &subject_req, &crl);
184 if (!
NIL_P(issuer_cert))
185 ossl_x509extfactory_set_issuer_cert(
self, issuer_cert);
186 if (!
NIL_P(subject_cert))
187 ossl_x509extfactory_set_subject_cert(
self, subject_cert);
188 if (!
NIL_P(subject_req))
189 ossl_x509extfactory_set_subject_req(
self, subject_req);
191 ossl_x509extfactory_set_crl(
self, crl);
208 VALUE oid, value, critical, valstr, obj;
230 X509V3_set_nconf(ctx, conf);
231 ext = X509V3_EXT_nconf_nid(conf, ctx, nid,
RSTRING_PTR(valstr));
232 X509V3_set_ctx_nodb(ctx);
246 ossl_x509ext_alloc(
VALUE klass)
252 if(!(ext = X509_EXTENSION_new())){
275 VALUE oid, value, critical;
276 const unsigned char *p;
277 X509_EXTENSION *ext, *x;
284 x = d2i_X509_EXTENSION(&ext, &p,
RSTRING_LEN(oid));
298 ossl_x509ext_initialize_copy(
VALUE self,
VALUE other)
300 X509_EXTENSION *ext, *ext_other, *ext_new;
306 ext_new = X509_EXTENSION_dup(ext_other);
311 X509_EXTENSION_free(ext);
326 if (!X509_EXTENSION_set_object(ext, obj)) {
327 ASN1_OBJECT_free(obj);
330 ASN1_OBJECT_free(obj);
336 ossl_x509ext_set_value(
VALUE self,
VALUE data)
339 ASN1_OCTET_STRING *asn1s;
344 asn1s = X509_EXTENSION_get_data(ext);
346 if (!ASN1_OCTET_STRING_set(asn1s, (
unsigned char *)
RSTRING_PTR(data),
355 ossl_x509ext_set_critical(
VALUE self,
VALUE flag)
360 X509_EXTENSION_set_critical(ext,
RTEST(flag) ? 1 : 0);
366 ossl_x509ext_get_oid(
VALUE obj)
375 extobj = X509_EXTENSION_get_object(ext);
376 if ((nid = OBJ_obj2nid(extobj)) != NID_undef)
379 if (!(out = BIO_new(BIO_s_mem())))
381 i2a_ASN1_OBJECT(out, extobj);
389 ossl_x509ext_get_value(
VALUE obj)
396 if (!(out = BIO_new(BIO_s_mem())))
398 if (!X509V3_EXT_print(out, ext, 0, 0))
399 ASN1_STRING_print(out, (ASN1_STRING *)X509_EXTENSION_get_data(ext));
406 ossl_x509ext_get_critical(
VALUE obj)
411 return X509_EXTENSION_get_critical(ext) ?
Qtrue :
Qfalse;
415 ossl_x509ext_to_der(
VALUE obj)
423 if((len = i2d_X509_EXTENSION(ext,
NULL)) <= 0)
427 if(i2d_X509_EXTENSION(ext, &p) < 0)
#define RUBY_TYPED_FREE_IMMEDIATELY
#define ossl_str_adjust(str, p)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_iv_set(VALUE, const char *, VALUE)
VALUE rb_iv_get(VALUE, const char *)
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)
VALUE ossl_membio2str(BIO *bio)
#define NewX509Ext(klass)
#define GetX509ExtFactory(obj, ctx)
X509 * GetX509CertPtr(VALUE)
void Init_ossl_x509ext(void)
VALUE ossl_to_der_if_possible(VALUE obj)
X509_EXTENSION * GetX509ExtPtr(VALUE obj)
RUBY_EXTERN VALUE rb_cObject
void rb_attr(VALUE, ID, int, int, int)
VALUE ossl_x509ext_new(X509_EXTENSION *ext)
#define SetX509Ext(obj, ext)
CONF * DupConfigPtr(VALUE obj)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
#define StringValueCStr(v)
#define MakeX509ExtFactory(klass, obj, ctx)
void ossl_raise(VALUE exc, const char *fmt,...)
#define RSTRING_LENINT(str)
#define rb_check_frozen(obj)
VALUE rb_define_module(const char *name)
X509_CRL * GetX509CRLPtr(VALUE)
X509_REQ * GetX509ReqPtr(VALUE)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
#define GetX509Ext(obj, ext)
VALUE rb_str_new(const char *, long)