Skip to content

Commit 0625e7a

Browse files
gastushmarkt-asf
authored andcommitted
TLS 1.3 requires a call to SSL_CTX_set_ciphersuites to configure the permitted ciphers
1 parent 0a7187e commit 0625e7a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

native/src/sslcontext.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCipherSuite)(TCN_STDARGS, jlong ctx,
518518
tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
519519
TCN_ALLOC_CSTRING(ciphers);
520520
jboolean rv = JNI_TRUE;
521+
int minProtoVer = 0;
522+
int maxProtoVer = 0;
521523
#ifndef HAVE_EXPORT_CIPHERS
522524
size_t len;
523525
char *buf;
@@ -528,6 +530,9 @@ TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCipherSuite)(TCN_STDARGS, jlong ctx,
528530
if (!J2S(ciphers))
529531
return JNI_FALSE;
530532

533+
minProtoVer = SSL_CTX_get_min_proto_version(c->ctx);
534+
maxProtoVer = SSL_CTX_get_max_proto_version(c->ctx);
535+
531536
#ifndef HAVE_EXPORT_CIPHERS
532537
/*
533538
* Always disable NULL and export ciphers,
@@ -540,14 +545,25 @@ TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCipherSuite)(TCN_STDARGS, jlong ctx,
540545
memcpy(buf, SSL_CIPHERS_ALWAYS_DISABLED, strlen(SSL_CIPHERS_ALWAYS_DISABLED));
541546
memcpy(buf + strlen(SSL_CIPHERS_ALWAYS_DISABLED), J2S(ciphers), strlen(J2S(ciphers)));
542547
buf[len - 1] = '\0';
543-
if (!SSL_CTX_set_cipher_list(c->ctx, buf)) {
544548
#else
545-
if (!SSL_CTX_set_cipher_list(c->ctx, J2S(ciphers))) {
549+
buf = (char*)J2S(ciphers);
546550
#endif
547-
char err[TCN_OPENSSL_ERROR_STRING_LENGTH];
548-
ERR_error_string_n(SSL_ERR_get(), err, TCN_OPENSSL_ERROR_STRING_LENGTH);
549-
tcn_Throw(e, "Unable to configure permitted SSL ciphers (%s)", err);
550-
rv = JNI_FALSE;
551+
/* OpenSSL will ignore any unknown cipher, but TLS 1.3 requires a call to SSL_CTX_set_ciphersuites */
552+
if (minProtoVer <= TLS1_2_VERSION) {
553+
if (!SSL_CTX_set_cipher_list(c->ctx, buf)) {
554+
char err[TCN_OPENSSL_ERROR_STRING_LENGTH];
555+
ERR_error_string_n(SSL_ERR_get(), err, TCN_OPENSSL_ERROR_STRING_LENGTH);
556+
tcn_Throw(e, "Unable to configure permitted SSL ciphers (%s)", err);
557+
rv = JNI_FALSE;
558+
}
559+
}
560+
if (maxProtoVer >= TLS1_3_VERSION) {
561+
if (!SSL_CTX_set_ciphersuites(c->ctx, buf)) {
562+
char err[TCN_OPENSSL_ERROR_STRING_LENGTH];
563+
ERR_error_string_n(SSL_ERR_get(), err, TCN_OPENSSL_ERROR_STRING_LENGTH);
564+
tcn_Throw(e, "Unable to configure permitted SSL ciphers (%s)", err);
565+
rv = JNI_FALSE;
566+
}
551567
}
552568
#ifndef HAVE_EXPORT_CIPHERS
553569
free(buf);

0 commit comments

Comments
 (0)