openssl 3.0.3 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e3734ac5044a3ae69b9fb618a0896867e28cfe1390220d802e9db114b449384
4
- data.tar.gz: '0976489913ce74b9b7e83c013db968687c75d2b61715bdda5d6ced8a7b6cdd6a'
3
+ metadata.gz: 239c530562472710697b8da573b8aa64b477c02f5895907220e83e9f09c88fec
4
+ data.tar.gz: 62f2d04df3f693b995bf29be9d299c9f916f44a82b5bc5df60e9f46a748990d8
5
5
  SHA512:
6
- metadata.gz: df86c47dd43a0d92ddaea6d9edd39cbac1eb963807eeb525c9e4be2a9820f1f5dfac017492082fcac63f93ceb3cb6d1a4e0d0574104bd61004c14b5a1866bd9f
7
- data.tar.gz: 071d295fd05b9be5e941a9698977cdb62a02d6b1f83557243bf250d566db372f42df8338c6c9fb11af349c5df879c1ab7179042b2e5c44664431fa0eae1cd1b9
6
+ metadata.gz: 05f891730a9dea150a2cecedb8decbf7f7dbb500cc825226a635fce8ca195a2dbf036de38dbdb7462cbb18e2e3c8aca337c1e1d9d021a94bbc444312dcf26568
7
+ data.tar.gz: 4cff09ce02fc107422829ca552c97cf912f2b5f129c87e37137b153fd2c09d9a231493af7ce32f391c32828b3ffc64bf905adf6a1e3fad943e78ca81048a4f96
data/CONTRIBUTING.md CHANGED
@@ -17,7 +17,7 @@ When reporting a bug, please make sure you include:
17
17
  * Ruby version (`ruby -v`)
18
18
  * `openssl` gem version (`gem list openssl` and `OpenSSL::VERSION`)
19
19
  * OpenSSL library version (`OpenSSL::OPENSSL_VERSION`)
20
- * A sample file that illustrates the problem or link to the repository or
20
+ * A sample file that illustrates the problem or link to the repository or
21
21
  gem that is associated with the bug.
22
22
 
23
23
  There are a number of unresolved issues and feature requests for openssl that
data/History.md CHANGED
@@ -1,26 +1,37 @@
1
- Version 3.0.3
1
+ Version 3.1.0
2
2
  =============
3
3
 
4
- Bug fixes
5
- ---------
4
+ Ruby/OpenSSL 3.1 will be maintained for the lifetime of Ruby 3.2.
5
+
6
+ Merged bug fixes in 2.2.3 and 3.0.2. Among the new features and changes are:
7
+
8
+ Notable changes
9
+ ---------------
6
10
 
7
- * Fix a performance regression introduced in v2.1.3 on a buffered write to
8
- `SSLSocket`.
9
- [[GitHub #706]](https://github.com/ruby/openssl/pull/706)
10
- * Fix `OpenSSL::PKCS7` to handle PKCS#7 structures without content.
11
- [[GitHub #690]](https://github.com/ruby/openssl/pull/690)
12
- [[GitHub #752]](https://github.com/ruby/openssl/pull/752)
13
- * Fix `OpenSSL::ASN1::ObjectId#==` with OIDs without a known name.
14
- [[GitHub #791]](https://github.com/ruby/openssl/issues/791)
15
- [[GitHub #792]](https://github.com/ruby/openssl/pull/792)
16
- * Fix `OpenSSL::X509::Certificate#crl_uris` to handle CDP with multiple CRL
17
- URIs.
18
- [[GitHub #775]](https://github.com/ruby/openssl/issues/775)
19
- [[GitHub #776]](https://github.com/ruby/openssl/pull/776)
20
- * Fix `OpenSSL::Cipher#update` to always make the output buffer `String`
21
- independent.
22
- [[Bug #20937]](https://bugs.ruby-lang.org/issues/20937)
23
- [[GitHub #824]](https://github.com/ruby/openssl/pull/824)
11
+ * Add `OpenSSL::SSL::SSLContext#ciphersuites=` to allow setting TLS 1.3 cipher
12
+ suites.
13
+ [[GitHub #493]](https://github.com/ruby/openssl/pull/493)
14
+ * Add `OpenSSL::SSL::SSLSocket#export_keying_material` for exporting keying
15
+ material of the session, as defined in RFC 5705.
16
+ [[GitHub #530]](https://github.com/ruby/openssl/pull/530)
17
+ * Add `OpenSSL::SSL::SSLContext#keylog_cb=` for setting the TLS key logging
18
+ callback, which is useful for supporting NSS's SSLKEYLOGFILE debugging output.
19
+ [[GitHub #536]](https://github.com/ruby/openssl/pull/536)
20
+ * Remove the default digest algorithm from `OpenSSL::OCSP::BasicResponse#sign`
21
+ and `OpenSSL::OCSP::Request#sign`. Omitting the 5th parameter of these
22
+ methods used to be equivalent of specifying SHA-1. This default value is now
23
+ removed and we will let the underlying OpenSSL library decide instead.
24
+ [[GitHub #507]](https://github.com/ruby/openssl/pull/507)
25
+ * Add `OpenSSL::BN#mod_sqrt`.
26
+ [[GitHub #553]](https://github.com/ruby/openssl/pull/553)
27
+ * Allow calling `OpenSSL::Cipher#update` with an empty string. This was
28
+ prohibited to workaround an ancient bug in OpenSSL.
29
+ [[GitHub #568]](https://github.com/ruby/openssl/pull/568)
30
+ * Fix build on platforms without socket support, such as WASI. `OpenSSL::SSL`
31
+ will not be defined if OpenSSL is compiled with `OPENSSL_NO_SOCK`.
32
+ [[GitHub #558]](https://github.com/ruby/openssl/pull/558)
33
+ * Improve support for recent LibreSSL versions. This includes HKDF support in
34
+ LibreSSL 3.6 and Ed25519 support in LibreSSL 3.7.
24
35
 
25
36
 
26
37
  Version 3.0.2
@@ -25,8 +25,9 @@ Logging::message "=== OpenSSL for Ruby configurator ===\n"
25
25
  if with_config("debug") or enable_config("debug")
26
26
  $defs.push("-DOSSL_DEBUG")
27
27
  end
28
+ $defs.push("-D""OPENSSL_SUPPRESS_DEPRECATED")
28
29
 
29
- have_func("rb_io_maybe_wait") # Ruby 3.1
30
+ have_func("rb_io_maybe_wait(0, Qnil, Qnil, Qnil)", "ruby/io.h") # Ruby 3.1
30
31
 
31
32
  Logging::message "=== Checking for system dependent stuff... ===\n"
32
33
  have_library("nsl", "t_open")
@@ -120,8 +121,13 @@ if is_libressl && ($mswin || $mingw)
120
121
  end
121
122
 
122
123
  Logging::message "=== Checking for OpenSSL features... ===\n"
124
+ evp_h = "openssl/evp.h".freeze
125
+ x509_h = "openssl/x509.h".freeze
126
+ ts_h = "openssl/ts.h".freeze
127
+ ssl_h = "openssl/ssl.h".freeze
128
+
123
129
  # compile options
124
- have_func("RAND_egd")
130
+ have_func("RAND_egd()", "openssl/rand.h")
125
131
  engines = %w{dynamic 4758cca aep atalla chil
126
132
  cswift nuron sureware ubsec padlock capi gmp gost cryptodev}
127
133
  engines.each { |name|
@@ -132,55 +138,56 @@ engines.each { |name|
132
138
  if !have_struct_member("SSL", "ctx", "openssl/ssl.h") || is_libressl
133
139
  $defs.push("-DHAVE_OPAQUE_OPENSSL")
134
140
  end
135
- have_func("EVP_MD_CTX_new")
136
- have_func("EVP_MD_CTX_free")
137
- have_func("EVP_MD_CTX_pkey_ctx")
138
- have_func("X509_STORE_get_ex_data")
139
- have_func("X509_STORE_set_ex_data")
140
- have_func("X509_STORE_get_ex_new_index")
141
- have_func("X509_CRL_get0_signature")
142
- have_func("X509_REQ_get0_signature")
143
- have_func("X509_REVOKED_get0_serialNumber")
144
- have_func("X509_REVOKED_get0_revocationDate")
145
- have_func("X509_get0_tbs_sigalg")
146
- have_func("X509_STORE_CTX_get0_untrusted")
147
- have_func("X509_STORE_CTX_get0_cert")
148
- have_func("X509_STORE_CTX_get0_chain")
149
- have_func("OCSP_SINGLERESP_get0_id")
150
- have_func("SSL_CTX_get_ciphers")
151
- have_func("X509_up_ref")
152
- have_func("X509_CRL_up_ref")
153
- have_func("X509_STORE_up_ref")
154
- have_func("SSL_SESSION_up_ref")
155
- have_func("EVP_PKEY_up_ref")
156
- have_func("SSL_CTX_set_min_proto_version(NULL, 0)", "openssl/ssl.h")
157
- have_func("SSL_CTX_get_security_level")
158
- have_func("X509_get0_notBefore")
159
- have_func("SSL_SESSION_get_protocol_version")
160
- have_func("TS_STATUS_INFO_get0_status")
161
- have_func("TS_STATUS_INFO_get0_text")
162
- have_func("TS_STATUS_INFO_get0_failure_info")
163
- have_func("TS_VERIFY_CTS_set_certs(NULL, NULL)", "openssl/ts.h")
164
- have_func("TS_VERIFY_CTX_set_store")
165
- have_func("TS_VERIFY_CTX_add_flags")
166
- have_func("TS_RESP_CTX_set_time_cb")
167
- have_func("EVP_PBE_scrypt")
168
- have_func("SSL_CTX_set_post_handshake_auth")
141
+ have_func("EVP_MD_CTX_new()", evp_h)
142
+ have_func("EVP_MD_CTX_free(NULL)", evp_h)
143
+ have_func("EVP_MD_CTX_pkey_ctx(NULL)", evp_h)
144
+ have_func("X509_STORE_get_ex_data(NULL, 0)", x509_h)
145
+ have_func("X509_STORE_set_ex_data(NULL, 0, NULL)", x509_h)
146
+ have_func("X509_STORE_get_ex_new_index(0, NULL, NULL, NULL, NULL)", x509_h)
147
+ have_func("X509_CRL_get0_signature(NULL, NULL, NULL)", x509_h)
148
+ have_func("X509_REQ_get0_signature(NULL, NULL, NULL)", x509_h)
149
+ have_func("X509_REVOKED_get0_serialNumber(NULL)", x509_h)
150
+ have_func("X509_REVOKED_get0_revocationDate(NULL)", x509_h)
151
+ have_func("X509_get0_tbs_sigalg(NULL)", x509_h)
152
+ have_func("X509_STORE_CTX_get0_untrusted(NULL)", x509_h)
153
+ have_func("X509_STORE_CTX_get0_cert(NULL)", x509_h)
154
+ have_func("X509_STORE_CTX_get0_chain(NULL)", x509_h)
155
+ have_func("OCSP_SINGLERESP_get0_id(NULL)", "openssl/ocsp.h")
156
+ have_func("SSL_CTX_get_ciphers(NULL)", ssl_h)
157
+ have_func("X509_up_ref(NULL)", x509_h)
158
+ have_func("X509_CRL_up_ref(NULL)", x509_h)
159
+ have_func("X509_STORE_up_ref(NULL)", x509_h)
160
+ have_func("SSL_SESSION_up_ref(NULL)", ssl_h)
161
+ have_func("EVP_PKEY_up_ref(NULL)", evp_h)
162
+ have_func("SSL_CTX_set_min_proto_version(NULL, 0)", ssl_h)
163
+ have_func("SSL_CTX_get_security_level(NULL)", ssl_h)
164
+ have_func("X509_get0_notBefore(NULL)", x509_h)
165
+ have_func("SSL_SESSION_get_protocol_version(NULL)", ssl_h)
166
+ have_func("TS_STATUS_INFO_get0_status(NULL)", ts_h)
167
+ have_func("TS_STATUS_INFO_get0_text(NULL)", ts_h)
168
+ have_func("TS_STATUS_INFO_get0_failure_info(NULL)", ts_h)
169
+ have_func("TS_VERIFY_CTS_set_certs(NULL, NULL)", ts_h)
170
+ have_func("TS_VERIFY_CTX_set_store(NULL, NULL)", ts_h)
171
+ have_func("TS_VERIFY_CTX_add_flags(NULL, 0)", ts_h)
172
+ have_func("TS_RESP_CTX_set_time_cb(NULL, NULL, NULL)", ts_h)
173
+ have_func("EVP_PBE_scrypt(\"\", 0, (unsigned char *)\"\", 0, 0, 0, 0, 0, NULL, 0)", evp_h)
174
+ have_func("SSL_CTX_set_post_handshake_auth(NULL, 0)", ssl_h)
169
175
 
170
176
  # added in 1.1.1
171
- have_func("EVP_PKEY_check")
172
- have_func("EVP_PKEY_new_raw_private_key")
177
+ have_func("EVP_PKEY_check(NULL)", evp_h)
178
+ have_func("EVP_PKEY_new_raw_private_key(0, NULL, (unsigned char *)\"\", 0)", evp_h)
179
+ have_func("SSL_CTX_set_ciphersuites(NULL, \"\")", ssl_h)
173
180
 
174
181
  # added in 3.0.0
175
- have_func("SSL_set0_tmp_dh_pkey")
176
- have_func("ERR_get_error_all")
177
- have_func("TS_VERIFY_CTX_set_certs(NULL, NULL)", "openssl/ts.h")
178
- have_func("SSL_CTX_load_verify_file")
179
- have_func("BN_check_prime")
180
- have_func("EVP_MD_CTX_get0_md")
181
- have_func("EVP_MD_CTX_get_pkey_ctx")
182
- have_func("EVP_PKEY_eq")
183
- have_func("EVP_PKEY_dup")
182
+ have_func("SSL_set0_tmp_dh_pkey(NULL, NULL)", ssl_h)
183
+ have_func("ERR_get_error_all(NULL, NULL, NULL, NULL, NULL)", "openssl/err.h")
184
+ have_func("TS_VERIFY_CTX_set_certs(NULL, NULL)", ts_h)
185
+ have_func("SSL_CTX_load_verify_file(NULL, \"\")", ssl_h)
186
+ have_func("BN_check_prime(NULL, NULL, NULL)", "openssl/bn.h")
187
+ have_func("EVP_MD_CTX_get0_md(NULL)", evp_h)
188
+ have_func("EVP_MD_CTX_get_pkey_ctx(NULL)", evp_h)
189
+ have_func("EVP_PKEY_eq(NULL, NULL)", evp_h)
190
+ have_func("EVP_PKEY_dup(NULL)", evp_h)
184
191
 
185
192
  Logging::message "=== Checking done. ===\n"
186
193
 
data/ext/openssl/ossl.h CHANGED
@@ -52,6 +52,12 @@
52
52
  (LIBRESSL_VERSION_NUMBER >= ((maj << 28) | (min << 20) | (pat << 12)))
53
53
  #endif
54
54
 
55
+ #if OSSL_OPENSSL_PREREQ(3, 0, 0)
56
+ # define OSSL_3_const const
57
+ #else
58
+ # define OSSL_3_const /* const */
59
+ #endif
60
+
55
61
  #if !defined(OPENSSL_NO_ENGINE) && !OSSL_OPENSSL_PREREQ(3, 0, 0)
56
62
  # define OSSL_USE_ENGINE
57
63
  #endif
@@ -509,7 +509,8 @@ ossl_asn1_get_asn1type(VALUE obj)
509
509
  ASN1_TYPE *ret;
510
510
  VALUE value, rflag;
511
511
  void *ptr;
512
- void (*free_func)();
512
+ typedef void free_func_type(void *);
513
+ free_func_type *free_func;
513
514
  int tag;
514
515
 
515
516
  tag = ossl_asn1_default_tag(obj);
@@ -522,16 +523,16 @@ ossl_asn1_get_asn1type(VALUE obj)
522
523
  case V_ASN1_INTEGER: /* FALLTHROUGH */
523
524
  case V_ASN1_ENUMERATED:
524
525
  ptr = obj_to_asn1int(value);
525
- free_func = ASN1_INTEGER_free;
526
+ free_func = (free_func_type *)ASN1_INTEGER_free;
526
527
  break;
527
528
  case V_ASN1_BIT_STRING:
528
529
  rflag = rb_attr_get(obj, sivUNUSED_BITS);
529
530
  ptr = obj_to_asn1bstr(value, NUM2INT(rflag));
530
- free_func = ASN1_BIT_STRING_free;
531
+ free_func = (free_func_type *)ASN1_BIT_STRING_free;
531
532
  break;
532
533
  case V_ASN1_NULL:
533
534
  ptr = obj_to_asn1null(value);
534
- free_func = ASN1_NULL_free;
535
+ free_func = (free_func_type *)ASN1_NULL_free;
535
536
  break;
536
537
  case V_ASN1_OCTET_STRING: /* FALLTHROUGH */
537
538
  case V_ASN1_UTF8STRING: /* FALLTHROUGH */
@@ -546,24 +547,24 @@ ossl_asn1_get_asn1type(VALUE obj)
546
547
  case V_ASN1_UNIVERSALSTRING: /* FALLTHROUGH */
547
548
  case V_ASN1_BMPSTRING:
548
549
  ptr = obj_to_asn1str(value);
549
- free_func = ASN1_STRING_free;
550
+ free_func = (free_func_type *)ASN1_STRING_free;
550
551
  break;
551
552
  case V_ASN1_OBJECT:
552
553
  ptr = obj_to_asn1obj(value);
553
- free_func = ASN1_OBJECT_free;
554
+ free_func = (free_func_type *)ASN1_OBJECT_free;
554
555
  break;
555
556
  case V_ASN1_UTCTIME:
556
557
  ptr = obj_to_asn1utime(value);
557
- free_func = ASN1_TIME_free;
558
+ free_func = (free_func_type *)ASN1_TIME_free;
558
559
  break;
559
560
  case V_ASN1_GENERALIZEDTIME:
560
561
  ptr = obj_to_asn1gtime(value);
561
- free_func = ASN1_TIME_free;
562
+ free_func = (free_func_type *)ASN1_TIME_free;
562
563
  break;
563
564
  case V_ASN1_SET: /* FALLTHROUGH */
564
565
  case V_ASN1_SEQUENCE:
565
566
  ptr = obj_to_asn1derstr(obj);
566
- free_func = ASN1_STRING_free;
567
+ free_func = (free_func_type *)ASN1_STRING_free;
567
568
  break;
568
569
  default:
569
570
  ossl_raise(eASN1Error, "unsupported ASN.1 type");
@@ -1297,6 +1298,30 @@ ossl_asn1obj_get_ln(VALUE self)
1297
1298
  return ret;
1298
1299
  }
1299
1300
 
1301
+ /*
1302
+ * call-seq:
1303
+ * oid == other_oid => true or false
1304
+ *
1305
+ * Returns +true+ if _other_oid_ is the same as _oid_
1306
+ */
1307
+ static VALUE
1308
+ ossl_asn1obj_eq(VALUE self, VALUE other)
1309
+ {
1310
+ VALUE valSelf, valOther;
1311
+ int nidSelf, nidOther;
1312
+
1313
+ valSelf = ossl_asn1_get_value(self);
1314
+ valOther = ossl_asn1_get_value(other);
1315
+
1316
+ if ((nidSelf = OBJ_txt2nid(StringValueCStr(valSelf))) == NID_undef)
1317
+ ossl_raise(eASN1Error, "OBJ_txt2nid");
1318
+
1319
+ if ((nidOther = OBJ_txt2nid(StringValueCStr(valOther))) == NID_undef)
1320
+ ossl_raise(eASN1Error, "OBJ_txt2nid");
1321
+
1322
+ return nidSelf == nidOther ? Qtrue : Qfalse;
1323
+ }
1324
+
1300
1325
  static VALUE
1301
1326
  asn1obj_get_oid_i(VALUE vobj)
1302
1327
  {
@@ -1341,25 +1366,6 @@ ossl_asn1obj_get_oid(VALUE self)
1341
1366
  return str;
1342
1367
  }
1343
1368
 
1344
- /*
1345
- * call-seq:
1346
- * oid == other_oid => true or false
1347
- *
1348
- * Returns +true+ if _other_oid_ is the same as _oid_.
1349
- */
1350
- static VALUE
1351
- ossl_asn1obj_eq(VALUE self, VALUE other)
1352
- {
1353
- VALUE oid1, oid2;
1354
-
1355
- if (!rb_obj_is_kind_of(other, cASN1ObjectId))
1356
- return Qfalse;
1357
-
1358
- oid1 = ossl_asn1obj_get_oid(self);
1359
- oid2 = ossl_asn1obj_get_oid(other);
1360
- return rb_str_equal(oid1, oid2);
1361
- }
1362
-
1363
1369
  #define OSSL_ASN1_IMPL_FACTORY_METHOD(klass) \
1364
1370
  static VALUE ossl_asn1_##klass(int argc, VALUE *argv, VALUE self)\
1365
1371
  { return rb_funcall3(cASN1##klass, rb_intern("new"), argc, argv); }
@@ -1517,7 +1523,7 @@ Init_ossl_asn1(void)
1517
1523
  *
1518
1524
  * An Array that stores the name of a given tag number. These names are
1519
1525
  * the same as the name of the tag constant that is additionally defined,
1520
- * e.g. +UNIVERSAL_TAG_NAME[2] = "INTEGER"+ and +OpenSSL::ASN1::INTEGER = 2+.
1526
+ * e.g. <tt>UNIVERSAL_TAG_NAME[2] = "INTEGER"</tt> and <tt>OpenSSL::ASN1::INTEGER = 2</tt>.
1521
1527
  *
1522
1528
  * == Example usage
1523
1529
  *
@@ -577,22 +577,33 @@ BIGNUM_2c(gcd)
577
577
  */
578
578
  BIGNUM_2c(mod_sqr)
579
579
 
580
+ #define BIGNUM_2cr(func) \
581
+ static VALUE \
582
+ ossl_bn_##func(VALUE self, VALUE other) \
583
+ { \
584
+ BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
585
+ VALUE obj; \
586
+ GetBN(self, bn1); \
587
+ obj = NewBN(rb_obj_class(self)); \
588
+ if (!(result = BN_##func(NULL, bn1, bn2, ossl_bn_ctx))) \
589
+ ossl_raise(eBNError, NULL); \
590
+ SetBN(obj, result); \
591
+ return obj; \
592
+ }
593
+
580
594
  /*
595
+ * Document-method: OpenSSL::BN#mod_sqrt
596
+ * call-seq:
597
+ * bn.mod_sqrt(bn2) => aBN
598
+ */
599
+ BIGNUM_2cr(mod_sqrt)
600
+
601
+ /*
602
+ * Document-method: OpenSSL::BN#mod_inverse
581
603
  * call-seq:
582
604
  * bn.mod_inverse(bn2) => aBN
583
605
  */
584
- static VALUE
585
- ossl_bn_mod_inverse(VALUE self, VALUE other)
586
- {
587
- BIGNUM *bn1, *bn2 = GetBNPtr(other), *result;
588
- VALUE obj;
589
- GetBN(self, bn1);
590
- obj = NewBN(rb_obj_class(self));
591
- if (!(result = BN_mod_inverse(NULL, bn1, bn2, ossl_bn_ctx)))
592
- ossl_raise(eBNError, "BN_mod_inverse");
593
- SetBN(obj, result);
594
- return obj;
595
- }
606
+ BIGNUM_2cr(mod_inverse)
596
607
 
597
608
  /*
598
609
  * call-seq:
@@ -1234,6 +1245,7 @@ Init_ossl_bn(void)
1234
1245
  rb_define_method(cBN, "mod_sub", ossl_bn_mod_sub, 2);
1235
1246
  rb_define_method(cBN, "mod_mul", ossl_bn_mod_mul, 2);
1236
1247
  rb_define_method(cBN, "mod_sqr", ossl_bn_mod_sqr, 1);
1248
+ rb_define_method(cBN, "mod_sqrt", ossl_bn_mod_sqrt, 1);
1237
1249
  rb_define_method(cBN, "**", ossl_bn_exp, 1);
1238
1250
  rb_define_method(cBN, "mod_exp", ossl_bn_mod_exp, 2);
1239
1251
  rb_define_method(cBN, "gcd", ossl_bn_gcd, 1);
@@ -384,40 +384,24 @@ ossl_cipher_update(int argc, VALUE *argv, VALUE self)
384
384
 
385
385
  StringValue(data);
386
386
  in = (unsigned char *)RSTRING_PTR(data);
387
- if ((in_len = RSTRING_LEN(data)) == 0)
388
- ossl_raise(rb_eArgError, "data must not be empty");
387
+ in_len = RSTRING_LEN(data);
389
388
  GetCipher(self, ctx);
390
-
391
- /*
392
- * As of OpenSSL 3.2, there is no reliable way to determine the required
393
- * output buffer size for arbitrary cipher modes.
394
- * https://github.com/openssl/openssl/issues/22628
395
- *
396
- * in_len+block_size is usually sufficient, but AES key wrap with padding
397
- * ciphers require in_len+15 even though they have a block size of 8 bytes.
398
- *
399
- * Using EVP_MAX_BLOCK_LENGTH (32) as a safe upper bound for ciphers
400
- * currently implemented in OpenSSL, but this can change in the future.
401
- */
402
- if (in_len > LONG_MAX - EVP_MAX_BLOCK_LENGTH) {
389
+ out_len = in_len+EVP_CIPHER_CTX_block_size(ctx);
390
+ if (out_len <= 0) {
403
391
  ossl_raise(rb_eRangeError,
404
392
  "data too big to make output buffer: %ld bytes", in_len);
405
393
  }
406
- out_len = in_len + EVP_MAX_BLOCK_LENGTH;
407
394
 
408
395
  if (NIL_P(str)) {
409
396
  str = rb_str_new(0, out_len);
410
397
  } else {
411
398
  StringValue(str);
412
- if ((long)rb_str_capacity(str) >= out_len)
413
- rb_str_modify(str);
414
- else
415
- rb_str_modify_expand(str, out_len - RSTRING_LEN(str));
399
+ rb_str_resize(str, out_len);
416
400
  }
417
401
 
418
402
  if (!ossl_cipher_update_long(ctx, (unsigned char *)RSTRING_PTR(str), &out_len, in, in_len))
419
403
  ossl_raise(eCipherError, NULL);
420
- assert(out_len <= RSTRING_LEN(str));
404
+ assert(out_len < RSTRING_LEN(str));
421
405
  rb_str_set_len(str, out_len);
422
406
 
423
407
  return str;
@@ -232,7 +232,6 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
232
232
  str = rb_str_new(NULL, out_len);
233
233
  } else {
234
234
  StringValue(str);
235
- rb_str_modify(str);
236
235
  rb_str_resize(str, out_len);
237
236
  }
238
237
 
@@ -3,7 +3,7 @@
3
3
  * Copyright (C) 2007, 2017 Ruby/OpenSSL Project Authors
4
4
  */
5
5
  #include "ossl.h"
6
- #if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER)
6
+ #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_LIBRESSL_PREREQ(3, 6, 0)
7
7
  # include <openssl/kdf.h>
8
8
  #endif
9
9
 
@@ -141,7 +141,7 @@ kdf_scrypt(int argc, VALUE *argv, VALUE self)
141
141
  }
142
142
  #endif
143
143
 
144
- #if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER)
144
+ #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_LIBRESSL_PREREQ(3, 6, 0)
145
145
  /*
146
146
  * call-seq:
147
147
  * KDF.hkdf(ikm, salt:, info:, length:, hash:) -> String
@@ -305,7 +305,7 @@ Init_ossl_kdf(void)
305
305
  #if defined(HAVE_EVP_PBE_SCRYPT)
306
306
  rb_define_module_function(mKDF, "scrypt", kdf_scrypt, -1);
307
307
  #endif
308
- #if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER)
308
+ #if OSSL_OPENSSL_PREREQ(1, 1, 0) || OSSL_LIBRESSL_PREREQ(3, 6, 0)
309
309
  rb_define_module_function(mKDF, "hkdf", kdf_hkdf, -1);
310
310
  #endif
311
311
  }
@@ -382,7 +382,7 @@ ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
382
382
  if (!NIL_P(flags))
383
383
  flg = NUM2INT(flags);
384
384
  if (NIL_P(digest))
385
- md = EVP_sha1();
385
+ md = NULL;
386
386
  else
387
387
  md = ossl_evp_get_digestbyname(digest);
388
388
  if (NIL_P(certs))
@@ -1033,7 +1033,7 @@ ossl_ocspbres_sign(int argc, VALUE *argv, VALUE self)
1033
1033
  if (!NIL_P(flags))
1034
1034
  flg = NUM2INT(flags);
1035
1035
  if (NIL_P(digest))
1036
- md = EVP_sha1();
1036
+ md = NULL;
1037
1037
  else
1038
1038
  md = ossl_evp_get_digestbyname(digest);
1039
1039
  if (NIL_P(certs))
@@ -165,13 +165,7 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
165
165
  out = NULL;
166
166
  pkcs7 = SMIME_read_PKCS7(in, &out);
167
167
  BIO_free(in);
168
- if (!pkcs7)
169
- ossl_raise(ePKCS7Error, "Could not parse the PKCS7");
170
- if (!pkcs7->d.ptr) {
171
- PKCS7_free(pkcs7);
172
- ossl_raise(ePKCS7Error, "No content in PKCS7");
173
- }
174
-
168
+ if(!pkcs7) ossl_raise(ePKCS7Error, NULL);
175
169
  data = out ? ossl_membio2str(out) : Qnil;
176
170
  SetPKCS7(ret, pkcs7);
177
171
  ossl_pkcs7_set_data(ret, data);
@@ -352,10 +346,6 @@ ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
352
346
  BIO_free(in);
353
347
  if (!p7)
354
348
  ossl_raise(rb_eArgError, "Could not parse the PKCS7");
355
- if (!p7->d.ptr) {
356
- PKCS7_free(p7);
357
- ossl_raise(rb_eArgError, "No content in PKCS7");
358
- }
359
349
 
360
350
  RTYPEDDATA_DATA(self) = p7;
361
351
  PKCS7_free(p7_orig);
@@ -92,7 +92,7 @@ void Init_ossl_ec(void);
92
92
  */ \
93
93
  static VALUE ossl_##_keytype##_get_##_name(VALUE self) \
94
94
  { \
95
- _type *obj; \
95
+ const _type *obj; \
96
96
  const BIGNUM *bn; \
97
97
  \
98
98
  Get##_type(self, obj); \
@@ -178,7 +178,7 @@ ossl_dh_initialize_copy(VALUE self, VALUE other)
178
178
  static VALUE
179
179
  ossl_dh_is_public(VALUE self)
180
180
  {
181
- DH *dh;
181
+ OSSL_3_const DH *dh;
182
182
  const BIGNUM *bn;
183
183
 
184
184
  GetDH(self, dh);
@@ -197,14 +197,14 @@ ossl_dh_is_public(VALUE self)
197
197
  static VALUE
198
198
  ossl_dh_is_private(VALUE self)
199
199
  {
200
- DH *dh;
200
+ OSSL_3_const DH *dh;
201
201
  const BIGNUM *bn;
202
202
 
203
203
  GetDH(self, dh);
204
204
  DH_get0_key(dh, NULL, &bn);
205
205
 
206
206
  #if !defined(OPENSSL_NO_ENGINE)
207
- return (bn || DH_get0_engine(dh)) ? Qtrue : Qfalse;
207
+ return (bn || DH_get0_engine((DH *)dh)) ? Qtrue : Qfalse;
208
208
  #else
209
209
  return bn ? Qtrue : Qfalse;
210
210
  #endif
@@ -223,7 +223,7 @@ ossl_dh_is_private(VALUE self)
223
223
  static VALUE
224
224
  ossl_dh_export(VALUE self)
225
225
  {
226
- DH *dh;
226
+ OSSL_3_const DH *dh;
227
227
  BIO *out;
228
228
  VALUE str;
229
229
 
@@ -252,7 +252,7 @@ ossl_dh_export(VALUE self)
252
252
  static VALUE
253
253
  ossl_dh_to_der(VALUE self)
254
254
  {
255
- DH *dh;
255
+ OSSL_3_const DH *dh;
256
256
  unsigned char *p;
257
257
  long len;
258
258
  VALUE str;
@@ -280,7 +280,7 @@ ossl_dh_to_der(VALUE self)
280
280
  static VALUE
281
281
  ossl_dh_get_params(VALUE self)
282
282
  {
283
- DH *dh;
283
+ OSSL_3_const DH *dh;
284
284
  VALUE hash;
285
285
  const BIGNUM *p, *q, *g, *pub_key, *priv_key;
286
286
 
@@ -24,7 +24,7 @@
24
24
  } while (0)
25
25
 
26
26
  static inline int
27
- DSA_HAS_PRIVATE(DSA *dsa)
27
+ DSA_HAS_PRIVATE(OSSL_3_const DSA *dsa)
28
28
  {
29
29
  const BIGNUM *bn;
30
30
  DSA_get0_key(dsa, NULL, &bn);
@@ -32,7 +32,7 @@ DSA_HAS_PRIVATE(DSA *dsa)
32
32
  }
33
33
 
34
34
  static inline int
35
- DSA_PRIVATE(VALUE obj, DSA *dsa)
35
+ DSA_PRIVATE(VALUE obj, OSSL_3_const DSA *dsa)
36
36
  {
37
37
  return DSA_HAS_PRIVATE(dsa) || OSSL_PKEY_IS_PRIVATE(obj);
38
38
  }
@@ -179,7 +179,7 @@ ossl_dsa_initialize_copy(VALUE self, VALUE other)
179
179
  static VALUE
180
180
  ossl_dsa_is_public(VALUE self)
181
181
  {
182
- DSA *dsa;
182
+ const DSA *dsa;
183
183
  const BIGNUM *bn;
184
184
 
185
185
  GetDSA(self, dsa);
@@ -198,7 +198,7 @@ ossl_dsa_is_public(VALUE self)
198
198
  static VALUE
199
199
  ossl_dsa_is_private(VALUE self)
200
200
  {
201
- DSA *dsa;
201
+ OSSL_3_const DSA *dsa;
202
202
 
203
203
  GetDSA(self, dsa);
204
204
 
@@ -225,7 +225,7 @@ ossl_dsa_is_private(VALUE self)
225
225
  static VALUE
226
226
  ossl_dsa_export(int argc, VALUE *argv, VALUE self)
227
227
  {
228
- DSA *dsa;
228
+ OSSL_3_const DSA *dsa;
229
229
 
230
230
  GetDSA(self, dsa);
231
231
  if (DSA_HAS_PRIVATE(dsa))
@@ -244,7 +244,7 @@ ossl_dsa_export(int argc, VALUE *argv, VALUE self)
244
244
  static VALUE
245
245
  ossl_dsa_to_der(VALUE self)
246
246
  {
247
- DSA *dsa;
247
+ OSSL_3_const DSA *dsa;
248
248
 
249
249
  GetDSA(self, dsa);
250
250
  if (DSA_HAS_PRIVATE(dsa))
@@ -265,7 +265,7 @@ ossl_dsa_to_der(VALUE self)
265
265
  static VALUE
266
266
  ossl_dsa_get_params(VALUE self)
267
267
  {
268
- DSA *dsa;
268
+ OSSL_3_const DSA *dsa;
269
269
  VALUE hash;
270
270
  const BIGNUM *p, *q, *g, *pub_key, *priv_key;
271
271