Skip to content

Commit e063431

Browse files
authored
Merge pull request #394 from rhenium/ky/ssl-remove-tmp-ecdh-callback
ssl: remove SSL::SSLContext#tmp_ecdh_callback
2 parents d756d64 + ee037e1 commit e063431

File tree

3 files changed

+3
-94
lines changed

3 files changed

+3
-94
lines changed

ext/openssl/extconf.rb

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def find_openssl_library
160160
have_func("X509_STORE_up_ref")
161161
have_func("SSL_SESSION_up_ref")
162162
have_func("EVP_PKEY_up_ref")
163-
have_func("SSL_CTX_set_tmp_ecdh_callback(NULL, NULL)", "openssl/ssl.h") # removed
164163
have_func("SSL_CTX_set_min_proto_version(NULL, 0)", "openssl/ssl.h")
165164
have_func("SSL_CTX_get_security_level")
166165
have_func("X509_get0_notBefore")

ext/openssl/ossl_ssl.c

+3-69
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ VALUE cSSLSocket;
3232
static VALUE eSSLErrorWaitReadable;
3333
static VALUE eSSLErrorWaitWritable;
3434

35-
static ID id_call, ID_callback_state, id_tmp_dh_callback, id_tmp_ecdh_callback,
35+
static ID id_call, ID_callback_state, id_tmp_dh_callback,
3636
id_npn_protocols_encoded;
3737
static VALUE sym_exception, sym_wait_readable, sym_wait_writable;
3838

3939
static ID id_i_cert_store, id_i_ca_file, id_i_ca_path, id_i_verify_mode,
4040
id_i_verify_depth, id_i_verify_callback, id_i_client_ca,
4141
id_i_renegotiation_cb, id_i_cert, id_i_key, id_i_extra_chain_cert,
42-
id_i_client_cert_cb, id_i_tmp_ecdh_callback, id_i_timeout,
42+
id_i_client_cert_cb, id_i_timeout,
4343
id_i_session_id_context, id_i_session_get_cb, id_i_session_new_cb,
4444
id_i_session_remove_cb, id_i_npn_select_cb, id_i_npn_protocols,
4545
id_i_alpn_select_cb, id_i_alpn_protocols, id_i_servername_cb,
@@ -231,8 +231,7 @@ ossl_client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey)
231231
return 1;
232232
}
233233

234-
#if !defined(OPENSSL_NO_DH) || \
235-
!defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
234+
#if !defined(OPENSSL_NO_DH)
236235
struct tmp_dh_callback_args {
237236
VALUE ssl_obj;
238237
ID id;
@@ -289,35 +288,6 @@ ossl_tmp_dh_callback(SSL *ssl, int is_export, int keylength)
289288
}
290289
#endif /* OPENSSL_NO_DH */
291290

292-
#if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
293-
static EC_KEY *
294-
ossl_tmp_ecdh_callback(SSL *ssl, int is_export, int keylength)
295-
{
296-
VALUE rb_ssl;
297-
EVP_PKEY *pkey;
298-
struct tmp_dh_callback_args args;
299-
int state;
300-
301-
rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
302-
args.ssl_obj = rb_ssl;
303-
args.id = id_tmp_ecdh_callback;
304-
args.is_export = is_export;
305-
args.keylength = keylength;
306-
args.type = EVP_PKEY_EC;
307-
308-
pkey = (EVP_PKEY *)rb_protect((VALUE (*)(VALUE))ossl_call_tmp_dh_callback,
309-
(VALUE)&args, &state);
310-
if (state) {
311-
rb_ivar_set(rb_ssl, ID_callback_state, INT2NUM(state));
312-
return NULL;
313-
}
314-
if (!pkey)
315-
return NULL;
316-
317-
return EVP_PKEY_get0_EC_KEY(pkey);
318-
}
319-
#endif
320-
321291
static VALUE
322292
call_verify_certificate_identity(VALUE ctx_v)
323293
{
@@ -797,26 +767,6 @@ ossl_sslctx_setup(VALUE self)
797767
SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);
798768
#endif
799769

800-
#if !defined(OPENSSL_NO_EC)
801-
/* We added SSLContext#tmp_ecdh_callback= in Ruby 2.3.0,
802-
* but SSL_CTX_set_tmp_ecdh_callback() was removed in OpenSSL 1.1.0. */
803-
if (RTEST(rb_attr_get(self, id_i_tmp_ecdh_callback))) {
804-
# if defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
805-
rb_warn("#tmp_ecdh_callback= is deprecated; use #ecdh_curves= instead");
806-
SSL_CTX_set_tmp_ecdh_callback(ctx, ossl_tmp_ecdh_callback);
807-
# if defined(HAVE_SSL_CTX_SET_ECDH_AUTO)
808-
/* tmp_ecdh_callback and ecdh_auto conflict; OpenSSL ignores
809-
* tmp_ecdh_callback. So disable ecdh_auto. */
810-
if (!SSL_CTX_set_ecdh_auto(ctx, 0))
811-
ossl_raise(eSSLError, "SSL_CTX_set_ecdh_auto");
812-
# endif
813-
# else
814-
ossl_raise(eSSLError, "OpenSSL does not support tmp_ecdh_callback; "
815-
"use #ecdh_curves= instead");
816-
# endif
817-
}
818-
#endif /* OPENSSL_NO_EC */
819-
820770
#ifdef HAVE_SSL_CTX_SET_POST_HANDSHAKE_AUTH
821771
SSL_CTX_set_post_handshake_auth(ctx, 1);
822772
#endif
@@ -2632,20 +2582,6 @@ Init_ossl_ssl(void)
26322582
*/
26332583
rb_attr(cSSLContext, rb_intern("client_cert_cb"), 1, 1, Qfalse);
26342584

2635-
#if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
2636-
/*
2637-
* A callback invoked when ECDH parameters are required.
2638-
*
2639-
* The callback is invoked with the Session for the key exchange, an
2640-
* flag indicating the use of an export cipher and the keylength
2641-
* required.
2642-
*
2643-
* The callback is deprecated. This does not work with recent versions of
2644-
* OpenSSL. Use OpenSSL::SSL::SSLContext#ecdh_curves= instead.
2645-
*/
2646-
rb_attr(cSSLContext, rb_intern("tmp_ecdh_callback"), 1, 1, Qfalse);
2647-
#endif
2648-
26492585
/*
26502586
* Sets the context in which a session can be reused. This allows
26512587
* sessions for multiple applications to be distinguished, for example, by
@@ -2997,7 +2933,6 @@ Init_ossl_ssl(void)
29972933
sym_wait_writable = ID2SYM(rb_intern("wait_writable"));
29982934

29992935
id_tmp_dh_callback = rb_intern("tmp_dh_callback");
3000-
id_tmp_ecdh_callback = rb_intern("tmp_ecdh_callback");
30012936
id_npn_protocols_encoded = rb_intern("npn_protocols_encoded");
30022937

30032938
#define DefIVarID(name) do \
@@ -3015,7 +2950,6 @@ Init_ossl_ssl(void)
30152950
DefIVarID(key);
30162951
DefIVarID(extra_chain_cert);
30172952
DefIVarID(client_cert_cb);
3018-
DefIVarID(tmp_ecdh_callback);
30192953
DefIVarID(timeout);
30202954
DefIVarID(session_id_context);
30212955
DefIVarID(session_get_cb);

test/openssl/test_ssl.rb

-24
Original file line numberDiff line numberDiff line change
@@ -1603,30 +1603,6 @@ def test_connect_works_when_setting_dh_callback_to_nil
16031603
end
16041604
end
16051605

1606-
def test_tmp_ecdh_callback
1607-
pend "EC is disabled" unless defined?(OpenSSL::PKey::EC)
1608-
pend "tmp_ecdh_callback is not supported" unless \
1609-
OpenSSL::SSL::SSLContext.method_defined?(:tmp_ecdh_callback)
1610-
pend "LibreSSL 2.6 has broken SSL_CTX_set_tmp_ecdh_callback()" \
1611-
if libressl?(2, 6, 1)
1612-
1613-
EnvUtil.suppress_warning do # tmp_ecdh_callback is deprecated (2016-05)
1614-
called = false
1615-
ctx_proc = -> ctx {
1616-
ctx.ciphers = "DEFAULT:!kRSA:!kEDH"
1617-
ctx.tmp_ecdh_callback = -> (*args) {
1618-
called = true
1619-
OpenSSL::PKey::EC.new "prime256v1"
1620-
}
1621-
}
1622-
start_server(ctx_proc: ctx_proc) do |port|
1623-
server_connect(port) { |s|
1624-
assert called, "tmp_ecdh_callback should be called"
1625-
}
1626-
end
1627-
end
1628-
end
1629-
16301606
def test_ecdh_curves
16311607
pend "EC is disabled" unless defined?(OpenSSL::PKey::EC)
16321608

0 commit comments

Comments
 (0)