Skip to content

Commit 8a2860f

Browse files
committed
Cleanup
1 parent 6caae14 commit 8a2860f

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

src/libmongoc/src/mongoc/mongoc-stream-tls-secure-channel-private.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ typedef enum {
4646
} ssl_connect_state;
4747

4848
/* enum for underlying type cred field in mongoc_secure_channel_cred */
49-
typedef enum {
50-
schannel_cred,
51-
sch_credentials
52-
} schannel_credential_type;
49+
typedef enum { schannel_cred, sch_credentials } schannel_credential_type;
5350

5451
/* Structs to store Schannel handles */
5552
typedef struct {
@@ -61,7 +58,7 @@ typedef struct {
6158
typedef struct _mongoc_secure_channel_cred {
6259
PCCERT_CONTEXT cert; /* Owning. Optional client cert. */
6360
schannel_credential_type cred_type;
64-
void *cred; /* Underlying type is specified by schannel_credential_type. */
61+
void *cred; /* Underlying type is specified by schannel_credential_type. */
6562
} mongoc_secure_channel_cred;
6663

6764
typedef struct {

src/libmongoc/src/mongoc/mongoc-stream-tls-secure-channel.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ _mongoc_secure_channel_sch_credentials_new(const mongoc_ssl_opt_t *opt, PCCERT_C
856856
{
857857
SCH_CREDENTIALS *cred = bson_malloc0(sizeof(SCH_CREDENTIALS));
858858

859-
// version
860859
cred->dwVersion = SCH_CREDENTIALS_VERSION;
861860

862861
/* SCHANNEL_CRED:
@@ -892,18 +891,11 @@ _mongoc_secure_channel_sch_credentials_new(const mongoc_ssl_opt_t *opt, PCCERT_C
892891
cred->paCred = cert;
893892
}
894893

895-
TLS_PARAMETERS tls_parameters;
896894
cred->cTlsParameters = 1;
897-
cred->pTlsParameters = &tls_parameters;
898-
899-
// Blocked suites
900-
CRYPTO_SETTINGS crypto_settings[1] = { { 0 } };
901-
cred->pTlsParameters->cDisabledCrypto = 0;
902-
cred->pTlsParameters->pDisabledCrypto = crypto_settings;
903-
895+
cred->pTlsParameters = bson_malloc0(sizeof(TLS_PARAMETERS));
904896
cred->pTlsParameters->grbitDisabledProtocols = (DWORD)~enabled_protocols;
905897

906-
return (void*)cred;
898+
return (void *)cred;
907899
}
908900

909901
#endif
@@ -950,24 +942,23 @@ _mongoc_secure_channel_schannel_cred_new(const mongoc_ssl_opt_t *opt, PCCERT_CON
950942

951943
cred->grbitEnabledProtocols = enabled_protocols;
952944

953-
return (void*)cred;
945+
return (void *)cred;
954946
}
955947

956948
mongoc_secure_channel_cred *
957949
mongoc_secure_channel_cred_new(const mongoc_ssl_opt_t *opt)
958950
{
959951
BSON_ASSERT_PARAM(opt);
960952
mongoc_secure_channel_cred *cred = bson_malloc0(sizeof(mongoc_secure_channel_cred));
961-
953+
962954
bool is_server = IsWindowsServer();
963-
DWORD enabled_protocols = SP_PROT_TLS1_1_CLIENT | SP_PROT_TLS1_2_CLIENT;
955+
DWORD enabled_protocols = SP_PROT_TLS1_1_CLIENT | SP_PROT_TLS1_2_CLIENT;
964956

965-
/* TLS 1.3 is supported starting with Windows 11 and Windows Server 2022.
957+
/* TLS 1.3 is supported on Windows 11 (or Windows Server 2022) and newer.
966958
* Schannel will not negotiate TLS 1.3 when SCHANNEL_CRED is used. */
967959
if ((is_server && _mongoc_verify_windows_version(10, 0, 19044, false)) ||
968960
(!is_server && _mongoc_verify_windows_version(10, 0, 22000, false))) {
969961
enabled_protocols |= SP_PROT_TLS1_3_CLIENT;
970-
printf("Enabling TLS 1.3 with Secure Channel \n");
971962
}
972963

973964
if (opt->ca_file) {
@@ -984,7 +975,7 @@ mongoc_secure_channel_cred_new(const mongoc_ssl_opt_t *opt)
984975

985976
#ifdef MONGOC_HAVE_SCH_CREDENTIALS
986977
// SCH_CREDENTIALS is supported in Windows 10 1809 / Server 1809 and later
987-
if (_mongoc_verify_windows_version(10, 0, 17763, false)) {
978+
if (_mongoc_verify_windows_version(10, 0, 17763, false)) {
988979
cred->cred = _mongoc_secure_channel_sch_credentials_new(opt, &cred->cert, enabled_protocols);
989980
cred->cred_type = sch_credentials;
990981
} else {
@@ -1007,6 +998,12 @@ mongoc_secure_channel_cred_deleter(void *cred_void)
1007998
return;
1008999
}
10091000
CertFreeCertificateContext(cred->cert);
1001+
#ifdef MONGOC_HAVE_SCH_CREDENTIALS
1002+
if (cred->cred_type == sch_credentials) {
1003+
SCH_CREDENTIALS *sch_cred = (SCH_CREDENTIALS *)cred->cred;
1004+
bson_free(sch_cred->pTlsParameters);
1005+
}
1006+
#endif
10101007
bson_free(cred->cred);
10111008
bson_free(cred);
10121009
}
@@ -1084,7 +1081,7 @@ mongoc_stream_tls_secure_channel_new_with_creds(mongoc_stream_t *base_stream,
10841081
UNISP_NAME, /* security package */
10851082
SECPKG_CRED_OUTBOUND, /* we are preparing outbound connection */
10861083
NULL, /* Optional logon */
1087-
cred->cred, /* TLS "configuration", "auth data" */
1084+
cred->cred, /* TLS "configuration", "auth data" */
10881085
NULL, /* unused */
10891086
NULL, /* unused */
10901087
&secure_channel->cred_handle->cred_handle, /* credential OUT param */

src/libmongoc/tests/test-mongoc-secure-channel.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ test_secure_channel_shared_creds_stream(void *unused)
9696
mongoc_shared_ptr_reset_null(&cred_ptr);
9797
}
9898

99-
// Test with bad SCHANNEL_CRED to exercise error path:
99+
// Test with bad SCHANNEL CREDENTIALS to exercise error path:
100100
{
101101
mongoc_secure_channel_cred *cred = mongoc_secure_channel_cred_new(&ssl_opt);
102102
mongoc_shared_ptr cred_ptr = mongoc_shared_ptr_create(cred, mongoc_secure_channel_cred_deleter);
103103
#ifdef MONGOC_HAVE_SCH_CREDENTIALS
104-
if (cred->cred_type == sch_credentials) {
105-
SCH_CREDENTIALS *sch_cred = (SCH_CREDENTIALS*)cred->cred;
106-
sch_cred->dwVersion = 0; // Invalid version.
107-
} else {
108-
SCHANNEL_CRED *sch_cred = (SCHANNEL_CRED*)cred->cred;
109-
sch_cred->dwVersion = 0;
110-
}
104+
if (cred->cred_type == sch_credentials) {
105+
SCH_CREDENTIALS *sch_cred = (SCH_CREDENTIALS *)cred->cred;
106+
sch_cred->dwVersion = 0; // Invalid version.
107+
} else {
108+
SCHANNEL_CRED *sch_cred = (SCHANNEL_CRED *)cred->cred;
109+
sch_cred->dwVersion = 0;
110+
}
111111
#else
112-
SCHANNEL_CRED *sch_cred = (SCHANNEL_CRED*)cred->cred;
113-
sch_cred->dwVersion = 0;
112+
SCHANNEL_CRED *sch_cred = (SCHANNEL_CRED *)cred->cred;
113+
sch_cred->dwVersion = 0;
114114
#endif
115115
capture_logs(true);
116116
mongoc_stream_t *stream = connect_with_secure_channel_cred(&ssl_opt, cred_ptr, &error);

0 commit comments

Comments
 (0)