Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes to allow disable of TLSv1.3 #409

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions c/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "bpxnet.h"
#include "fdpoll.h"
#include "tls.h"
#include "zos.h"

int getClientCertificate(gsk_handle soc_handle, char *clientCertificate, unsigned int clientCertificateBufferSize, unsigned int *clientCertificateLength) {

Expand Down Expand Up @@ -54,6 +55,17 @@ int getClientCertificate(gsk_handle soc_handle, char *clientCertificate, unsigne
return rc;
}

static int isTLSV13Enabled(TlsSettings *settings) {
ECVT *ecvt = getECVT();
if ((ecvt->ecvtpseq > 0x1020300) && (settings->maxTls == NULL || !strcmp(settings->maxTls, "TLSv1.3"))) {
return true;
}
/*
Default to false for versions lower than 2.3 and when set to anything other than TLSV1.3.
*/
return false;
}

int tlsInit(TlsEnvironment **outEnv, TlsSettings *settings) {
int rc = 0;
TlsEnvironment *env = (TlsEnvironment *)safeMalloc(sizeof(*env), "Tls Environment");
Expand All @@ -67,7 +79,12 @@ int tlsInit(TlsEnvironment **outEnv, TlsSettings *settings) {
rc = rc || gsk_attribute_set_enum(env->envHandle, GSK_PROTOCOL_TLSV1, GSK_PROTOCOL_TLSV1_OFF);
rc = rc || gsk_attribute_set_enum(env->envHandle, GSK_PROTOCOL_TLSV1_1, GSK_PROTOCOL_TLSV1_1_OFF);
rc = rc || gsk_attribute_set_enum(env->envHandle, GSK_PROTOCOL_TLSV1_2, GSK_PROTOCOL_TLSV1_2_ON);
rc = rc || gsk_attribute_set_enum(env->envHandle, GSK_PROTOCOL_TLSV1_3, GSK_PROTOCOL_TLSV1_3_ON);
/*
We will treat not set as allowing TLSv1.3.
*/
if (isTLSV13Enabled(settings)) {
rc = rc || gsk_attribute_set_enum(env->envHandle, GSK_PROTOCOL_TLSV1_3, GSK_PROTOCOL_TLSV1_3_ON);
}
rc = rc || gsk_attribute_set_enum(env->envHandle, GSK_SERVER_EPHEMERAL_DH_GROUP_SIZE, GSK_SERVER_EPHEMERAL_DH_GROUP_SIZE_2048);

#ifdef DEV_DO_NOT_VALIDATE_CLIENT_CERTIFICATES
Expand Down Expand Up @@ -155,19 +172,24 @@ int tlsSocketInit(TlsEnvironment *env, TlsSocket **outSocket, int fd, bool isSer
if (label) {
rc = rc || gsk_attribute_set_buffer(socket->socketHandle, GSK_KEYRING_LABEL, label, 0);
}
rc = rc || gsk_attribute_set_enum(socket->socketHandle, GSK_SESSION_TYPE, isServer ? GSK_SERVER_SESSION_WITH_CL_AUTH : GSK_CLIENT_SESSION);
if (ciphers) {
rc = rc || gsk_attribute_set_buffer(socket->socketHandle, GSK_V3_CIPHER_SPECS_EXPANDED, ciphers, 0);
rc = rc || gsk_attribute_set_enum(socket->socketHandle, GSK_V3_CIPHERS, GSK_V3_CIPHERS_CHAR4);
}
if (keyshares) {
/*
* TLS 1.3 needs this.
rc = rc || gsk_attribute_set_enum(socket->socketHandle, GSK_SESSION_TYPE, isServer ? GSK_SERVER_SESSION_WITH_CL_AUTH : GSK_CLIENT_SESSION);
/*
To be safe,
*/
if (isTLSV13Enabled(env->settings)) {
if (keyshares) {
/*
Only TLS 1.3 needs this.
*/
if (isServer) {
rc = rc || gsk_attribute_set_buffer(socket->socketHandle, GSK_SERVER_TLS_KEY_SHARES, keyshares, 0);
} else {
rc = rc || gsk_attribute_set_buffer(socket->socketHandle, GSK_CLIENT_TLS_KEY_SHARES, keyshares, 0);
if (isServer) {
rc = rc || gsk_attribute_set_buffer(socket->socketHandle, GSK_SERVER_TLS_KEY_SHARES, keyshares, 0);
} else {
rc = rc || gsk_attribute_set_buffer(socket->socketHandle, GSK_CLIENT_TLS_KEY_SHARES, keyshares, 0);
}
}
}
rc = rc || gsk_attribute_set_callback(socket->socketHandle, GSK_IO_CALLBACK, &ioCallbacks);
Expand Down
8 changes: 7 additions & 1 deletion h/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ typedef struct TlsSettings_tag {
#define TLS_SECP256R1 "0023"
#define TLS_SECP521R1 "0025"
char *keyshares;
/*
TLSv1.3 isn't supported on some zos versions. Having it
enabled causes issues.
TODO: Find out why it isn't negotiating 1.2.
*/
char *maxTls;
} TlsSettings;

typedef struct TlsEnvironment_tag {
Expand Down Expand Up @@ -161,4 +167,4 @@ int getClientCertificate(gsk_handle soc_handle, char *clientCertificate, unsigne
SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zowe Project.
*/
*/
Loading