Skip to content

Commit b4543ac

Browse files
authored
Obtain correct cipher in authentication_method(...) (#932)
Motivation: This function returns the first cipher from the preference order, but is not necessarily the actual cipher that was negotiated. Modifications: - Use SSL_get_current_cipher or the struct directly to obtain the used cipher Result: authentication_method(...) returns the correct method.
1 parent 3d4e7e2 commit b4543ac

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

openssl-dynamic/src/main/c/sslcontext.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,19 +1404,24 @@ TCN_IMPLEMENT_CALL(void, SSLContext, setSessionTicketKeys0)(TCN_STDARGS, jlong c
14041404

14051405
static const char* authentication_method(const SSL* ssl) {
14061406
{
1407-
const STACK_OF(SSL_CIPHER) *ciphers = NULL;
1408-
1407+
const SSL_CIPHER *cipher = NULL;
14091408
switch (SSL_version(ssl))
14101409
{
14111410
case SSL2_VERSION:
14121411
return SSL_TXT_RSA;
14131412
default:
1414-
ciphers = SSL_get_ciphers(ssl);
1415-
if (ciphers == NULL || sk_SSL_CIPHER_num(ciphers) <= 0) {
1413+
#if OPENSSL_VERSION_NUMBER > 0x10001000L
1414+
cipher = SSL_get_current_cipher(ssl);
1415+
#else
1416+
// Directly access the struct to get the current cipher as SSL_get_current_cipher(...)
1417+
// does not exists prior openssl 1.1.0
1418+
cipher = ssl->s3->tmp.new_cipher
1419+
#endif
1420+
if (cipher == NULL) {
14161421
// No cipher available so return UNKNOWN.
14171422
return TCN_UNKNOWN_AUTH_METHOD;
14181423
}
1419-
return tcn_SSL_cipher_authentication_method(sk_SSL_CIPHER_value(ciphers, 0));
1424+
return tcn_SSL_cipher_authentication_method(cipher);
14201425
}
14211426
}
14221427
}

0 commit comments

Comments
 (0)