openssl 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,7 +77,7 @@ static const rb_data_type_t ossl_sslctx_type = {
77
77
  {
78
78
  ossl_sslctx_mark, ossl_sslctx_free,
79
79
  },
80
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
80
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
81
81
  };
82
82
 
83
83
  static VALUE
@@ -885,9 +885,9 @@ ossl_sslctx_setup(VALUE self)
885
885
  if (ca_path && !SSL_CTX_load_verify_dir(ctx, ca_path))
886
886
  ossl_raise(eSSLError, "SSL_CTX_load_verify_dir");
887
887
  #else
888
- if(ca_file || ca_path){
889
- if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
890
- rb_warning("can't set verify locations");
888
+ if (ca_file || ca_path) {
889
+ if (!SSL_CTX_load_verify_locations(ctx, ca_file, ca_path))
890
+ ossl_raise(eSSLError, "SSL_CTX_load_verify_locations");
891
891
  }
892
892
  #endif
893
893
 
@@ -1553,6 +1553,10 @@ ossl_ssl_mark(void *ptr)
1553
1553
  {
1554
1554
  SSL *ssl = ptr;
1555
1555
  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.
1556
1560
  rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_vcb_idx));
1557
1561
  }
1558
1562
 
@@ -1567,7 +1571,7 @@ const rb_data_type_t ossl_ssl_type = {
1567
1571
  {
1568
1572
  ossl_ssl_mark, ossl_ssl_free,
1569
1573
  },
1570
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
1574
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
1571
1575
  };
1572
1576
 
1573
1577
  static VALUE
@@ -1646,6 +1650,8 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
1646
1650
  SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void *)self);
1647
1651
  SSL_set_info_callback(ssl, ssl_info_cb);
1648
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.
1649
1655
  SSL_set_ex_data(ssl, ossl_ssl_ex_vcb_idx, (void *)verify_cb);
1650
1656
 
1651
1657
  rb_call_super(0, NULL);
@@ -1653,6 +1659,17 @@ ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
1653
1659
  return self;
1654
1660
  }
1655
1661
 
1662
+ #ifndef HAVE_RB_IO_DESCRIPTOR
1663
+ static int
1664
+ io_descriptor_fallback(VALUE io)
1665
+ {
1666
+ rb_io_t *fptr;
1667
+ GetOpenFile(io, fptr);
1668
+ return fptr->fd;
1669
+ }
1670
+ #define rb_io_descriptor io_descriptor_fallback
1671
+ #endif
1672
+
1656
1673
  static VALUE
1657
1674
  ossl_ssl_setup(VALUE self)
1658
1675
  {
@@ -1668,8 +1685,8 @@ ossl_ssl_setup(VALUE self)
1668
1685
  GetOpenFile(io, fptr);
1669
1686
  rb_io_check_readable(fptr);
1670
1687
  rb_io_check_writable(fptr);
1671
- if (!SSL_set_fd(ssl, TO_SOCKET(fptr->fd)))
1672
- ossl_raise(eSSLError, "SSL_set_fd");
1688
+ if (!SSL_set_fd(ssl, TO_SOCKET(rb_io_descriptor(io))))
1689
+ ossl_raise(eSSLError, "SSL_set_fd");
1673
1690
 
1674
1691
  return Qtrue;
1675
1692
  }
@@ -1709,21 +1726,25 @@ no_exception_p(VALUE opts)
1709
1726
  #endif
1710
1727
 
1711
1728
  static void
1712
- io_wait_writable(rb_io_t *fptr)
1729
+ io_wait_writable(VALUE io)
1713
1730
  {
1714
1731
  #ifdef HAVE_RB_IO_MAYBE_WAIT
1715
- rb_io_maybe_wait_writable(errno, fptr->self, RUBY_IO_TIMEOUT_DEFAULT);
1732
+ rb_io_maybe_wait_writable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
1716
1733
  #else
1734
+ rb_io_t *fptr;
1735
+ GetOpenFile(io, fptr);
1717
1736
  rb_io_wait_writable(fptr->fd);
1718
1737
  #endif
1719
1738
  }
1720
1739
 
1721
1740
  static void
1722
- io_wait_readable(rb_io_t *fptr)
1741
+ io_wait_readable(VALUE io)
1723
1742
  {
1724
1743
  #ifdef HAVE_RB_IO_MAYBE_WAIT
1725
- rb_io_maybe_wait_readable(errno, fptr->self, RUBY_IO_TIMEOUT_DEFAULT);
1744
+ rb_io_maybe_wait_readable(errno, io, RUBY_IO_TIMEOUT_DEFAULT);
1726
1745
  #else
1746
+ rb_io_t *fptr;
1747
+ GetOpenFile(io, fptr);
1727
1748
  rb_io_wait_readable(fptr->fd);
1728
1749
  #endif
1729
1750
  }
@@ -1732,75 +1753,74 @@ static VALUE
1732
1753
  ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts)
1733
1754
  {
1734
1755
  SSL *ssl;
1735
- rb_io_t *fptr;
1736
1756
  int ret, ret2;
1737
1757
  VALUE cb_state;
1738
1758
  int nonblock = opts != Qfalse;
1739
- #if defined(SSL_R_CERTIFICATE_VERIFY_FAILED)
1740
- unsigned long err;
1741
- #endif
1742
1759
 
1743
1760
  rb_ivar_set(self, ID_callback_state, Qnil);
1744
1761
 
1745
1762
  GetSSL(self, ssl);
1746
1763
 
1747
- GetOpenFile(rb_attr_get(self, id_i_io), fptr);
1748
- for(;;){
1749
- ret = func(ssl);
1764
+ VALUE io = rb_attr_get(self, id_i_io);
1765
+ for (;;) {
1766
+ ret = func(ssl);
1750
1767
 
1751
- cb_state = rb_attr_get(self, ID_callback_state);
1768
+ cb_state = rb_attr_get(self, ID_callback_state);
1752
1769
  if (!NIL_P(cb_state)) {
1753
- /* must cleanup OpenSSL error stack before re-raising */
1754
- ossl_clear_error();
1755
- rb_jump_tag(NUM2INT(cb_state));
1756
- }
1770
+ /* must cleanup OpenSSL error stack before re-raising */
1771
+ ossl_clear_error();
1772
+ rb_jump_tag(NUM2INT(cb_state));
1773
+ }
1757
1774
 
1758
- if (ret > 0)
1759
- break;
1775
+ if (ret > 0)
1776
+ break;
1760
1777
 
1761
- switch((ret2 = ssl_get_error(ssl, ret))){
1762
- case SSL_ERROR_WANT_WRITE:
1778
+ switch ((ret2 = ssl_get_error(ssl, ret))) {
1779
+ case SSL_ERROR_WANT_WRITE:
1763
1780
  if (no_exception_p(opts)) { return sym_wait_writable; }
1764
1781
  write_would_block(nonblock);
1765
- io_wait_writable(fptr);
1782
+ io_wait_writable(io);
1766
1783
  continue;
1767
- case SSL_ERROR_WANT_READ:
1784
+ case SSL_ERROR_WANT_READ:
1768
1785
  if (no_exception_p(opts)) { return sym_wait_readable; }
1769
1786
  read_would_block(nonblock);
1770
- io_wait_readable(fptr);
1787
+ io_wait_readable(io);
1771
1788
  continue;
1772
- case SSL_ERROR_SYSCALL:
1789
+ case SSL_ERROR_SYSCALL:
1773
1790
  #ifdef __APPLE__
1774
1791
  /* See ossl_ssl_write_internal() */
1775
1792
  if (errno == EPROTOTYPE)
1776
1793
  continue;
1777
1794
  #endif
1778
- if (errno) rb_sys_fail(funcname);
1779
- ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d peeraddr=%"PRIsVALUE" state=%s",
1780
- funcname, ret2, errno, peeraddr_ip_str(self), SSL_state_string_long(ssl));
1781
-
1795
+ if (errno) rb_sys_fail(funcname);
1796
+ /* fallthrough */
1797
+ default: {
1798
+ VALUE error_append = Qnil;
1782
1799
  #if defined(SSL_R_CERTIFICATE_VERIFY_FAILED)
1783
- case SSL_ERROR_SSL:
1784
- err = ERR_peek_last_error();
1785
- if (ERR_GET_LIB(err) == ERR_LIB_SSL &&
1786
- ERR_GET_REASON(err) == SSL_R_CERTIFICATE_VERIFY_FAILED) {
1787
- const char *err_msg = ERR_reason_error_string(err),
1788
- *verify_msg = X509_verify_cert_error_string(SSL_get_verify_result(ssl));
1789
- if (!err_msg)
1790
- err_msg = "(null)";
1791
- if (!verify_msg)
1792
- verify_msg = "(null)";
1793
- ossl_clear_error(); /* let ossl_raise() not append message */
1794
- ossl_raise(eSSLError, "%s returned=%d errno=%d peeraddr=%"PRIsVALUE" state=%s: %s (%s)",
1795
- funcname, ret2, errno, peeraddr_ip_str(self), SSL_state_string_long(ssl),
1796
- err_msg, verify_msg);
1797
- }
1800
+ unsigned long err = ERR_peek_last_error();
1801
+ if (ERR_GET_LIB(err) == ERR_LIB_SSL &&
1802
+ ERR_GET_REASON(err) == SSL_R_CERTIFICATE_VERIFY_FAILED) {
1803
+ const char *err_msg = ERR_reason_error_string(err),
1804
+ *verify_msg = X509_verify_cert_error_string(SSL_get_verify_result(ssl));
1805
+ if (!err_msg)
1806
+ err_msg = "(null)";
1807
+ if (!verify_msg)
1808
+ verify_msg = "(null)";
1809
+ ossl_clear_error(); /* let ossl_raise() not append message */
1810
+ error_append = rb_sprintf(": %s (%s)", err_msg, verify_msg);
1811
+ }
1798
1812
  #endif
1799
- /* fallthrough */
1800
- default:
1801
- ossl_raise(eSSLError, "%s returned=%d errno=%d peeraddr=%"PRIsVALUE" state=%s",
1802
- funcname, ret2, errno, peeraddr_ip_str(self), SSL_state_string_long(ssl));
1803
- }
1813
+ ossl_raise(eSSLError,
1814
+ "%s%s returned=%d errno=%d peeraddr=%"PRIsVALUE" state=%s%"PRIsVALUE,
1815
+ funcname,
1816
+ ret2 == SSL_ERROR_SYSCALL ? " SYSCALL" : "",
1817
+ ret2,
1818
+ errno,
1819
+ peeraddr_ip_str(self),
1820
+ SSL_state_string_long(ssl),
1821
+ error_append);
1822
+ }
1823
+ }
1804
1824
  }
1805
1825
 
1806
1826
  return self;
@@ -1906,8 +1926,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1906
1926
  SSL *ssl;
1907
1927
  int ilen;
1908
1928
  VALUE len, str;
1909
- rb_io_t *fptr;
1910
- VALUE io, opts = Qnil;
1929
+ VALUE opts = Qnil;
1911
1930
 
1912
1931
  if (nonblock) {
1913
1932
  rb_scan_args(argc, argv, "11:", &len, &str, &opts);
@@ -1932,8 +1951,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1932
1951
  if (ilen == 0)
1933
1952
  return str;
1934
1953
 
1935
- io = rb_attr_get(self, id_i_io);
1936
- GetOpenFile(io, fptr);
1954
+ VALUE io = rb_attr_get(self, id_i_io);
1937
1955
 
1938
1956
  rb_str_locktmp(str);
1939
1957
  for (;;) {
@@ -1953,7 +1971,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1953
1971
  if (no_exception_p(opts)) { return sym_wait_writable; }
1954
1972
  write_would_block(nonblock);
1955
1973
  }
1956
- io_wait_writable(fptr);
1974
+ io_wait_writable(io);
1957
1975
  continue;
1958
1976
  case SSL_ERROR_WANT_READ:
1959
1977
  if (nonblock) {
@@ -1961,7 +1979,7 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
1961
1979
  if (no_exception_p(opts)) { return sym_wait_readable; }
1962
1980
  read_would_block(nonblock);
1963
1981
  }
1964
- io_wait_readable(fptr);
1982
+ io_wait_readable(io);
1965
1983
  continue;
1966
1984
  case SSL_ERROR_SYSCALL:
1967
1985
  if (!ERR_peek_error()) {
@@ -2027,14 +2045,14 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
2027
2045
  SSL *ssl;
2028
2046
  rb_io_t *fptr;
2029
2047
  int num, nonblock = opts != Qfalse;
2030
- VALUE tmp, io;
2048
+ VALUE tmp;
2031
2049
 
2032
2050
  GetSSL(self, ssl);
2033
2051
  if (!ssl_started(ssl))
2034
2052
  rb_raise(eSSLError, "SSL session is not started yet");
2035
2053
 
2036
2054
  tmp = rb_str_new_frozen(StringValue(str));
2037
- io = rb_attr_get(self, id_i_io);
2055
+ VALUE io = rb_attr_get(self, id_i_io);
2038
2056
  GetOpenFile(io, fptr);
2039
2057
 
2040
2058
  /* SSL_write(3ssl) manpage states num == 0 is undefined */
@@ -2050,12 +2068,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
2050
2068
  case SSL_ERROR_WANT_WRITE:
2051
2069
  if (no_exception_p(opts)) { return sym_wait_writable; }
2052
2070
  write_would_block(nonblock);
2053
- io_wait_writable(fptr);
2071
+ io_wait_writable(io);
2054
2072
  continue;
2055
2073
  case SSL_ERROR_WANT_READ:
2056
2074
  if (no_exception_p(opts)) { return sym_wait_readable; }
2057
2075
  read_would_block(nonblock);
2058
- io_wait_readable(fptr);
2076
+ io_wait_readable(io);
2059
2077
  continue;
2060
2078
  case SSL_ERROR_SYSCALL:
2061
2079
  #ifdef __APPLE__
@@ -19,7 +19,7 @@ const rb_data_type_t ossl_ssl_session_type = {
19
19
  {
20
20
  0, ossl_ssl_session_free,
21
21
  },
22
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
22
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
23
23
  };
24
24
 
25
25
  static VALUE ossl_ssl_session_alloc(VALUE klass)
@@ -83,7 +83,7 @@ static const rb_data_type_t ossl_ts_req_type = {
83
83
  {
84
84
  0, ossl_ts_req_free,
85
85
  },
86
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
86
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
87
87
  };
88
88
 
89
89
  static void
@@ -97,7 +97,7 @@ static const rb_data_type_t ossl_ts_resp_type = {
97
97
  {
98
98
  0, ossl_ts_resp_free,
99
99
  },
100
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
100
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
101
101
  };
102
102
 
103
103
  static void
@@ -111,7 +111,7 @@ static const rb_data_type_t ossl_ts_token_info_type = {
111
111
  {
112
112
  0, ossl_ts_token_info_free,
113
113
  },
114
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
114
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
115
115
  };
116
116
 
117
117
  static VALUE
@@ -41,7 +41,7 @@ static const rb_data_type_t ossl_x509attr_type = {
41
41
  {
42
42
  0, ossl_x509attr_free,
43
43
  },
44
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
45
45
  };
46
46
 
47
47
  /*
@@ -41,7 +41,7 @@ static const rb_data_type_t ossl_x509_type = {
41
41
  {
42
42
  0, ossl_x509_free,
43
43
  },
44
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
45
45
  };
46
46
 
47
47
  /*
@@ -41,7 +41,7 @@ static const rb_data_type_t ossl_x509crl_type = {
41
41
  {
42
42
  0, ossl_x509crl_free,
43
43
  },
44
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
45
45
  };
46
46
 
47
47
  /*
@@ -55,7 +55,7 @@ static const rb_data_type_t ossl_x509ext_type = {
55
55
  {
56
56
  0, ossl_x509ext_free,
57
57
  },
58
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
58
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
59
59
  };
60
60
 
61
61
  /*
@@ -108,7 +108,7 @@ static const rb_data_type_t ossl_x509extfactory_type = {
108
108
  {
109
109
  0, ossl_x509extfactory_free,
110
110
  },
111
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
111
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
112
112
  };
113
113
 
114
114
  static VALUE
@@ -209,15 +209,16 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
209
209
  int nid;
210
210
  VALUE rconf;
211
211
  CONF *conf;
212
+ const char *oid_cstr = NULL;
212
213
 
213
214
  rb_scan_args(argc, argv, "21", &oid, &value, &critical);
214
- StringValueCStr(oid);
215
215
  StringValue(value);
216
216
  if(NIL_P(critical)) critical = Qfalse;
217
217
 
218
- nid = OBJ_ln2nid(RSTRING_PTR(oid));
219
- if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
220
- if(!nid) ossl_raise(eX509ExtError, "unknown OID `%"PRIsVALUE"'", oid);
218
+ oid_cstr = StringValueCStr(oid);
219
+ nid = OBJ_ln2nid(oid_cstr);
220
+ if (nid != NID_undef)
221
+ oid_cstr = OBJ_nid2sn(nid);
221
222
 
222
223
  valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
223
224
  rb_str_append(valstr, value);
@@ -228,7 +229,12 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
228
229
  rconf = rb_iv_get(self, "@config");
229
230
  conf = NIL_P(rconf) ? NULL : GetConfig(rconf);
230
231
  X509V3_set_nconf(ctx, conf);
231
- ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
232
+
233
+ #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_IS_LIBRESSL
234
+ ext = X509V3_EXT_nconf(conf, ctx, oid_cstr, RSTRING_PTR(valstr));
235
+ #else
236
+ ext = X509V3_EXT_nconf(conf, ctx, (char *)oid_cstr, RSTRING_PTR(valstr));
237
+ #endif
232
238
  X509V3_set_ctx_nodb(ctx);
233
239
  if (!ext){
234
240
  ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr);
@@ -46,7 +46,7 @@ static const rb_data_type_t ossl_x509name_type = {
46
46
  {
47
47
  0, ossl_x509name_free,
48
48
  },
49
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
49
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
50
50
  };
51
51
 
52
52
  /*
@@ -41,7 +41,7 @@ static const rb_data_type_t ossl_x509req_type = {
41
41
  {
42
42
  0, ossl_x509req_free,
43
43
  },
44
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
45
45
  };
46
46
 
47
47
  /*
@@ -41,7 +41,7 @@ static const rb_data_type_t ossl_x509rev_type = {
41
41
  {
42
42
  0, ossl_x509rev_free,
43
43
  },
44
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
45
45
  };
46
46
 
47
47
  /*
@@ -116,6 +116,9 @@ static void
116
116
  ossl_x509store_mark(void *ptr)
117
117
  {
118
118
  X509_STORE *store = ptr;
119
+ // Note: this reference is stored as @verify_callback so we don't need to mark it.
120
+ // However we do need to ensure GC compaction won't move it, hence why
121
+ // we call rb_gc_mark here.
119
122
  rb_gc_mark((VALUE)X509_STORE_get_ex_data(store, store_ex_verify_cb_idx));
120
123
  }
121
124
 
@@ -130,7 +133,7 @@ static const rb_data_type_t ossl_x509store_type = {
130
133
  {
131
134
  ossl_x509store_mark, ossl_x509store_free,
132
135
  },
133
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
136
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
134
137
  };
135
138
 
136
139
  /*
@@ -187,8 +190,9 @@ ossl_x509store_set_vfy_cb(VALUE self, VALUE cb)
187
190
  X509_STORE *store;
188
191
 
189
192
  GetX509Store(self, store);
190
- X509_STORE_set_ex_data(store, store_ex_verify_cb_idx, (void *)cb);
191
193
  rb_iv_set(self, "@verify_callback", cb);
194
+ // We don't need to trigger a write barrier because `rb_iv_set` did it.
195
+ X509_STORE_set_ex_data(store, store_ex_verify_cb_idx, (void *)cb);
192
196
 
193
197
  return cb;
194
198
  }
@@ -507,6 +511,9 @@ static void
507
511
  ossl_x509stctx_mark(void *ptr)
508
512
  {
509
513
  X509_STORE_CTX *ctx = ptr;
514
+ // Note: this reference is stored as @verify_callback so we don't need to mark it.
515
+ // However we do need to ensure GC compaction won't move it, hence why
516
+ // we call rb_gc_mark here.
510
517
  rb_gc_mark((VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx));
511
518
  }
512
519
 
@@ -526,7 +533,7 @@ static const rb_data_type_t ossl_x509stctx_type = {
526
533
  {
527
534
  ossl_x509stctx_mark, ossl_x509stctx_free,
528
535
  },
529
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
536
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
530
537
  };
531
538
 
532
539
  static VALUE
@@ -614,8 +621,8 @@ ossl_x509stctx_verify(VALUE self)
614
621
  X509_STORE_CTX *ctx;
615
622
 
616
623
  GetX509StCtx(self, ctx);
617
- X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx,
618
- (void *)rb_iv_get(self, "@verify_callback"));
624
+ VALUE cb = rb_iv_get(self, "@verify_callback");
625
+ X509_STORE_CTX_set_ex_data(ctx, stctx_ex_verify_cb_idx, (void *)cb);
619
626
 
620
627
  switch (X509_verify_cert(ctx)) {
621
628
  case 1:
@@ -93,9 +93,7 @@ module OpenSSL::Buffering
93
93
  nil
94
94
  else
95
95
  size = @rbuffer.size unless size
96
- ret = @rbuffer[0, size]
97
- @rbuffer[0, size] = ""
98
- ret
96
+ @rbuffer.slice!(0, size)
99
97
  end
100
98
  end
101
99
 
@@ -106,8 +104,7 @@ module OpenSSL::Buffering
106
104
  #
107
105
  # Get the next 8bit byte from `ssl`. Returns `nil` on EOF
108
106
  def getbyte
109
- byte = read(1)
110
- byte && byte.unpack1("C")
107
+ read(1)&.ord
111
108
  end
112
109
 
113
110
  ##
@@ -18,13 +18,9 @@ module OpenSSL
18
18
  # Return the hash value computed with _name_ Digest. _name_ is either the
19
19
  # long name or short name of a supported digest algorithm.
20
20
  #
21
- # === Examples
21
+ # === Example
22
22
  #
23
23
  # OpenSSL::Digest.digest("SHA256", "abc")
24
- #
25
- # which is equivalent to:
26
- #
27
- # OpenSSL::Digest.digest('SHA256', "abc")
28
24
 
29
25
  def self.digest(name, data)
30
26
  super(data, name)
data/lib/openssl/ssl.rb CHANGED
@@ -34,21 +34,21 @@ module OpenSSL
34
34
  }
35
35
 
36
36
  if defined?(OpenSSL::PKey::DH)
37
- DEFAULT_2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_
37
+ DH_ffdhe2048 = OpenSSL::PKey::DH.new <<-_end_of_pem_
38
38
  -----BEGIN DH PARAMETERS-----
39
- MIIBCAKCAQEA7E6kBrYiyvmKAMzQ7i8WvwVk9Y/+f8S7sCTN712KkK3cqd1jhJDY
40
- JbrYeNV3kUIKhPxWHhObHKpD1R84UpL+s2b55+iMd6GmL7OYmNIT/FccKhTcveab
41
- VBmZT86BZKYyf45hUF9FOuUM9xPzuK3Vd8oJQvfYMCd7LPC0taAEljQLR4Edf8E6
42
- YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
43
- 1bNveX5wInh5GDx1FGhKBZ+s1H+aedudCm7sCgRwv8lKWYGiHzObSma8A86KG+MD
44
- 7Lo5JquQ3DlBodj3IDyPrxIv96lvRPFtAwIBAg==
39
+ MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz
40
+ +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a
41
+ 87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7
42
+ YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi
43
+ 7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD
44
+ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
45
45
  -----END DH PARAMETERS-----
46
46
  _end_of_pem_
47
- private_constant :DEFAULT_2048
47
+ private_constant :DH_ffdhe2048
48
48
 
49
49
  DEFAULT_TMP_DH_CALLBACK = lambda { |ctx, is_export, keylen| # :nodoc:
50
50
  warn "using default DH parameters." if $VERBOSE
51
- DEFAULT_2048
51
+ DH_ffdhe2048
52
52
  }
53
53
  end
54
54
 
@@ -494,7 +494,7 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
494
494
  unless ctx.session_id_context
495
495
  # see #6137 - session id may not exceed 32 bytes
496
496
  prng = ::Random.new($0.hash)
497
- session_id = prng.bytes(16).unpack('H*')[0]
497
+ session_id = prng.bytes(16).unpack1('H*')
498
498
  @ctx.session_id_context = session_id
499
499
  end
500
500
  @start_immediately = true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenSSL
4
- VERSION = "3.1.0"
4
+ VERSION = "3.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openssl
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Bosslet
@@ -11,9 +11,10 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-12-23 00:00:00.000000000 Z
14
+ date: 2023-09-21 00:00:00.000000000 Z
15
15
  dependencies: []
16
- description: It wraps the OpenSSL library.
16
+ description: OpenSSL for Ruby provides access to SSL/TLS and general-purpose cryptography
17
+ based on the OpenSSL library.
17
18
  email:
18
19
  - ruby-core@ruby-lang.org
19
20
  executables: []
@@ -66,6 +67,8 @@ files:
66
67
  - ext/openssl/ossl_pkey_dsa.c
67
68
  - ext/openssl/ossl_pkey_ec.c
68
69
  - ext/openssl/ossl_pkey_rsa.c
70
+ - ext/openssl/ossl_provider.c
71
+ - ext/openssl/ossl_provider.h
69
72
  - ext/openssl/ossl_rand.c
70
73
  - ext/openssl/ossl_rand.h
71
74
  - ext/openssl/ossl_ssl.c
@@ -110,15 +113,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
113
  requirements:
111
114
  - - ">="
112
115
  - !ruby/object:Gem::Version
113
- version: 2.6.0
116
+ version: 2.7.0
114
117
  required_rubygems_version: !ruby/object:Gem::Requirement
115
118
  requirements:
116
119
  - - ">="
117
120
  - !ruby/object:Gem::Version
118
121
  version: '0'
119
122
  requirements: []
120
- rubygems_version: 3.4.0.dev
123
+ rubygems_version: 3.4.10
121
124
  signing_key:
122
125
  specification_version: 4
123
- summary: OpenSSL provides SSL, TLS and general purpose cryptography.
126
+ summary: SSL/TLS and general-purpose cryptography for Ruby
124
127
  test_files: []