Ruby  2.5.0dev(2017-10-22revision60238)
ossl_x509cert.c
Go to the documentation of this file.
1 /*
2  * 'OpenSSL for Ruby' project
3  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4  * All rights reserved.
5  */
6 /*
7  * This program is licensed under the same licence as Ruby.
8  * (See the file 'LICENCE'.)
9  */
10 #include "ossl.h"
11 
12 #define NewX509(klass) \
13  TypedData_Wrap_Struct((klass), &ossl_x509_type, 0)
14 #define SetX509(obj, x509) do { \
15  if (!(x509)) { \
16  ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \
17  } \
18  RTYPEDDATA_DATA(obj) = (x509); \
19 } while (0)
20 #define GetX509(obj, x509) do { \
21  TypedData_Get_Struct((obj), X509, &ossl_x509_type, (x509)); \
22  if (!(x509)) { \
23  ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \
24  } \
25 } while (0)
26 
27 /*
28  * Classes
29  */
32 
33 static void
34 ossl_x509_free(void *ptr)
35 {
36  X509_free(ptr);
37 }
38 
39 static const rb_data_type_t ossl_x509_type = {
40  "OpenSSL/X509",
41  {
42  0, ossl_x509_free,
43  },
45 };
46 
47 /*
48  * Public
49  */
50 VALUE
51 ossl_x509_new(X509 *x509)
52 {
53  X509 *new;
54  VALUE obj;
55 
56  obj = NewX509(cX509Cert);
57  if (!x509) {
58  new = X509_new();
59  } else {
60  new = X509_dup(x509);
61  }
62  if (!new) {
64  }
65  SetX509(obj, new);
66 
67  return obj;
68 }
69 
70 X509 *
72 {
73  X509 *x509;
74 
75  GetX509(obj, x509);
76 
77  return x509;
78 }
79 
80 X509 *
82 {
83  X509 *x509;
84 
85  GetX509(obj, x509);
86 
87  X509_up_ref(x509);
88 
89  return x509;
90 }
91 
92 /*
93  * Private
94  */
95 static VALUE
96 ossl_x509_alloc(VALUE klass)
97 {
98  X509 *x509;
99  VALUE obj;
100 
101  obj = NewX509(klass);
102  x509 = X509_new();
103  if (!x509) ossl_raise(eX509CertError, NULL);
104  SetX509(obj, x509);
105 
106  return obj;
107 }
108 
109 /*
110  * call-seq:
111  * Certificate.new => cert
112  * Certificate.new(string) => cert
113  */
114 static VALUE
115 ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
116 {
117  BIO *in;
118  X509 *x509, *x = DATA_PTR(self);
119  VALUE arg;
120 
121  if (rb_scan_args(argc, argv, "01", &arg) == 0) {
122  /* create just empty X509Cert */
123  return self;
124  }
125  arg = ossl_to_der_if_possible(arg);
126  in = ossl_obj2bio(&arg);
127  x509 = PEM_read_bio_X509(in, &x, NULL, NULL);
128  DATA_PTR(self) = x;
129  if (!x509) {
130  OSSL_BIO_reset(in);
131  x509 = d2i_X509_bio(in, &x);
132  DATA_PTR(self) = x;
133  }
134  BIO_free(in);
135  if (!x509) ossl_raise(eX509CertError, NULL);
136 
137  return self;
138 }
139 
140 static VALUE
141 ossl_x509_copy(VALUE self, VALUE other)
142 {
143  X509 *a, *b, *x509;
144 
145  rb_check_frozen(self);
146  if (self == other) return self;
147 
148  GetX509(self, a);
149  GetX509(other, b);
150 
151  x509 = X509_dup(b);
152  if (!x509) ossl_raise(eX509CertError, NULL);
153 
154  DATA_PTR(self) = x509;
155  X509_free(a);
156 
157  return self;
158 }
159 
160 /*
161  * call-seq:
162  * cert.to_der => string
163  */
164 static VALUE
165 ossl_x509_to_der(VALUE self)
166 {
167  X509 *x509;
168  VALUE str;
169  long len;
170  unsigned char *p;
171 
172  GetX509(self, x509);
173  if ((len = i2d_X509(x509, NULL)) <= 0)
175  str = rb_str_new(0, len);
176  p = (unsigned char *)RSTRING_PTR(str);
177  if (i2d_X509(x509, &p) <= 0)
179  ossl_str_adjust(str, p);
180 
181  return str;
182 }
183 
184 /*
185  * call-seq:
186  * cert.to_pem => string
187  */
188 static VALUE
189 ossl_x509_to_pem(VALUE self)
190 {
191  X509 *x509;
192  BIO *out;
193  VALUE str;
194 
195  GetX509(self, x509);
196  out = BIO_new(BIO_s_mem());
197  if (!out) ossl_raise(eX509CertError, NULL);
198 
199  if (!PEM_write_bio_X509(out, x509)) {
200  BIO_free(out);
202  }
203  str = ossl_membio2str(out);
204 
205  return str;
206 }
207 
208 /*
209  * call-seq:
210  * cert.to_text => string
211  */
212 static VALUE
213 ossl_x509_to_text(VALUE self)
214 {
215  X509 *x509;
216  BIO *out;
217  VALUE str;
218 
219  GetX509(self, x509);
220 
221  out = BIO_new(BIO_s_mem());
222  if (!out) ossl_raise(eX509CertError, NULL);
223 
224  if (!X509_print(out, x509)) {
225  BIO_free(out);
227  }
228  str = ossl_membio2str(out);
229 
230  return str;
231 }
232 
233 #if 0
234 /*
235  * Makes from X509 X509_REQuest
236  */
237 static VALUE
238 ossl_x509_to_req(VALUE self)
239 {
240  X509 *x509;
241  X509_REQ *req;
242  VALUE obj;
243 
244  GetX509(self, x509);
245  if (!(req = X509_to_X509_REQ(x509, NULL, EVP_md5()))) {
247  }
248  obj = ossl_x509req_new(req);
249  X509_REQ_free(req);
250 
251  return obj;
252 }
253 #endif
254 
255 /*
256  * call-seq:
257  * cert.version => integer
258  */
259 static VALUE
260 ossl_x509_get_version(VALUE self)
261 {
262  X509 *x509;
263 
264  GetX509(self, x509);
265 
266  return LONG2NUM(X509_get_version(x509));
267 }
268 
269 /*
270  * call-seq:
271  * cert.version = integer => integer
272  */
273 static VALUE
274 ossl_x509_set_version(VALUE self, VALUE version)
275 {
276  X509 *x509;
277  long ver;
278 
279  if ((ver = NUM2LONG(version)) < 0) {
280  ossl_raise(eX509CertError, "version must be >= 0!");
281  }
282  GetX509(self, x509);
283  if (!X509_set_version(x509, ver)) {
285  }
286 
287  return version;
288 }
289 
290 /*
291  * call-seq:
292  * cert.serial => integer
293  */
294 static VALUE
295 ossl_x509_get_serial(VALUE self)
296 {
297  X509 *x509;
298 
299  GetX509(self, x509);
300 
301  return asn1integer_to_num(X509_get_serialNumber(x509));
302 }
303 
304 /*
305  * call-seq:
306  * cert.serial = integer => integer
307  */
308 static VALUE
309 ossl_x509_set_serial(VALUE self, VALUE num)
310 {
311  X509 *x509;
312 
313  GetX509(self, x509);
314  X509_set_serialNumber(x509, num_to_asn1integer(num, X509_get_serialNumber(x509)));
315 
316  return num;
317 }
318 
319 /*
320  * call-seq:
321  * cert.signature_algorithm => string
322  */
323 static VALUE
324 ossl_x509_get_signature_algorithm(VALUE self)
325 {
326  X509 *x509;
327  BIO *out;
328  VALUE str;
329 
330  GetX509(self, x509);
331  out = BIO_new(BIO_s_mem());
332  if (!out) ossl_raise(eX509CertError, NULL);
333 
334  if (!i2a_ASN1_OBJECT(out, X509_get0_tbs_sigalg(x509)->algorithm)) {
335  BIO_free(out);
337  }
338  str = ossl_membio2str(out);
339 
340  return str;
341 }
342 
343 /*
344  * call-seq:
345  * cert.subject => name
346  */
347 static VALUE
348 ossl_x509_get_subject(VALUE self)
349 {
350  X509 *x509;
351  X509_NAME *name;
352 
353  GetX509(self, x509);
354  if (!(name = X509_get_subject_name(x509))) { /* NO DUP - don't free! */
356  }
357 
358  return ossl_x509name_new(name);
359 }
360 
361 /*
362  * call-seq:
363  * cert.subject = name => name
364  */
365 static VALUE
366 ossl_x509_set_subject(VALUE self, VALUE subject)
367 {
368  X509 *x509;
369 
370  GetX509(self, x509);
371  if (!X509_set_subject_name(x509, GetX509NamePtr(subject))) { /* DUPs name */
373  }
374 
375  return subject;
376 }
377 
378 /*
379  * call-seq:
380  * cert.issuer => name
381  */
382 static VALUE
383 ossl_x509_get_issuer(VALUE self)
384 {
385  X509 *x509;
386  X509_NAME *name;
387 
388  GetX509(self, x509);
389  if(!(name = X509_get_issuer_name(x509))) { /* NO DUP - don't free! */
391  }
392 
393  return ossl_x509name_new(name);
394 }
395 
396 /*
397  * call-seq:
398  * cert.issuer = name => name
399  */
400 static VALUE
401 ossl_x509_set_issuer(VALUE self, VALUE issuer)
402 {
403  X509 *x509;
404 
405  GetX509(self, x509);
406  if (!X509_set_issuer_name(x509, GetX509NamePtr(issuer))) { /* DUPs name */
408  }
409 
410  return issuer;
411 }
412 
413 /*
414  * call-seq:
415  * cert.not_before => time
416  */
417 static VALUE
418 ossl_x509_get_not_before(VALUE self)
419 {
420  X509 *x509;
421  const ASN1_TIME *asn1time;
422 
423  GetX509(self, x509);
424  if (!(asn1time = X509_get0_notBefore(x509))) {
426  }
427 
428  return asn1time_to_time(asn1time);
429 }
430 
431 /*
432  * call-seq:
433  * cert.not_before = time => time
434  */
435 static VALUE
436 ossl_x509_set_not_before(VALUE self, VALUE time)
437 {
438  X509 *x509;
439  ASN1_TIME *asn1time;
440 
441  GetX509(self, x509);
442  asn1time = ossl_x509_time_adjust(NULL, time);
443  if (!X509_set_notBefore(x509, asn1time)) {
444  ASN1_TIME_free(asn1time);
445  ossl_raise(eX509CertError, "X509_set_notBefore");
446  }
447  ASN1_TIME_free(asn1time);
448 
449  return time;
450 }
451 
452 /*
453  * call-seq:
454  * cert.not_after => time
455  */
456 static VALUE
457 ossl_x509_get_not_after(VALUE self)
458 {
459  X509 *x509;
460  const ASN1_TIME *asn1time;
461 
462  GetX509(self, x509);
463  if (!(asn1time = X509_get0_notAfter(x509))) {
465  }
466 
467  return asn1time_to_time(asn1time);
468 }
469 
470 /*
471  * call-seq:
472  * cert.not_after = time => time
473  */
474 static VALUE
475 ossl_x509_set_not_after(VALUE self, VALUE time)
476 {
477  X509 *x509;
478  ASN1_TIME *asn1time;
479 
480  GetX509(self, x509);
481  asn1time = ossl_x509_time_adjust(NULL, time);
482  if (!X509_set_notAfter(x509, asn1time)) {
483  ASN1_TIME_free(asn1time);
484  ossl_raise(eX509CertError, "X509_set_notAfter");
485  }
486  ASN1_TIME_free(asn1time);
487 
488  return time;
489 }
490 
491 /*
492  * call-seq:
493  * cert.public_key => key
494  */
495 static VALUE
496 ossl_x509_get_public_key(VALUE self)
497 {
498  X509 *x509;
499  EVP_PKEY *pkey;
500 
501  GetX509(self, x509);
502  if (!(pkey = X509_get_pubkey(x509))) { /* adds an reference */
504  }
505 
506  return ossl_pkey_new(pkey); /* NO DUP - OK */
507 }
508 
509 /*
510  * call-seq:
511  * cert.public_key = key => key
512  */
513 static VALUE
514 ossl_x509_set_public_key(VALUE self, VALUE key)
515 {
516  X509 *x509;
517 
518  GetX509(self, x509);
519  if (!X509_set_pubkey(x509, GetPKeyPtr(key))) { /* DUPs pkey */
521  }
522 
523  return key;
524 }
525 
526 /*
527  * call-seq:
528  * cert.sign(key, digest) => self
529  */
530 static VALUE
531 ossl_x509_sign(VALUE self, VALUE key, VALUE digest)
532 {
533  X509 *x509;
534  EVP_PKEY *pkey;
535  const EVP_MD *md;
536 
537  pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
538  md = ossl_evp_get_digestbyname(digest);
539  GetX509(self, x509);
540  if (!X509_sign(x509, pkey, md)) {
542  }
543 
544  return self;
545 }
546 
547 /*
548  * call-seq:
549  * cert.verify(key) => true | false
550  *
551  * Verifies the signature of the certificate, with the public key _key_. _key_
552  * must be an instance of OpenSSL::PKey.
553  */
554 static VALUE
555 ossl_x509_verify(VALUE self, VALUE key)
556 {
557  X509 *x509;
558  EVP_PKEY *pkey;
559 
560  pkey = GetPKeyPtr(key); /* NO NEED TO DUP */
561  GetX509(self, x509);
562 
563  switch (X509_verify(x509, pkey)) {
564  case 1:
565  return Qtrue;
566  case 0:
568  return Qfalse;
569  default:
571  }
572 }
573 
574 /*
575  * call-seq:
576  * cert.check_private_key(key) -> true | false
577  *
578  * Returns +true+ if _key_ is the corresponding private key to the Subject
579  * Public Key Information, +false+ otherwise.
580  */
581 static VALUE
582 ossl_x509_check_private_key(VALUE self, VALUE key)
583 {
584  X509 *x509;
585  EVP_PKEY *pkey;
586 
587  /* not needed private key, but should be */
588  pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
589  GetX509(self, x509);
590  if (!X509_check_private_key(x509, pkey)) {
592  return Qfalse;
593  }
594 
595  return Qtrue;
596 }
597 
598 /*
599  * call-seq:
600  * cert.extensions => [extension...]
601  */
602 static VALUE
603 ossl_x509_get_extensions(VALUE self)
604 {
605  X509 *x509;
606  int count, i;
607  X509_EXTENSION *ext;
608  VALUE ary;
609 
610  GetX509(self, x509);
611  count = X509_get_ext_count(x509);
612  if (count < 0) {
613  return rb_ary_new();
614  }
615  ary = rb_ary_new2(count);
616  for (i=0; i<count; i++) {
617  ext = X509_get_ext(x509, i); /* NO DUP - don't free! */
618  rb_ary_push(ary, ossl_x509ext_new(ext));
619  }
620 
621  return ary;
622 }
623 
624 /*
625  * call-seq:
626  * cert.extensions = [ext...] => [ext...]
627  */
628 static VALUE
629 ossl_x509_set_extensions(VALUE self, VALUE ary)
630 {
631  X509 *x509;
632  X509_EXTENSION *ext;
633  long i;
634 
635  Check_Type(ary, T_ARRAY);
636  /* All ary's members should be X509Extension */
637  for (i=0; i<RARRAY_LEN(ary); i++) {
639  }
640  GetX509(self, x509);
641  while ((ext = X509_delete_ext(x509, 0)))
642  X509_EXTENSION_free(ext);
643  for (i=0; i<RARRAY_LEN(ary); i++) {
644  ext = GetX509ExtPtr(RARRAY_AREF(ary, i));
645  if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext */
647  }
648  }
649 
650  return ary;
651 }
652 
653 /*
654  * call-seq:
655  * cert.add_extension(extension) => extension
656  */
657 static VALUE
658 ossl_x509_add_extension(VALUE self, VALUE extension)
659 {
660  X509 *x509;
661  X509_EXTENSION *ext;
662 
663  GetX509(self, x509);
664  ext = GetX509ExtPtr(extension);
665  if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
667  }
668 
669  return extension;
670 }
671 
672 static VALUE
673 ossl_x509_inspect(VALUE self)
674 {
675  return rb_sprintf("#<%"PRIsVALUE": subject=%+"PRIsVALUE", "
676  "issuer=%+"PRIsVALUE", serial=%+"PRIsVALUE", "
677  "not_before=%+"PRIsVALUE", not_after=%+"PRIsVALUE">",
678  rb_obj_class(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));
684 }
685 
686 /*
687  * INIT
688  */
689 void
691 {
692 #if 0
693  mOSSL = rb_define_module("OpenSSL");
696 #endif
697 
698  eX509CertError = rb_define_class_under(mX509, "CertificateError", eOSSLError);
699 
700  /* Document-class: OpenSSL::X509::Certificate
701  *
702  * Implementation of an X.509 certificate as specified in RFC 5280.
703  * Provides access to a certificate's attributes and allows certificates
704  * to be read from a string, but also supports the creation of new
705  * certificates from scratch.
706  *
707  * === Reading a certificate from a file
708  *
709  * Certificate is capable of handling DER-encoded certificates and
710  * certificates encoded in OpenSSL's PEM format.
711  *
712  * raw = File.read "cert.cer" # DER- or PEM-encoded
713  * certificate = OpenSSL::X509::Certificate.new raw
714  *
715  * === Saving a certificate to a file
716  *
717  * A certificate may be encoded in DER format
718  *
719  * cert = ...
720  * File.open("cert.cer", "wb") { |f| f.print cert.to_der }
721  *
722  * or in PEM format
723  *
724  * cert = ...
725  * File.open("cert.pem", "wb") { |f| f.print cert.to_pem }
726  *
727  * X.509 certificates are associated with a private/public key pair,
728  * typically a RSA, DSA or ECC key (see also OpenSSL::PKey::RSA,
729  * OpenSSL::PKey::DSA and OpenSSL::PKey::EC), the public key itself is
730  * stored within the certificate and can be accessed in form of an
731  * OpenSSL::PKey. Certificates are typically used to be able to associate
732  * some form of identity with a key pair, for example web servers serving
733  * pages over HTTPs use certificates to authenticate themselves to the user.
734  *
735  * The public key infrastructure (PKI) model relies on trusted certificate
736  * authorities ("root CAs") that issue these certificates, so that end
737  * users need to base their trust just on a selected few authorities
738  * that themselves again vouch for subordinate CAs issuing their
739  * certificates to end users.
740  *
741  * The OpenSSL::X509 module provides the tools to set up an independent
742  * PKI, similar to scenarios where the 'openssl' command line tool is
743  * used for issuing certificates in a private PKI.
744  *
745  * === Creating a root CA certificate and an end-entity certificate
746  *
747  * First, we need to create a "self-signed" root certificate. To do so,
748  * we need to generate a key first. Please note that the choice of "1"
749  * as a serial number is considered a security flaw for real certificates.
750  * Secure choices are integers in the two-digit byte range and ideally
751  * not sequential but secure random numbers, steps omitted here to keep
752  * the example concise.
753  *
754  * root_key = OpenSSL::PKey::RSA.new 2048 # the CA's public/private key
755  * root_ca = OpenSSL::X509::Certificate.new
756  * root_ca.version = 2 # cf. RFC 5280 - to make it a "v3" certificate
757  * root_ca.serial = 1
758  * root_ca.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby CA"
759  * root_ca.issuer = root_ca.subject # root CA's are "self-signed"
760  * root_ca.public_key = root_key.public_key
761  * root_ca.not_before = Time.now
762  * root_ca.not_after = root_ca.not_before + 2 * 365 * 24 * 60 * 60 # 2 years validity
763  * ef = OpenSSL::X509::ExtensionFactory.new
764  * ef.subject_certificate = root_ca
765  * ef.issuer_certificate = root_ca
766  * root_ca.add_extension(ef.create_extension("basicConstraints","CA:TRUE",true))
767  * root_ca.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true))
768  * root_ca.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
769  * root_ca.add_extension(ef.create_extension("authorityKeyIdentifier","keyid:always",false))
770  * root_ca.sign(root_key, OpenSSL::Digest::SHA256.new)
771  *
772  * The next step is to create the end-entity certificate using the root CA
773  * certificate.
774  *
775  * key = OpenSSL::PKey::RSA.new 2048
776  * cert = OpenSSL::X509::Certificate.new
777  * cert.version = 2
778  * cert.serial = 2
779  * cert.subject = OpenSSL::X509::Name.parse "/DC=org/DC=ruby-lang/CN=Ruby certificate"
780  * cert.issuer = root_ca.subject # root CA is the issuer
781  * cert.public_key = key.public_key
782  * cert.not_before = Time.now
783  * cert.not_after = cert.not_before + 1 * 365 * 24 * 60 * 60 # 1 years validity
784  * ef = OpenSSL::X509::ExtensionFactory.new
785  * ef.subject_certificate = cert
786  * ef.issuer_certificate = root_ca
787  * cert.add_extension(ef.create_extension("keyUsage","digitalSignature", true))
788  * cert.add_extension(ef.create_extension("subjectKeyIdentifier","hash",false))
789  * cert.sign(root_key, OpenSSL::Digest::SHA256.new)
790  *
791  */
792  cX509Cert = rb_define_class_under(mX509, "Certificate", rb_cObject);
793 
794  rb_define_alloc_func(cX509Cert, ossl_x509_alloc);
795  rb_define_method(cX509Cert, "initialize", ossl_x509_initialize, -1);
796  rb_define_method(cX509Cert, "initialize_copy", ossl_x509_copy, 1);
797 
798  rb_define_method(cX509Cert, "to_der", ossl_x509_to_der, 0);
799  rb_define_method(cX509Cert, "to_pem", ossl_x509_to_pem, 0);
800  rb_define_alias(cX509Cert, "to_s", "to_pem");
801  rb_define_method(cX509Cert, "to_text", ossl_x509_to_text, 0);
802  rb_define_method(cX509Cert, "version", ossl_x509_get_version, 0);
803  rb_define_method(cX509Cert, "version=", ossl_x509_set_version, 1);
804  rb_define_method(cX509Cert, "signature_algorithm", ossl_x509_get_signature_algorithm, 0);
805  rb_define_method(cX509Cert, "serial", ossl_x509_get_serial, 0);
806  rb_define_method(cX509Cert, "serial=", ossl_x509_set_serial, 1);
807  rb_define_method(cX509Cert, "subject", ossl_x509_get_subject, 0);
808  rb_define_method(cX509Cert, "subject=", ossl_x509_set_subject, 1);
809  rb_define_method(cX509Cert, "issuer", ossl_x509_get_issuer, 0);
810  rb_define_method(cX509Cert, "issuer=", ossl_x509_set_issuer, 1);
811  rb_define_method(cX509Cert, "not_before", ossl_x509_get_not_before, 0);
812  rb_define_method(cX509Cert, "not_before=", ossl_x509_set_not_before, 1);
813  rb_define_method(cX509Cert, "not_after", ossl_x509_get_not_after, 0);
814  rb_define_method(cX509Cert, "not_after=", ossl_x509_set_not_after, 1);
815  rb_define_method(cX509Cert, "public_key", ossl_x509_get_public_key, 0);
816  rb_define_method(cX509Cert, "public_key=", ossl_x509_set_public_key, 1);
817  rb_define_method(cX509Cert, "sign", ossl_x509_sign, 2);
818  rb_define_method(cX509Cert, "verify", ossl_x509_verify, 1);
819  rb_define_method(cX509Cert, "check_private_key", ossl_x509_check_private_key, 1);
820  rb_define_method(cX509Cert, "extensions", ossl_x509_get_extensions, 0);
821  rb_define_method(cX509Cert, "extensions=", ossl_x509_set_extensions, 1);
822  rb_define_method(cX509Cert, "add_extension", ossl_x509_add_extension, 1);
823  rb_define_method(cX509Cert, "inspect", ossl_x509_inspect, 0);
824 }
#define NewX509(klass)
Definition: ossl_x509cert.c:12
VALUE mOSSL
Definition: ossl.c:231
#define RARRAY_LEN(a)
Definition: ruby.h:1019
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1138
int count
Definition: encoding.c:56
#define X509_up_ref(x)
#define Qtrue
Definition: ruby.h:437
EVP_PKEY * GetPrivPKeyPtr(VALUE obj)
Definition: ossl_pkey.c:216
#define ossl_str_adjust(str, p)
Definition: ossl.h:82
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:924
#define X509_get0_notBefore(x)
ASN1_TIME * ossl_x509_time_adjust(ASN1_TIME *s, VALUE time)
Definition: ossl_x509.c:19
BIO * ossl_obj2bio(volatile VALUE *pobj)
Definition: ossl_bio.c:13
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:693
#define Check_Type(v, t)
Definition: ruby.h:562
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE cX509Ext
Definition: ossl_x509ext.c:43
#define DATA_PTR(dta)
Definition: ruby.h:1106
#define T_ARRAY
Definition: ruby.h:498
VALUE asn1integer_to_num(const ASN1_INTEGER *ai)
Definition: ossl_asn1.c:101
VALUE ossl_membio2str(BIO *bio)
Definition: ossl_bio.c:29
VALUE ossl_x509_new(X509 *x509)
Definition: ossl_x509cert.c:51
VALUE ossl_pkey_new(EVP_PKEY *pkey)
Definition: ossl_pkey.c:107
X509_NAME * GetX509NamePtr(VALUE)
Definition: ossl_x509name.c:76
#define rb_ary_new2
Definition: intern.h:90
const unsigned char * in
Definition: ossl_ssl.c:617
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
Definition: object.c:277
void Init_ossl_x509cert(void)
#define GetX509(obj, x509)
Definition: ossl_x509cert.c:20
VALUE ossl_to_der_if_possible(VALUE obj)
Definition: ossl.c:255
void ossl_clear_error(void)
Definition: ossl.c:304
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1893
VALUE rb_ary_new(void)
Definition: array.c:499
#define OSSL_BIO_reset(bio)
Definition: ossl.h:110
VALUE eOSSLError
Definition: ossl.c:236
int argc
Definition: ruby.c:187
#define Qfalse
Definition: ruby.h:436
VALUE ossl_x509ext_new(X509_EXTENSION *)
Definition: ossl_x509ext.c:65
VALUE cX509Cert
Definition: ossl_x509cert.c:30
X509 * DupX509CertPtr(VALUE obj)
Definition: ossl_x509cert.c:81
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1758
const EVP_MD * ossl_evp_get_digestbyname(VALUE obj)
Definition: ossl_digest.c:45
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1452
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1908
#define PRIsVALUE
Definition: ruby.h:135
VALUE eX509CertError
Definition: ossl_x509cert.c:31
VALUE rb_eStandardError
Definition: error.c:799
unsigned long VALUE
Definition: ruby.h:85
#define X509_get0_notAfter(x)
VALUE mX509
Definition: ossl_x509.c:12
#define X509_get0_tbs_sigalg(x)
#define LONG2NUM(x)
Definition: ruby.h:1573
register unsigned int len
Definition: zonetab.h:51
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:790
X509_EXTENSION * GetX509ExtPtr(VALUE)
Definition: ossl_x509ext.c:85
#define RSTRING_PTR(str)
Definition: ruby.h:975
#define RARRAY_AREF(a, i)
Definition: ruby.h:1033
VALUE asn1time_to_time(const ASN1_TIME *time)
Definition: ossl_asn1.c:20
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:52
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:293
EVP_PKEY * GetPKeyPtr(VALUE obj)
Definition: ossl_pkey.c:206
const char * name
Definition: nkf.c:208
#define SetX509(obj, x509)
Definition: ossl_x509cert.c:14
VALUE ossl_x509name_new(X509_NAME *)
Definition: ossl_x509name.c:56
#define rb_check_frozen(obj)
Definition: intern.h:271
X509 * GetX509CertPtr(VALUE obj)
Definition: ossl_x509cert.c:71
VALUE rb_define_module(const char *name)
Definition: class.c:768
#define NULL
Definition: _sdbm.c:102
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1515
#define NUM2LONG(x)
Definition: ruby.h:648
char ** argv
Definition: ruby.c:188
VALUE rb_str_new(const char *, long)
Definition: string.c:737
ASN1_INTEGER * num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
Definition: ossl_asn1.c:124