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)