12 #define NewX509(klass) \ 13 TypedData_Wrap_Struct((klass), &ossl_x509_type, 0) 14 #define SetX509(obj, x509) do { \ 16 ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \ 18 RTYPEDDATA_DATA(obj) = (x509); \ 20 #define GetX509(obj, x509) do { \ 21 TypedData_Get_Struct((obj), X509, &ossl_x509_type, (x509)); \ 23 ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \ 34 ossl_x509_free(
void *ptr)
96 ossl_x509_alloc(
VALUE klass)
127 x509 = PEM_read_bio_X509(in, &x,
NULL,
NULL);
131 x509 = d2i_X509_bio(in, &x);
146 if (
self == other)
return self;
165 ossl_x509_to_der(
VALUE self)
173 if ((len = i2d_X509(x509,
NULL)) <= 0)
177 if (i2d_X509(x509, &p) <= 0)
189 ossl_x509_to_pem(
VALUE self)
196 out = BIO_new(BIO_s_mem());
199 if (!PEM_write_bio_X509(out, x509)) {
213 ossl_x509_to_text(
VALUE self)
221 out = BIO_new(BIO_s_mem());
224 if (!X509_print(out, x509)) {
238 ossl_x509_to_req(
VALUE self)
245 if (!(req = X509_to_X509_REQ(x509,
NULL, EVP_md5()))) {
248 obj = ossl_x509req_new(req);
260 ossl_x509_get_version(
VALUE self)
266 return LONG2NUM(X509_get_version(x509));
274 ossl_x509_set_version(
VALUE self,
VALUE version)
279 if ((ver =
NUM2LONG(version)) < 0) {
283 if (!X509_set_version(x509, ver)) {
295 ossl_x509_get_serial(
VALUE self)
324 ossl_x509_get_signature_algorithm(
VALUE self)
331 out = BIO_new(BIO_s_mem());
348 ossl_x509_get_subject(
VALUE self)
354 if (!(name = X509_get_subject_name(x509))) {
366 ossl_x509_set_subject(
VALUE self,
VALUE subject)
383 ossl_x509_get_issuer(
VALUE self)
389 if(!(name = X509_get_issuer_name(x509))) {
401 ossl_x509_set_issuer(
VALUE self,
VALUE issuer)
418 ossl_x509_get_not_before(
VALUE self)
421 const ASN1_TIME *asn1time;
436 ossl_x509_set_not_before(
VALUE self,
VALUE time)
443 if (!X509_set_notBefore(x509, asn1time)) {
444 ASN1_TIME_free(asn1time);
447 ASN1_TIME_free(asn1time);
457 ossl_x509_get_not_after(
VALUE self)
460 const ASN1_TIME *asn1time;
475 ossl_x509_set_not_after(
VALUE self,
VALUE time)
482 if (!X509_set_notAfter(x509, asn1time)) {
483 ASN1_TIME_free(asn1time);
486 ASN1_TIME_free(asn1time);
496 ossl_x509_get_public_key(
VALUE self)
502 if (!(pkey = X509_get_pubkey(x509))) {
519 if (!X509_set_pubkey(x509,
GetPKeyPtr(key))) {
540 if (!X509_sign(x509, pkey, md)) {
563 switch (X509_verify(x509, pkey)) {
590 if (!X509_check_private_key(x509, pkey)) {
603 ossl_x509_get_extensions(
VALUE self)
611 count = X509_get_ext_count(x509);
616 for (i=0; i<
count; i++) {
617 ext = X509_get_ext(x509, i);
629 ossl_x509_set_extensions(
VALUE self,
VALUE ary)
641 while ((ext = X509_delete_ext(x509, 0)))
642 X509_EXTENSION_free(ext);
645 if (!X509_add_ext(x509, ext, -1)) {
658 ossl_x509_add_extension(
VALUE self,
VALUE extension)
665 if (!X509_add_ext(x509, ext, -1)) {
673 ossl_x509_inspect(
VALUE self)
679 ossl_x509_get_subject(
self),
680 ossl_x509_get_issuer(
self),
681 ossl_x509_get_serial(
self),
682 ossl_x509_get_not_before(
self),
683 ossl_x509_get_not_after(
self));
#define RUBY_TYPED_FREE_IMMEDIATELY
EVP_PKEY * GetPrivPKeyPtr(VALUE obj)
#define ossl_str_adjust(str, p)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define X509_get0_notBefore(x)
ASN1_TIME * ossl_x509_time_adjust(ASN1_TIME *s, VALUE time)
BIO * ossl_obj2bio(volatile VALUE *pobj)
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 asn1integer_to_num(const ASN1_INTEGER *ai)
VALUE ossl_membio2str(BIO *bio)
VALUE ossl_x509_new(X509 *x509)
VALUE ossl_pkey_new(EVP_PKEY *pkey)
X509_NAME * GetX509NamePtr(VALUE)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
void Init_ossl_x509cert(void)
#define GetX509(obj, x509)
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_clear_error(void)
RUBY_EXTERN VALUE rb_cObject
#define OSSL_BIO_reset(bio)
VALUE ossl_x509ext_new(X509_EXTENSION *)
X509 * DupX509CertPtr(VALUE obj)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
const EVP_MD * ossl_evp_get_digestbyname(VALUE obj)
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define X509_get0_notAfter(x)
#define X509_get0_tbs_sigalg(x)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
X509_EXTENSION * GetX509ExtPtr(VALUE)
#define RARRAY_AREF(a, i)
VALUE asn1time_to_time(const ASN1_TIME *time)
#define OSSL_Check_Kind(obj, klass)
void ossl_raise(VALUE exc, const char *fmt,...)
EVP_PKEY * GetPKeyPtr(VALUE obj)
#define SetX509(obj, x509)
VALUE ossl_x509name_new(X509_NAME *)
#define rb_check_frozen(obj)
X509 * GetX509CertPtr(VALUE obj)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)
ASN1_INTEGER * num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)