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);
245 ossl_x509ext_alloc(
VALUE klass)
251 if(!(ext = X509_EXTENSION_new())){
274 VALUE oid, value, critical;
275 const unsigned char *p;
276 X509_EXTENSION *ext, *x;
283 x = d2i_X509_EXTENSION(&ext, &p,
RSTRING_LEN(oid));
297 ossl_x509ext_initialize_copy(
VALUE self,
VALUE other)
299 X509_EXTENSION *ext, *ext_other, *ext_new;
305 ext_new = X509_EXTENSION_dup(ext_other);
310 X509_EXTENSION_free(ext);
325 if (!X509_EXTENSION_set_object(ext, obj)) {
326 ASN1_OBJECT_free(obj);
329 ASN1_OBJECT_free(obj);
335 ossl_x509ext_set_value(
VALUE self,
VALUE data)
338 ASN1_OCTET_STRING *asn1s;
343 asn1s = X509_EXTENSION_get_data(ext);
345 if (!ASN1_OCTET_STRING_set(asn1s, (
unsigned char *)
RSTRING_PTR(data),
346 RSTRING_LENINT(data))) {
354 ossl_x509ext_set_critical(
VALUE self,
VALUE flag)
359 X509_EXTENSION_set_critical(ext,
RTEST(flag) ? 1 : 0);
365 ossl_x509ext_get_oid(
VALUE obj)
374 extobj = X509_EXTENSION_get_object(ext);
375 if ((nid = OBJ_obj2nid(extobj)) != NID_undef)
378 if (!(out = BIO_new(BIO_s_mem())))
380 i2a_ASN1_OBJECT(out, extobj);
388 ossl_x509ext_get_value(
VALUE obj)
395 if (!(out = BIO_new(BIO_s_mem())))
397 if (!X509V3_EXT_print(out, ext, 0, 0))
398 ASN1_STRING_print(out, (ASN1_STRING *)X509_EXTENSION_get_data(ext));
405 ossl_x509ext_get_value_der(
VALUE obj)
408 ASN1_OCTET_STRING *value;
411 if ((value = X509_EXTENSION_get_data(ext)) ==
NULL)
414 return rb_str_new((
const char *)value->data, value->length);
418 ossl_x509ext_get_critical(
VALUE obj)
423 return X509_EXTENSION_get_critical(ext) ?
Qtrue :
Qfalse;
427 ossl_x509ext_to_der(
VALUE obj)
435 if((
len = i2d_X509_EXTENSION(ext,
NULL)) <= 0)
439 if(i2d_X509_EXTENSION(ext, &p) < 0)