Commit 9e002cd5 by Edward Thomson

mbedtls: make ciphers_list a static array

Instead of allocating the ciphers_list, make it a static array.  This
prevents us from leaking it or having to manage its memory.
parent 4e62d26f
...@@ -43,12 +43,13 @@ ...@@ -43,12 +43,13 @@
#undef inline #undef inline
mbedtls_ssl_config *git__ssl_conf;
mbedtls_entropy_context *mbedtls_entropy;
#define GIT_SSL_DEFAULT_CIPHERS "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384:TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-DSS-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-DSS-WITH-AES-256-GCM-SHA384:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-CBC-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-128-CBC-SHA:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-128-CBC-SHA256:TLS-DHE-DSS-WITH-AES-256-CBC-SHA256:TLS-DHE-DSS-WITH-AES-128-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-128-GCM-SHA256:TLS-RSA-WITH-AES-256-GCM-SHA384:TLS-RSA-WITH-AES-128-CBC-SHA256:TLS-RSA-WITH-AES-256-CBC-SHA256:TLS-RSA-WITH-AES-128-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA" #define GIT_SSL_DEFAULT_CIPHERS "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256:TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384:TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-DSS-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-DSS-WITH-AES-256-GCM-SHA384:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256:TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384:TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA:TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-CBC-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-128-CBC-SHA:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-DSS-WITH-AES-128-CBC-SHA256:TLS-DHE-DSS-WITH-AES-256-CBC-SHA256:TLS-DHE-DSS-WITH-AES-128-CBC-SHA:TLS-DHE-DSS-WITH-AES-256-CBC-SHA:TLS-RSA-WITH-AES-128-GCM-SHA256:TLS-RSA-WITH-AES-256-GCM-SHA384:TLS-RSA-WITH-AES-128-CBC-SHA256:TLS-RSA-WITH-AES-256-CBC-SHA256:TLS-RSA-WITH-AES-128-CBC-SHA:TLS-RSA-WITH-AES-256-CBC-SHA"
#define GIT_SSL_DEFAULT_CIPHERS_COUNT 30 #define GIT_SSL_DEFAULT_CIPHERS_COUNT 30
mbedtls_ssl_config *git__ssl_conf;
static int ciphers_list[GIT_SSL_DEFAULT_CIPHERS_COUNT];
mbedtls_entropy_context *mbedtls_entropy;
/** /**
* This function aims to clean-up the SSL context which * This function aims to clean-up the SSL context which
* we allocated. * we allocated.
...@@ -80,8 +81,7 @@ int git_mbedtls_stream_global_init(void) ...@@ -80,8 +81,7 @@ int git_mbedtls_stream_global_init(void)
struct stat statbuf; struct stat statbuf;
mbedtls_ctr_drbg_context *ctr_drbg = NULL; mbedtls_ctr_drbg_context *ctr_drbg = NULL;
int *ciphers_list = NULL; size_t ciphers_known = 0;
int ciphers_known = 0;
char *cipher_name = NULL; char *cipher_name = NULL;
char *cipher_string = NULL; char *cipher_string = NULL;
char *cipher_string_tmp = NULL; char *cipher_string_tmp = NULL;
...@@ -109,9 +109,6 @@ int git_mbedtls_stream_global_init(void) ...@@ -109,9 +109,6 @@ int git_mbedtls_stream_global_init(void)
mbedtls_ssl_conf_authmode(git__ssl_conf, MBEDTLS_SSL_VERIFY_OPTIONAL); mbedtls_ssl_conf_authmode(git__ssl_conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
/* set the list of allowed ciphersuites */ /* set the list of allowed ciphersuites */
ciphers_list = git__calloc(GIT_SSL_DEFAULT_CIPHERS_COUNT, sizeof(int));
GITERR_CHECK_ALLOC(ciphers_list);
ciphers_known = 0; ciphers_known = 0;
cipher_string = cipher_string_tmp = git__strdup(GIT_SSL_DEFAULT_CIPHERS); cipher_string = cipher_string_tmp = git__strdup(GIT_SSL_DEFAULT_CIPHERS);
GITERR_CHECK_ALLOC(cipher_string); GITERR_CHECK_ALLOC(cipher_string);
...@@ -120,6 +117,11 @@ int git_mbedtls_stream_global_init(void) ...@@ -120,6 +117,11 @@ int git_mbedtls_stream_global_init(void)
int cipherid = mbedtls_ssl_get_ciphersuite_id(cipher_name); int cipherid = mbedtls_ssl_get_ciphersuite_id(cipher_name);
if (cipherid == 0) continue; if (cipherid == 0) continue;
if (ciphers_known >= ARRAY_SIZE(ciphers_list)) {
giterr_set(GITERR_SSL, "out of cipher list space");
goto cleanup;
}
ciphers_list[ciphers_known++] = cipherid; ciphers_list[ciphers_known++] = cipherid;
} }
git__free(cipher_string); git__free(cipher_string);
...@@ -129,7 +131,6 @@ int git_mbedtls_stream_global_init(void) ...@@ -129,7 +131,6 @@ int git_mbedtls_stream_global_init(void)
goto cleanup; goto cleanup;
} }
mbedtls_ssl_conf_ciphersuites(git__ssl_conf, ciphers_list); mbedtls_ssl_conf_ciphersuites(git__ssl_conf, ciphers_list);
git__free(ciphers_list);
/* Seeding the random number generator */ /* Seeding the random number generator */
mbedtls_entropy = git__malloc(sizeof(mbedtls_entropy_context)); mbedtls_entropy = git__malloc(sizeof(mbedtls_entropy_context));
...@@ -167,7 +168,6 @@ cleanup: ...@@ -167,7 +168,6 @@ cleanup:
mbedtls_ctr_drbg_free(ctr_drbg); mbedtls_ctr_drbg_free(ctr_drbg);
git__free(ctr_drbg); git__free(ctr_drbg);
mbedtls_ssl_config_free(git__ssl_conf); mbedtls_ssl_config_free(git__ssl_conf);
git__free(ciphers_list);
git__free(git__ssl_conf); git__free(git__ssl_conf);
git__ssl_conf = NULL; git__ssl_conf = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment