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