Skip to content

Commit 289889a

Browse files
committed
merge revision(s) 54258: [Backport ruby#12182]
* ext/openssl/extconf.rb: check SSL_CTX_set_next_proto_select_cb function rather than OPENSSL_NPN_NEGOTIATED macro. it exists even if it is disabled by OpenSSL configuration. [ruby-core:74384] [Bug ruby#12182] * ext/openssl/ossl_ssl.c: update #ifdef(s) as above. * test/openssl/test_ssl.rb: skip NPN tests if NPN is disabled. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@54397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 1a5d585 commit 289889a

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Tue Mar 29 21:10:10 2016 Kazuki Yamaguchi <k@rhe.jp>
2+
3+
* ext/openssl/extconf.rb: check SSL_CTX_set_next_proto_select_cb
4+
function rather than OPENSSL_NPN_NEGOTIATED macro. it exists
5+
even if it is disabled by OpenSSL configuration.
6+
[ruby-core:74384] [Bug #12182]
7+
8+
* ext/openssl/ossl_ssl.c: update #ifdef(s) as above.
9+
10+
* test/openssl/test_ssl.rb: skip NPN tests if NPN is disabled.
11+
112
Tue Mar 29 21:09:02 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
213

314
* lib/uri/http.rb (URI::HTTP#initialize): [DOC] fix example,

ext/openssl/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
have_func("TLSv1_2_method")
113113
have_func("TLSv1_2_server_method")
114114
have_func("TLSv1_2_client_method")
115-
have_macro("OPENSSL_NPN_NEGOTIATED", ['openssl/ssl.h']) && $defs.push("-DHAVE_OPENSSL_NPN_NEGOTIATED")
115+
have_func("SSL_CTX_set_next_proto_select_cb")
116116
unless have_func("SSL_set_tlsext_host_name", ['openssl/ssl.h'])
117117
have_macro("SSL_set_tlsext_host_name", ['openssl/ssl.h']) && $defs.push("-DHAVE_SSL_SET_TLSEXT_HOST_NAME")
118118
end

ext/openssl/ossl_ssl.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ ssl_renegotiation_cb(const SSL *ssl)
572572
(void) rb_funcall(cb, rb_intern("call"), 1, ssl_obj);
573573
}
574574

575-
#ifdef HAVE_OPENSSL_NPN_NEGOTIATED
575+
#if defined(HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB) || defined(HAVE_SSL_CTX_SET_ALPN_SELECT_CB)
576576
static VALUE
577577
ssl_npn_encode_protocol_i(VALUE cur, VALUE encoded)
578578
{
@@ -596,18 +596,6 @@ ssl_npn_encode_protocols(VALUE sslctx, VALUE protocols)
596596
rb_iv_set(sslctx, "@_protocols", encoded);
597597
}
598598

599-
static int
600-
ssl_npn_advertise_cb(SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg)
601-
{
602-
VALUE sslctx_obj = (VALUE) arg;
603-
VALUE protocols = rb_iv_get(sslctx_obj, "@_protocols");
604-
605-
*out = (const unsigned char *) RSTRING_PTR(protocols);
606-
*outlen = RSTRING_LENINT(protocols);
607-
608-
return SSL_TLSEXT_ERR_OK;
609-
}
610-
611599
static int
612600
ssl_npn_select_cb_common(VALUE cb, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen)
613601
{
@@ -640,6 +628,19 @@ ssl_npn_select_cb_common(VALUE cb, const unsigned char **out, unsigned char *out
640628
return SSL_TLSEXT_ERR_OK;
641629
}
642630

631+
#ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
632+
static int
633+
ssl_npn_advertise_cb(SSL *ssl, const unsigned char **out, unsigned int *outlen, void *arg)
634+
{
635+
VALUE sslctx_obj = (VALUE) arg;
636+
VALUE protocols = rb_iv_get(sslctx_obj, "@_protocols");
637+
638+
*out = (const unsigned char *) RSTRING_PTR(protocols);
639+
*outlen = RSTRING_LENINT(protocols);
640+
641+
return SSL_TLSEXT_ERR_OK;
642+
}
643+
643644
static int
644645
ssl_npn_select_cb(SSL *s, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
645646
{
@@ -651,6 +652,7 @@ ssl_npn_select_cb(SSL *s, unsigned char **out, unsigned char *outlen, const unsi
651652
return ssl_npn_select_cb_common(cb, (const unsigned char **)out, outlen, in, inlen);
652653
}
653654
#endif
655+
#endif /* HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB || HAVE_SSL_CTX_SET_ALPN_SELECT_CB */
654656

655657
/* This function may serve as the entry point to support further
656658
* callbacks. */
@@ -783,7 +785,7 @@ ossl_sslctx_setup(VALUE self)
783785
SSL_CTX_set_options(ctx, SSL_OP_ALL);
784786
}
785787

786-
#ifdef HAVE_OPENSSL_NPN_NEGOTIATED
788+
#ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
787789
val = rb_iv_get(self, "@npn_protocols");
788790
if (!NIL_P(val)) {
789791
ssl_npn_encode_protocols(self, val);
@@ -1848,7 +1850,7 @@ ossl_ssl_get_client_ca_list(VALUE self)
18481850
return ossl_x509name_sk2ary(ca);
18491851
}
18501852

1851-
# ifdef HAVE_OPENSSL_NPN_NEGOTIATED
1853+
# ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
18521854
/*
18531855
* call-seq:
18541856
* ssl.npn_protocol => String
@@ -2090,7 +2092,7 @@ Init_ossl_ssl()
20902092
* end
20912093
*/
20922094
rb_attr(cSSLContext, rb_intern("renegotiation_cb"), 1, 1, Qfalse);
2093-
#ifdef HAVE_OPENSSL_NPN_NEGOTIATED
2095+
#ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
20942096
/*
20952097
* An Enumerable of Strings. Each String represents a protocol to be
20962098
* advertised as the list of supported protocols for Next Protocol
@@ -2234,7 +2236,7 @@ Init_ossl_ssl()
22342236
rb_define_method(cSSLSocket, "session=", ossl_ssl_set_session, 1);
22352237
rb_define_method(cSSLSocket, "verify_result", ossl_ssl_get_verify_result, 0);
22362238
rb_define_method(cSSLSocket, "client_ca", ossl_ssl_get_client_ca_list, 0);
2237-
# ifdef HAVE_OPENSSL_NPN_NEGOTIATED
2239+
# ifdef HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB
22382240
rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
22392241
# endif
22402242
#endif

test/openssl/test_ssl.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ def test_renegotiation_cb
761761
}
762762
end
763763

764-
if OpenSSL::OPENSSL_VERSION_NUMBER > 0x10001000
764+
if OpenSSL::OPENSSL_VERSION_NUMBER > 0x10001000 &&
765+
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
766+
# NPN may be disabled by OpenSSL configure option
765767

766768
def test_npn_protocol_selection_ary
767769
advertised = ["http/1.1", "spdy/2"]

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.9"
22
#define RUBY_RELEASE_DATE "2016-03-29"
3-
#define RUBY_PATCHLEVEL 488
3+
#define RUBY_PATCHLEVEL 489
44

55
#define RUBY_RELEASE_YEAR 2016
66
#define RUBY_RELEASE_MONTH 3

0 commit comments

Comments
 (0)