Skip to content

Commit 333bb36

Browse files
committed
ssl: return nil in SSL::SSLSocket#cipher if session is not started
SSL_get_current_cipher() returns NULL if no session is established yet. Return nil in that case rather than an useless value like ["(NONE)", "(NONE)", 0, 32722]. Also, keep the constness of the SSL_CIPHER.
1 parent 3e8ae12 commit 333bb36

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,22 +1997,21 @@ ossl_ssl_get_version(VALUE self)
19971997
}
19981998

19991999
/*
2000-
* call-seq:
2001-
* ssl.cipher => [name, version, bits, alg_bits]
2002-
*
2003-
* The cipher being used for the current connection
2004-
*/
2000+
* call-seq:
2001+
* ssl.cipher -> nil or [name, version, bits, alg_bits]
2002+
*
2003+
* Returns the cipher suite actually used in the current session, or nil if
2004+
* no session has been established.
2005+
*/
20052006
static VALUE
20062007
ossl_ssl_get_cipher(VALUE self)
20072008
{
20082009
SSL *ssl;
2009-
SSL_CIPHER *cipher;
2010+
const SSL_CIPHER *cipher;
20102011

20112012
GetSSL(self, ssl);
2012-
2013-
cipher = (SSL_CIPHER *)SSL_get_current_cipher(ssl);
2014-
2015-
return ossl_ssl_cipher_to_ary(cipher);
2013+
cipher = SSL_get_current_cipher(ssl);
2014+
return cipher ? ossl_ssl_cipher_to_ary(cipher) : Qnil;
20162015
}
20172016

20182017
/*

0 commit comments

Comments
 (0)