openssl 3.2.4 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +180 -29
  3. data/History.md +69 -42
  4. data/README.md +11 -7
  5. data/ext/openssl/extconf.rb +6 -5
  6. data/ext/openssl/openssl_missing.c +1 -2
  7. data/ext/openssl/openssl_missing.h +1 -28
  8. data/ext/openssl/ossl.c +8 -10
  9. data/ext/openssl/ossl.h +13 -10
  10. data/ext/openssl/ossl_asn1.c +77 -273
  11. data/ext/openssl/ossl_asn1.h +1 -19
  12. data/ext/openssl/ossl_bio.c +1 -1
  13. data/ext/openssl/ossl_bio.h +1 -1
  14. data/ext/openssl/ossl_bn.c +12 -12
  15. data/ext/openssl/ossl_bn.h +1 -2
  16. data/ext/openssl/ossl_cipher.c +5 -5
  17. data/ext/openssl/ossl_cipher.h +1 -4
  18. data/ext/openssl/ossl_config.c +10 -9
  19. data/ext/openssl/ossl_config.h +1 -1
  20. data/ext/openssl/ossl_digest.c +39 -21
  21. data/ext/openssl/ossl_digest.h +1 -4
  22. data/ext/openssl/ossl_engine.c +3 -3
  23. data/ext/openssl/ossl_engine.h +1 -4
  24. data/ext/openssl/ossl_hmac.c +3 -3
  25. data/ext/openssl/ossl_hmac.h +1 -4
  26. data/ext/openssl/ossl_kdf.c +5 -5
  27. data/ext/openssl/ossl_ns_spki.c +13 -12
  28. data/ext/openssl/ossl_ns_spki.h +1 -5
  29. data/ext/openssl/ossl_ocsp.c +16 -16
  30. data/ext/openssl/ossl_ocsp.h +1 -8
  31. data/ext/openssl/ossl_pkcs12.c +54 -3
  32. data/ext/openssl/ossl_pkcs12.h +1 -4
  33. data/ext/openssl/ossl_pkcs7.c +69 -22
  34. data/ext/openssl/ossl_pkcs7.h +2 -22
  35. data/ext/openssl/ossl_pkey.c +22 -63
  36. data/ext/openssl/ossl_pkey.h +3 -14
  37. data/ext/openssl/ossl_pkey_dh.c +2 -4
  38. data/ext/openssl/ossl_pkey_dsa.c +2 -4
  39. data/ext/openssl/ossl_pkey_ec.c +6 -8
  40. data/ext/openssl/ossl_pkey_rsa.c +2 -4
  41. data/ext/openssl/ossl_provider.c +3 -1
  42. data/ext/openssl/ossl_rand.c +3 -3
  43. data/ext/openssl/ossl_rand.h +1 -4
  44. data/ext/openssl/ossl_ssl.c +71 -52
  45. data/ext/openssl/ossl_ssl.h +1 -1
  46. data/ext/openssl/ossl_ts.c +77 -19
  47. data/ext/openssl/ossl_ts.h +1 -1
  48. data/ext/openssl/ossl_x509.c +1 -1
  49. data/ext/openssl/ossl_x509.h +7 -26
  50. data/ext/openssl/ossl_x509attr.c +30 -32
  51. data/ext/openssl/ossl_x509cert.c +48 -9
  52. data/ext/openssl/ossl_x509crl.c +13 -9
  53. data/ext/openssl/ossl_x509ext.c +12 -21
  54. data/ext/openssl/ossl_x509name.c +8 -10
  55. data/ext/openssl/ossl_x509req.c +10 -6
  56. data/ext/openssl/ossl_x509revoked.c +5 -6
  57. data/ext/openssl/ossl_x509store.c +21 -14
  58. data/lib/openssl/asn1.rb +188 -0
  59. data/lib/openssl/bn.rb +1 -1
  60. data/lib/openssl/buffering.rb +13 -3
  61. data/lib/openssl/cipher.rb +1 -1
  62. data/lib/openssl/digest.rb +1 -1
  63. data/lib/openssl/marshal.rb +1 -1
  64. data/lib/openssl/ssl.rb +68 -4
  65. data/lib/openssl/version.rb +1 -1
  66. data/lib/openssl/x509.rb +1 -1
  67. data/lib/openssl.rb +2 -1
  68. metadata +9 -4
  69. /data/{LICENSE.txt → COPYING} +0 -0
@@ -7,7 +7,7 @@
7
7
  */
8
8
  /*
9
9
  * This program is licensed under the same licence as Ruby.
10
- * (See the file 'LICENCE'.)
10
+ * (See the file 'COPYING'.)
11
11
  */
12
12
  #include "ossl.h"
13
13
 
@@ -35,7 +35,7 @@
35
35
 
36
36
  VALUE mSSL;
37
37
  static VALUE eSSLError;
38
- VALUE cSSLContext;
38
+ static VALUE cSSLContext;
39
39
  VALUE cSSLSocket;
40
40
 
41
41
  static VALUE eSSLErrorWaitReadable;
@@ -55,7 +55,6 @@ static ID id_i_cert_store, id_i_ca_file, id_i_ca_path, id_i_verify_mode,
55
55
  id_i_verify_hostname, id_i_keylog_cb;
56
56
  static ID id_i_io, id_i_context, id_i_hostname;
57
57
 
58
- static int ossl_ssl_ex_vcb_idx;
59
58
  static int ossl_ssl_ex_ptr_idx;
60
59
  static int ossl_sslctx_ex_ptr_idx;
61
60
 
@@ -327,9 +326,9 @@ ossl_ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
327
326
  int status;
328
327
 
329
328
  ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
330
- cb = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_vcb_idx);
331
329
  ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
332
330
  sslctx_obj = rb_attr_get(ssl_obj, id_i_context);
331
+ cb = rb_attr_get(sslctx_obj, id_i_verify_callback);
333
332
  verify_hostname = rb_attr_get(sslctx_obj, id_i_verify_hostname);
334
333
 
335
334
  if (preverify_ok && RTEST(verify_hostname) && !SSL_is_server(ssl) &&
@@ -558,52 +557,42 @@ ossl_sslctx_add_extra_chain_cert_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
558
557
  static VALUE ossl_sslctx_setup(VALUE self);
559
558
 
560
559
  static VALUE
561
- ossl_call_servername_cb(VALUE ary)
560
+ ossl_call_servername_cb(VALUE arg)
562
561
  {
563
- VALUE ssl_obj, sslctx_obj, cb, ret_obj;
562
+ SSL *ssl = (void *)arg;
563
+ const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
564
+ if (!servername)
565
+ return Qnil;
564
566
 
565
- Check_Type(ary, T_ARRAY);
566
- ssl_obj = rb_ary_entry(ary, 0);
567
+ VALUE ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
568
+ VALUE sslctx_obj = rb_attr_get(ssl_obj, id_i_context);
569
+ VALUE cb = rb_attr_get(sslctx_obj, id_i_servername_cb);
570
+ VALUE ary = rb_assoc_new(ssl_obj, rb_str_new_cstr(servername));
567
571
 
568
- sslctx_obj = rb_attr_get(ssl_obj, id_i_context);
569
- cb = rb_attr_get(sslctx_obj, id_i_servername_cb);
570
- if (NIL_P(cb)) return Qnil;
571
-
572
- ret_obj = rb_funcallv(cb, id_call, 1, &ary);
572
+ VALUE ret_obj = rb_funcallv(cb, id_call, 1, &ary);
573
573
  if (rb_obj_is_kind_of(ret_obj, cSSLContext)) {
574
- SSL *ssl;
575
574
  SSL_CTX *ctx2;
576
-
577
575
  ossl_sslctx_setup(ret_obj);
578
- GetSSL(ssl_obj, ssl);
579
576
  GetSSLCTX(ret_obj, ctx2);
580
- SSL_set_SSL_CTX(ssl, ctx2);
577
+ if (!SSL_set_SSL_CTX(ssl, ctx2))
578
+ ossl_raise(eSSLError, "SSL_set_SSL_CTX");
581
579
  rb_ivar_set(ssl_obj, id_i_context, ret_obj);
582
580
  } else if (!NIL_P(ret_obj)) {
583
581
  ossl_raise(rb_eArgError, "servername_cb must return an "
584
582
  "OpenSSL::SSL::SSLContext object or nil");
585
583
  }
586
584
 
587
- return ret_obj;
585
+ return Qnil;
588
586
  }
589
587
 
590
588
  static int
591
589
  ssl_servername_cb(SSL *ssl, int *ad, void *arg)
592
590
  {
593
- VALUE ary, ssl_obj;
594
- int state = 0;
595
- const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
596
-
597
- if (!servername)
598
- return SSL_TLSEXT_ERR_OK;
599
-
600
- ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
601
- ary = rb_ary_new2(2);
602
- rb_ary_push(ary, ssl_obj);
603
- rb_ary_push(ary, rb_str_new2(servername));
591
+ int state;
604
592
 
605
- rb_protect(ossl_call_servername_cb, ary, &state);
593
+ rb_protect(ossl_call_servername_cb, (VALUE)ssl, &state);
606
594
  if (state) {
595
+ VALUE ssl_obj = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
607
596
  rb_ivar_set(ssl_obj, ID_callback_state, INT2NUM(state));
608
597
  return SSL_TLSEXT_ERR_ALERT_FATAL;
609
598
  }
@@ -757,7 +746,10 @@ ssl_info_cb(const SSL *ssl, int where, int val)
757
746
  }
758
747
 
759
748
  /*
760
- * Gets various OpenSSL options.
749
+ * call-seq:
750
+ * ctx.options -> integer
751
+ *
752
+ * Gets various \OpenSSL options.
761
753
  */
762
754
  static VALUE
763
755
  ossl_sslctx_get_options(VALUE self)
@@ -772,7 +764,17 @@ ossl_sslctx_get_options(VALUE self)
772
764
  }
773
765
 
774
766
  /*
775
- * Sets various OpenSSL options.
767
+ * call-seq:
768
+ * ctx.options = integer
769
+ *
770
+ * Sets various \OpenSSL options. The options are a bit field and can be
771
+ * combined with the bitwise OR operator (<tt>|</tt>). Available options are
772
+ * defined as constants in OpenSSL::SSL that begin with +OP_+.
773
+ *
774
+ * For backwards compatibility, passing +nil+ has the same effect as passing
775
+ * OpenSSL::SSL::OP_ALL.
776
+ *
777
+ * See also man page SSL_CTX_set_options(3).
776
778
  */
777
779
  static VALUE
778
780
  ossl_sslctx_set_options(VALUE self, VALUE options)
@@ -1553,11 +1555,6 @@ ossl_ssl_mark(void *ptr)
1553
1555
  {
1554
1556
  SSL *ssl = ptr;
1555
1557
  rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx));
1556
-
1557
- // Note: this reference is stored as @verify_callback so we don't need to mark it.
1558
- // However we do need to ensure GC compaction won't move it, hence why
1559
- // we call rb_gc_mark here.
1560
- rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_vcb_idx));
1561
1558
  }
1562
1559
 
1563
1560
  static void
@@ -1622,7 +1619,7 @@ peeraddr_ip_str(VALUE self)
1622
1619
  static VALUE
1623
1620
  ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
1624
1621
  {
1625
- VALUE io, v_ctx, verify_cb;
1622
+ VALUE io, v_ctx;
1626
1623
  SSL *ssl;
1627
1624
  SSL_CTX *ctx;
1628
1625
 
@@ -1649,10 +1646,6 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
1649
1646
 
1650
1647
  SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void *)self);
1651
1648
  SSL_set_info_callback(ssl, ssl_info_cb);
1652
- verify_cb = rb_attr_get(v_ctx, id_i_verify_callback);
1653
- // We don't need to trigger a write barrier because it's already
1654
- // an instance variable of this object.
1655
- SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)verify_cb);
1656
1649
 
1657
1650
  rb_call_super(0, NULL);
1658
1651
 
@@ -1725,11 +1718,20 @@ no_exception_p(VALUE opts)
1725
1718
  #define RUBY_IO_TIMEOUT_DEFAULT Qnil
1726
1719
  #endif
1727
1720
 
1721
+ #ifdef HAVE_RB_IO_TIMEOUT
1722
+ #define IO_TIMEOUT_ERROR rb_eIOTimeoutError
1723
+ #else
1724
+ #define IO_TIMEOUT_ERROR rb_eIOError
1725
+ #endif
1726
+
1727
+
1728
1728
  static void
1729
1729
  io_wait_writable(VALUE io)
1730
1730
  {
1731
1731
  #ifdef HAVE_RB_IO_MAYBE_WAIT
1732
- rb_io_maybe_wait_writable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
1732
+ if (!rb_io_maybe_wait_writable(errno, io, RUBY_IO_TIMEOUT_DEFAULT)) {
1733
+ rb_raise(IO_TIMEOUT_ERROR, "Timed out while waiting to become writable!");
1734
+ }
1733
1735
  #else
1734
1736
  rb_io_t *fptr;
1735
1737
  GetOpenFile(io, fptr);
@@ -1741,7 +1743,9 @@ static void
1741
1743
  io_wait_readable(VALUE io)
1742
1744
  {
1743
1745
  #ifdef HAVE_RB_IO_MAYBE_WAIT
1744
- rb_io_maybe_wait_readable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
1746
+ if (!rb_io_maybe_wait_readable(errno, io, RUBY_IO_TIMEOUT_DEFAULT)) {
1747
+ rb_raise(IO_TIMEOUT_ERROR, "Timed out while waiting to become readable!");
1748
+ }
1745
1749
  #else
1746
1750
  rb_io_t *fptr;
1747
1751
  GetOpenFile(io, fptr);
@@ -1925,7 +1929,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1925
1929
  {
1926
1930
  SSL *ssl;
1927
1931
  int ilen;
1928
- VALUE len, str;
1932
+ VALUE len, str, cb_state;
1929
1933
  VALUE opts = Qnil;
1930
1934
 
1931
1935
  if (nonblock) {
@@ -1947,15 +1951,25 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1947
1951
  else
1948
1952
  rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
1949
1953
  }
1950
- rb_str_set_len(str, 0);
1951
- if (ilen == 0)
1952
- return str;
1954
+
1955
+ if (ilen == 0) {
1956
+ rb_str_set_len(str, 0);
1957
+ return str;
1958
+ }
1953
1959
 
1954
1960
  VALUE io = rb_attr_get(self, id_i_io);
1955
1961
 
1956
1962
  rb_str_locktmp(str);
1957
1963
  for (;;) {
1958
1964
  int nread = SSL_read(ssl, RSTRING_PTR(str), ilen);
1965
+
1966
+ cb_state = rb_attr_get(self, ID_callback_state);
1967
+ if (!NIL_P(cb_state)) {
1968
+ rb_ivar_set(self, ID_callback_state, Qnil);
1969
+ ossl_clear_error();
1970
+ rb_jump_tag(NUM2INT(cb_state));
1971
+ }
1972
+
1959
1973
  switch (ssl_get_error(ssl, nread)) {
1960
1974
  case SSL_ERROR_NONE:
1961
1975
  rb_str_unlocktmp(str);
@@ -2045,7 +2059,7 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
2045
2059
  SSL *ssl;
2046
2060
  rb_io_t *fptr;
2047
2061
  int num, nonblock = opts != Qfalse;
2048
- VALUE tmp;
2062
+ VALUE tmp, cb_state;
2049
2063
 
2050
2064
  GetSSL(self, ssl);
2051
2065
  if (!ssl_started(ssl))
@@ -2062,6 +2076,14 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
2062
2076
 
2063
2077
  for (;;) {
2064
2078
  int nwritten = SSL_write(ssl, RSTRING_PTR(tmp), num);
2079
+
2080
+ cb_state = rb_attr_get(self, ID_callback_state);
2081
+ if (!NIL_P(cb_state)) {
2082
+ rb_ivar_set(self, ID_callback_state, Qnil);
2083
+ ossl_clear_error();
2084
+ rb_jump_tag(NUM2INT(cb_state));
2085
+ }
2086
+
2065
2087
  switch (ssl_get_error(ssl, nwritten)) {
2066
2088
  case SSL_ERROR_NONE:
2067
2089
  return INT2NUM(nwritten);
@@ -2590,9 +2612,6 @@ Init_ossl_ssl(void)
2590
2612
  id_call = rb_intern_const("call");
2591
2613
  ID_callback_state = rb_intern_const("callback_state");
2592
2614
 
2593
- ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0, (void *)"ossl_ssl_ex_vcb_idx", 0, 0, 0);
2594
- if (ossl_ssl_ex_vcb_idx < 0)
2595
- ossl_raise(rb_eRuntimeError, "SSL_get_ex_new_index");
2596
2615
  ossl_ssl_ex_ptr_idx = SSL_get_ex_new_index(0, (void *)"ossl_ssl_ex_ptr_idx", 0, 0, 0);
2597
2616
  if (ossl_ssl_ex_ptr_idx < 0)
2598
2617
  ossl_raise(rb_eRuntimeError, "SSL_get_ex_new_index");
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_SSL_H_)
11
11
  #define _OSSL_SSL_H_
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licenced under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -161,8 +161,11 @@ get_asn1obj(ASN1_OBJECT *obj)
161
161
  ret = rb_str_new2(OBJ_nid2sn(nid));
162
162
  else{
163
163
  if (!(out = BIO_new(BIO_s_mem())))
164
- ossl_raise(eX509AttrError, NULL);
165
- i2a_ASN1_OBJECT(out, obj);
164
+ ossl_raise(eTimestampError, "BIO_new(BIO_s_mem())");
165
+ if (i2a_ASN1_OBJECT(out, obj) <= 0) {
166
+ BIO_free(out);
167
+ ossl_raise(eTimestampError, "i2a_ASN1_OBJECT");
168
+ }
166
169
  ret = ossl_membio2str(out);
167
170
  }
168
171
 
@@ -288,7 +291,7 @@ ossl_ts_req_get_msg_imprint(VALUE self)
288
291
  mi = TS_REQ_get_msg_imprint(req);
289
292
  hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
290
293
 
291
- ret = asn1str_to_str(hashed_msg);
294
+ ret = rb_str_new((const char *)hashed_msg->data, hashed_msg->length);
292
295
 
293
296
  return ret;
294
297
  }
@@ -497,12 +500,31 @@ ossl_ts_req_to_der(VALUE self)
497
500
  ossl_raise(eTimestampError, "Message imprint missing algorithm");
498
501
 
499
502
  hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
500
- if (!ASN1_STRING_length(hashed_msg))
503
+ if (!hashed_msg->length)
501
504
  ossl_raise(eTimestampError, "Message imprint missing hashed message");
502
505
 
503
506
  return asn1_to_der((void *)req, (int (*)(void *, unsigned char **))i2d_TS_REQ);
504
507
  }
505
508
 
509
+ static VALUE
510
+ ossl_ts_req_to_text(VALUE self)
511
+ {
512
+ TS_REQ *req;
513
+ BIO *out;
514
+
515
+ GetTSRequest(self, req);
516
+
517
+ out = BIO_new(BIO_s_mem());
518
+ if (!out) ossl_raise(eTimestampError, NULL);
519
+
520
+ if (!TS_REQ_print_bio(out, req)) {
521
+ BIO_free(out);
522
+ ossl_raise(eTimestampError, NULL);
523
+ }
524
+
525
+ return ossl_membio2str(out);
526
+ }
527
+
506
528
  static VALUE
507
529
  ossl_ts_resp_alloc(VALUE klass)
508
530
  {
@@ -672,21 +694,12 @@ static VALUE
672
694
  ossl_ts_resp_get_token(VALUE self)
673
695
  {
674
696
  TS_RESP *resp;
675
- PKCS7 *p7, *copy;
676
- VALUE obj;
697
+ PKCS7 *p7;
677
698
 
678
699
  GetTSResponse(self, resp);
679
700
  if (!(p7 = TS_RESP_get_token(resp)))
680
701
  return Qnil;
681
-
682
- obj = NewPKCS7(cPKCS7);
683
-
684
- if (!(copy = PKCS7_dup(p7)))
685
- ossl_raise(eTimestampError, NULL);
686
-
687
- SetPKCS7(obj, copy);
688
-
689
- return obj;
702
+ return ossl_pkcs7_new(p7);
690
703
  }
691
704
 
692
705
  /*
@@ -730,7 +743,7 @@ ossl_ts_resp_get_tsa_certificate(VALUE self)
730
743
  TS_RESP *resp;
731
744
  PKCS7 *p7;
732
745
  PKCS7_SIGNER_INFO *ts_info;
733
- const X509 *cert;
746
+ X509 *cert;
734
747
 
735
748
  GetTSResponse(self, resp);
736
749
  if (!(p7 = TS_RESP_get_token(resp)))
@@ -757,6 +770,25 @@ ossl_ts_resp_to_der(VALUE self)
757
770
  return asn1_to_der((void *)resp, (int (*)(void *, unsigned char **))i2d_TS_RESP);
758
771
  }
759
772
 
773
+ static VALUE
774
+ ossl_ts_resp_to_text(VALUE self)
775
+ {
776
+ TS_RESP *resp;
777
+ BIO *out;
778
+
779
+ GetTSResponse(self, resp);
780
+
781
+ out = BIO_new(BIO_s_mem());
782
+ if (!out) ossl_raise(eTimestampError, NULL);
783
+
784
+ if (!TS_RESP_print_bio(out, resp)) {
785
+ BIO_free(out);
786
+ ossl_raise(eTimestampError, NULL);
787
+ }
788
+
789
+ return ossl_membio2str(out);
790
+ }
791
+
760
792
  /*
761
793
  * Verifies a timestamp token by checking the signature, validating the
762
794
  * certificate chain implied by tsa_certificate and by checking conformance to
@@ -974,7 +1006,7 @@ ossl_ts_token_info_get_msg_imprint(VALUE self)
974
1006
  GetTSTokenInfo(self, info);
975
1007
  mi = TS_TST_INFO_get_msg_imprint(info);
976
1008
  hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
977
- ret = asn1str_to_str(hashed_msg);
1009
+ ret = rb_str_new((const char *)hashed_msg->data, hashed_msg->length);
978
1010
 
979
1011
  return ret;
980
1012
  }
@@ -1073,6 +1105,25 @@ ossl_ts_token_info_to_der(VALUE self)
1073
1105
  return asn1_to_der((void *)info, (int (*)(void *, unsigned char **))i2d_TS_TST_INFO);
1074
1106
  }
1075
1107
 
1108
+ static VALUE
1109
+ ossl_ts_token_info_to_text(VALUE self)
1110
+ {
1111
+ TS_TST_INFO *info;
1112
+ BIO *out;
1113
+
1114
+ GetTSTokenInfo(self, info);
1115
+
1116
+ out = BIO_new(BIO_s_mem());
1117
+ if (!out) ossl_raise(eTimestampError, NULL);
1118
+
1119
+ if (!TS_TST_INFO_print_bio(out, info)) {
1120
+ BIO_free(out);
1121
+ ossl_raise(eTimestampError, NULL);
1122
+ }
1123
+
1124
+ return ossl_membio2str(out);
1125
+ }
1126
+
1076
1127
  static ASN1_INTEGER *
1077
1128
  ossl_tsfac_serial_cb(struct TS_resp_ctx *ctx, void *data)
1078
1129
  {
@@ -1356,6 +1407,7 @@ Init_ossl_ts(void)
1356
1407
  rb_define_method(cTimestampResponse, "token_info", ossl_ts_resp_get_token_info, 0);
1357
1408
  rb_define_method(cTimestampResponse, "tsa_certificate", ossl_ts_resp_get_tsa_certificate, 0);
1358
1409
  rb_define_method(cTimestampResponse, "to_der", ossl_ts_resp_to_der, 0);
1410
+ rb_define_method(cTimestampResponse, "to_text", ossl_ts_resp_to_text, 0);
1359
1411
  rb_define_method(cTimestampResponse, "verify", ossl_ts_resp_verify, -1);
1360
1412
 
1361
1413
  /* Document-class: OpenSSL::Timestamp::TokenInfo
@@ -1374,6 +1426,7 @@ Init_ossl_ts(void)
1374
1426
  rb_define_method(cTimestampTokenInfo, "ordering", ossl_ts_token_info_get_ordering, 0);
1375
1427
  rb_define_method(cTimestampTokenInfo, "nonce", ossl_ts_token_info_get_nonce, 0);
1376
1428
  rb_define_method(cTimestampTokenInfo, "to_der", ossl_ts_token_info_to_der, 0);
1429
+ rb_define_method(cTimestampTokenInfo, "to_text", ossl_ts_token_info_to_text, 0);
1377
1430
 
1378
1431
  /* Document-class: OpenSSL::Timestamp::Request
1379
1432
  * Allows to create timestamp requests or parse existing ones. A Request is
@@ -1399,6 +1452,7 @@ Init_ossl_ts(void)
1399
1452
  rb_define_method(cTimestampRequest, "cert_requested=", ossl_ts_req_set_cert_requested, 1);
1400
1453
  rb_define_method(cTimestampRequest, "cert_requested?", ossl_ts_req_get_cert_requested, 0);
1401
1454
  rb_define_method(cTimestampRequest, "to_der", ossl_ts_req_to_der, 0);
1455
+ rb_define_method(cTimestampRequest, "to_text", ossl_ts_req_to_text, 0);
1402
1456
 
1403
1457
  /*
1404
1458
  * Indicates a successful response. Equal to +0+.
@@ -1535,5 +1589,9 @@ Init_ossl_ts(void)
1535
1589
  rb_attr(cTimestampFactory, rb_intern_const("additional_certs"), 1, 1, 0);
1536
1590
  rb_define_method(cTimestampFactory, "create_timestamp", ossl_tsfac_create_ts, 3);
1537
1591
  }
1538
-
1592
+ #else /* OPENSSL_NO_TS */
1593
+ void
1594
+ Init_ossl_ts(void)
1595
+ {
1596
+ }
1539
1597
  #endif
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licenced under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
 
11
11
  #if !defined(_OSSL_TS_H_)
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #include "ossl.h"
11
11
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
  /*
7
7
  * This program is licensed under the same licence as Ruby.
8
- * (See the file 'LICENCE'.)
8
+ * (See the file 'COPYING'.)
9
9
  */
10
10
  #if !defined(_OSSL_X509_H_)
11
11
  #define _OSSL_X509_H_
@@ -28,9 +28,8 @@ void Init_ossl_x509(void);
28
28
  * X509Attr
29
29
  */
30
30
  extern VALUE cX509Attr;
31
- extern VALUE eX509AttrError;
32
31
 
33
- VALUE ossl_x509attr_new(const X509_ATTRIBUTE *);
32
+ VALUE ossl_x509attr_new(X509_ATTRIBUTE *);
34
33
  X509_ATTRIBUTE *GetX509AttrPtr(VALUE);
35
34
  void Init_ossl_x509attr(void);
36
35
 
@@ -38,9 +37,8 @@ void Init_ossl_x509attr(void);
38
37
  * X509Cert
39
38
  */
40
39
  extern VALUE cX509Cert;
41
- extern VALUE eX509CertError;
42
40
 
43
- VALUE ossl_x509_new(const X509 *);
41
+ VALUE ossl_x509_new(X509 *);
44
42
  X509 *GetX509CertPtr(VALUE);
45
43
  X509 *DupX509CertPtr(VALUE);
46
44
  void Init_ossl_x509cert(void);
@@ -48,10 +46,7 @@ void Init_ossl_x509cert(void);
48
46
  /*
49
47
  * X509CRL
50
48
  */
51
- extern VALUE cX509CRL;
52
- extern VALUE eX509CRLError;
53
-
54
- VALUE ossl_x509crl_new(const X509_CRL *);
49
+ VALUE ossl_x509crl_new(X509_CRL *);
55
50
  X509_CRL *GetX509CRLPtr(VALUE);
56
51
  void Init_ossl_x509crl(void);
57
52
 
@@ -59,29 +54,21 @@ void Init_ossl_x509crl(void);
59
54
  * X509Extension
60
55
  */
61
56
  extern VALUE cX509Ext;
62
- extern VALUE cX509ExtFactory;
63
- extern VALUE eX509ExtError;
64
57
 
65
- VALUE ossl_x509ext_new(const X509_EXTENSION *);
58
+ VALUE ossl_x509ext_new(X509_EXTENSION *);
66
59
  X509_EXTENSION *GetX509ExtPtr(VALUE);
67
60
  void Init_ossl_x509ext(void);
68
61
 
69
62
  /*
70
63
  * X509Name
71
64
  */
72
- extern VALUE cX509Name;
73
- extern VALUE eX509NameError;
74
-
75
- VALUE ossl_x509name_new(const X509_NAME *);
65
+ VALUE ossl_x509name_new(X509_NAME *);
76
66
  X509_NAME *GetX509NamePtr(VALUE);
77
67
  void Init_ossl_x509name(void);
78
68
 
79
69
  /*
80
70
  * X509Request
81
71
  */
82
- extern VALUE cX509Req;
83
- extern VALUE eX509ReqError;
84
-
85
72
  X509_REQ *GetX509ReqPtr(VALUE);
86
73
  void Init_ossl_x509req(void);
87
74
 
@@ -89,21 +76,15 @@ void Init_ossl_x509req(void);
89
76
  * X509Revoked
90
77
  */
91
78
  extern VALUE cX509Rev;
92
- extern VALUE eX509RevError;
93
79
 
94
- VALUE ossl_x509revoked_new(const X509_REVOKED *);
80
+ VALUE ossl_x509revoked_new(X509_REVOKED *);
95
81
  X509_REVOKED *DupX509RevokedPtr(VALUE);
96
82
  void Init_ossl_x509revoked(void);
97
83
 
98
84
  /*
99
85
  * X509Store and X509StoreContext
100
86
  */
101
- extern VALUE cX509Store;
102
- extern VALUE cX509StoreContext;
103
- extern VALUE eX509StoreError;
104
-
105
87
  X509_STORE *GetX509StorePtr(VALUE);
106
-
107
88
  void Init_ossl_x509store(void);
108
89
 
109
90
  /*