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!"); \
48ossl_x509ext_free(
void *
ptr)
50 X509_EXTENSION_free(
ptr);
54 "OpenSSL/X509/EXTENSION",
72 new = X509_EXTENSION_new();
74 new = X509_EXTENSION_dup(ext);
101ossl_x509extfactory_free(
void *ctx)
107 "OpenSSL/X509/EXTENSION/Factory",
109 0, ossl_x509extfactory_free,
127ossl_x509extfactory_set_issuer_cert(
VALUE self,
VALUE cert)
132 rb_iv_set(
self,
"@issuer_certificate", cert);
139ossl_x509extfactory_set_subject_cert(
VALUE self,
VALUE cert)
144 rb_iv_set(
self,
"@subject_certificate", cert);
151ossl_x509extfactory_set_subject_req(
VALUE self,
VALUE req)
156 rb_iv_set(
self,
"@subject_request", req);
163ossl_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);
232 X509V3_set_ctx_nodb(ctx);
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));
298ossl_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);
339 ASN1_OCTET_STRING *asn1s;
344 asn1s = X509_EXTENSION_get_data(ext);
346 if (!ASN1_OCTET_STRING_set(asn1s, (
unsigned char *)
RSTRING_PTR(data),
355ossl_x509ext_set_critical(
VALUE self,
VALUE flag)
360 X509_EXTENSION_set_critical(ext,
RTEST(flag) ? 1 : 0);
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);
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));
411 return X509_EXTENSION_get_critical(ext) ?
Qtrue :
Qfalse;
423 if((
len = i2d_X509_EXTENSION(ext,
NULL)) <= 0)
427 if(i2d_X509_EXTENSION(ext, &p) < 0)
char str[HTML_ESCAPE_MAX_LEN+1]
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *)
VALUE rb_define_module_under(VALUE, const char *)
VALUE rb_cObject
Object class.
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_raise(VALUE exc, const char *fmt,...)
#define ossl_str_adjust(str, p)
VALUE ossl_membio2str(BIO *bio)
CONF * DupConfigPtr(VALUE obj)
X509_REQ * GetX509ReqPtr(VALUE)
X509 * GetX509CertPtr(VALUE)
X509_CRL * GetX509CRLPtr(VALUE)
#define GetX509ExtFactory(obj, ctx)
#define SetX509Ext(obj, ext)
void Init_ossl_x509ext(void)
#define NewX509Ext(klass)
#define MakeX509ExtFactory(klass, obj, ctx)
#define GetX509Ext(obj, ext)
VALUE ossl_x509ext_new(X509_EXTENSION *ext)
X509_EXTENSION * GetX509ExtPtr(VALUE obj)