Skip to content

Commit 7451c14

Browse files
committed
openssl: use SSL_is_server()
* ext/openssl/extconf.rb: Check existence of SSL_is_server(). This function was introduced in OpenSSL 1.0.2. [ruby-core:75225] [Feature ruby#12324] * ext/openssl/openssl_missing.h: Implement SSL_is_server() if missing. * ext/openssl/ossl_ssl.c (ssl_info_cb): Use SSL_is_server() to see if the SSL is server. The state machine in OpenSSL was rewritten and SSL_get_state() no longer returns SSL_ST_ACCEPT. (ossl_ssl_cipher_to_ary, ossl_sslctx_session_get_cb): Add some `const`s to suppress warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent c7b583a commit 7451c14

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
Mon Jun 6 01:36:24 2016 Kazuki Yamaguchi <k@rhe.jp>
2+
3+
* ext/openssl/extconf.rb: Check existence of SSL_is_server(). This
4+
function was introduced in OpenSSL 1.0.2.
5+
[ruby-core:75225] [Feature #12324]
6+
7+
* ext/openssl/openssl_missing.h: Implement SSL_is_server() if missing.
8+
9+
* ext/openssl/ossl_ssl.c (ssl_info_cb): Use SSL_is_server() to see if
10+
the SSL is server. The state machine in OpenSSL was rewritten and
11+
SSL_get_state() no longer returns SSL_ST_ACCEPT.
12+
13+
(ossl_ssl_cipher_to_ary, ossl_sslctx_session_get_cb): Add some
14+
`const`s to suppress warning.
15+
116
Mon Jun 6 01:18:10 2016 Kazuki Yamaguchi <k@rhe.jp>
217

318
* ext/openssl/ossl_asn1.c (decode_bool): Do the same thing as

ext/openssl/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
OpenSSL.check_func_or_macro("SSL_CTX_set1_curves_list", "openssl/ssl.h")
115115
OpenSSL.check_func_or_macro("SSL_CTX_set_ecdh_auto", "openssl/ssl.h")
116116
OpenSSL.check_func_or_macro("SSL_get_server_tmp_key", "openssl/ssl.h")
117+
have_func("SSL_is_server")
117118

118119
# added in 1.1.0
119120
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")

ext/openssl/openssl_missing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ int EC_curve_nist2nid(const char *);
6161
# define X509_STORE_CTX_get0_store(x) ((x)->ctx)
6262
#endif
6363

64+
#if !defined(HAVE_SSL_IS_SERVER)
65+
# define SSL_is_server(s) ((s)->server)
66+
#endif
67+
6468
/* added in 1.1.0 */
6569
#if !defined(HAVE_BN_GENCB_NEW)
6670
# define BN_GENCB_new() ((BN_GENCB *)OPENSSL_malloc(sizeof(BN_GENCB)))

ext/openssl/ossl_ssl.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ ossl_call_session_get_cb(VALUE ary)
342342

343343
/* this method is currently only called for servers (in OpenSSL <= 0.9.8e) */
344344
static SSL_SESSION *
345+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
346+
ossl_sslctx_session_get_cb(SSL *ssl, const unsigned char *buf, int len, int *copy)
347+
#else
345348
ossl_sslctx_session_get_cb(SSL *ssl, unsigned char *buf, int len, int *copy)
349+
#endif
346350
{
347351
VALUE ary, ssl_obj, ret_obj;
348352
SSL_SESSION *sess;
@@ -650,15 +654,13 @@ ssl_alpn_select_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, c
650654
#endif
651655
#endif /* HAVE_SSL_CTX_SET_NEXT_PROTO_SELECT_CB || HAVE_SSL_CTX_SET_ALPN_SELECT_CB */
652656

653-
/* This function may serve as the entry point to support further
654-
* callbacks. */
657+
/* This function may serve as the entry point to support further callbacks. */
655658
static void
656659
ssl_info_cb(const SSL *ssl, int where, int val)
657660
{
658-
int state = SSL_state(ssl);
661+
int is_server = SSL_is_server((SSL *)ssl);
659662

660-
if ((where & SSL_CB_HANDSHAKE_START) &&
661-
(state & SSL_ST_ACCEPT)) {
663+
if (is_server && where & SSL_CB_HANDSHAKE_START) {
662664
ssl_renegotiation_cb(ssl);
663665
}
664666
}
@@ -887,7 +889,7 @@ ossl_sslctx_setup(VALUE self)
887889
}
888890

889891
static VALUE
890-
ossl_ssl_cipher_to_ary(SSL_CIPHER *cipher)
892+
ossl_ssl_cipher_to_ary(const SSL_CIPHER *cipher)
891893
{
892894
VALUE ary;
893895
int bits, alg_bits;
@@ -913,7 +915,7 @@ ossl_sslctx_get_ciphers(VALUE self)
913915
{
914916
SSL_CTX *ctx;
915917
STACK_OF(SSL_CIPHER) *ciphers;
916-
SSL_CIPHER *cipher;
918+
const SSL_CIPHER *cipher;
917919
VALUE ary;
918920
int i, num;
919921

0 commit comments

Comments
 (0)