Skip to content

Commit 289f6e0

Browse files
committed
ssl: disable NPN support on LibreSSL
As noted in commit a2ed156 ("test/test_ssl: do not run NPN tests for LibreSSL >= 2.6.1", 2017-08-13), NPN is known not to work properly on LibreSSL. Disable NPN support on LibreSSL, whether OPENSSL_NO_NEXTPROTONEG is defined or not. NPN is less relevant today anyway. Let's also silence test suite when it's not available.
1 parent 935698e commit 289f6e0

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
1515

16+
#if !defined(OPENSSL_NO_NEXTPROTONEG) && !OSSL_IS_LIBRESSL
17+
# define OSSL_USE_NEXTPROTONEG
18+
#endif
19+
1620
#if !defined(TLS1_3_VERSION) && \
1721
OSSL_LIBRESSL_PREREQ(3, 2, 0) && !OSSL_LIBRESSL_PREREQ(3, 4, 0)
1822
# define TLS1_3_VERSION 0x0304
@@ -702,7 +706,7 @@ ssl_npn_select_cb_common(SSL *ssl, VALUE cb, const unsigned char **out,
702706
return SSL_TLSEXT_ERR_OK;
703707
}
704708

705-
#ifndef OPENSSL_NO_NEXTPROTONEG
709+
#ifdef OSSL_USE_NEXTPROTONEG
706710
static int
707711
ssl_npn_advertise_cb(SSL *ssl, const unsigned char **out, unsigned int *outlen,
708712
void *arg)
@@ -899,7 +903,7 @@ ossl_sslctx_setup(VALUE self)
899903
val = rb_attr_get(self, id_i_verify_depth);
900904
if(!NIL_P(val)) SSL_CTX_set_verify_depth(ctx, NUM2INT(val));
901905

902-
#ifndef OPENSSL_NO_NEXTPROTONEG
906+
#ifdef OSSL_USE_NEXTPROTONEG
903907
val = rb_attr_get(self, id_i_npn_protocols);
904908
if (!NIL_P(val)) {
905909
VALUE encoded = ssl_encode_npn_protocols(val);
@@ -2445,7 +2449,7 @@ ossl_ssl_get_client_ca_list(VALUE self)
24452449
return ossl_x509name_sk2ary(ca);
24462450
}
24472451

2448-
# ifndef OPENSSL_NO_NEXTPROTONEG
2452+
# ifdef OSSL_USE_NEXTPROTONEG
24492453
/*
24502454
* call-seq:
24512455
* ssl.npn_protocol => String | nil
@@ -2781,7 +2785,7 @@ Init_ossl_ssl(void)
27812785
* end
27822786
*/
27832787
rb_attr(cSSLContext, rb_intern_const("renegotiation_cb"), 1, 1, Qfalse);
2784-
#ifndef OPENSSL_NO_NEXTPROTONEG
2788+
#ifdef OSSL_USE_NEXTPROTONEG
27852789
/*
27862790
* An Enumerable of Strings. Each String represents a protocol to be
27872791
* advertised as the list of supported protocols for Next Protocol
@@ -2987,7 +2991,7 @@ Init_ossl_ssl(void)
29872991
rb_define_method(cSSLSocket, "tmp_key", ossl_ssl_tmp_key, 0);
29882992
rb_define_method(cSSLSocket, "alpn_protocol", ossl_ssl_alpn_protocol, 0);
29892993
rb_define_method(cSSLSocket, "export_keying_material", ossl_ssl_export_keying_material, -1);
2990-
# ifndef OPENSSL_NO_NEXTPROTONEG
2994+
# ifdef OSSL_USE_NEXTPROTONEG
29912995
rb_define_method(cSSLSocket, "npn_protocol", ossl_ssl_npn_protocol, 0);
29922996
# endif
29932997
#endif

test/openssl/test_ssl.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,9 +1379,7 @@ def test_alpn_protocol_selection_cancel
13791379
end
13801380

13811381
def test_npn_protocol_selection_ary
1382-
pend "NPN is not supported" unless \
1383-
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
1384-
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
1382+
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
13851383

13861384
advertised = ["http/1.1", "spdy/2"]
13871385
ctx_proc = proc { |ctx| ctx.npn_protocols = advertised }
@@ -1399,9 +1397,7 @@ def test_npn_protocol_selection_ary
13991397
end
14001398

14011399
def test_npn_protocol_selection_enum
1402-
pend "NPN is not supported" unless \
1403-
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
1404-
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
1400+
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
14051401

14061402
advertised = Object.new
14071403
def advertised.each
@@ -1423,9 +1419,7 @@ def advertised.each
14231419
end
14241420

14251421
def test_npn_protocol_selection_cancel
1426-
pend "NPN is not supported" unless \
1427-
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
1428-
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
1422+
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
14291423

14301424
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
14311425
start_server_version(:TLSv1_2, ctx_proc) { |port|
@@ -1436,9 +1430,7 @@ def test_npn_protocol_selection_cancel
14361430
end
14371431

14381432
def test_npn_advertised_protocol_too_long
1439-
pend "NPN is not supported" unless \
1440-
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
1441-
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
1433+
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
14421434

14431435
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["a" * 256] }
14441436
start_server_version(:TLSv1_2, ctx_proc) { |port|
@@ -1449,9 +1441,7 @@ def test_npn_advertised_protocol_too_long
14491441
end
14501442

14511443
def test_npn_selected_protocol_too_long
1452-
pend "NPN is not supported" unless \
1453-
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
1454-
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
1444+
return unless OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
14551445

14561446
ctx_proc = Proc.new { |ctx| ctx.npn_protocols = ["http/1.1"] }
14571447
start_server_version(:TLSv1_2, ctx_proc) { |port|

0 commit comments

Comments
 (0)