andre@998: From 3dc7ab77759878778ae440a31304c736c1ef8cba Mon Sep 17 00:00:00 2001 andre@998: From: Andre Heinecke andre@998: Date: Mon, 1 Sep 2014 19:43:55 +0200 andre@998: Subject: [PATCH 3/3] Add possibility to fore polarssl ciphersuites. andre@998: andre@998: --- andre@998: lib/vtls/polarssl.c | 40 ++++++++++++++++++++++++++++++++++++++-- andre@998: 1 file changed, 38 insertions(+), 2 deletions(-) andre@998: andre@998: diff --git a/lib/vtls/polarssl.c b/lib/vtls/polarssl.c andre@998: index 2c40e36..7e806bf 100644 andre@998: --- a/lib/vtls/polarssl.c andre@998: +++ b/lib/vtls/polarssl.c andre@998: @@ -67,6 +67,8 @@ andre@998: #define THREADING_SUPPORT andre@998: #endif andre@998: andre@998: +#define MAX_CIPHERSUITES 255 andre@998: + andre@998: #if defined(THREADING_SUPPORT) andre@998: static entropy_context entropy; andre@998: andre@998: @@ -129,7 +131,7 @@ static void polarssl_debug(void *context, int level, const char *line) andre@998: andre@998: static Curl_recv polarssl_recv; andre@998: static Curl_send polarssl_send; andre@998: - andre@998: +static int ciphersuites[MAX_CIPHERSUITES + 1]; andre@998: andre@998: static CURLcode andre@998: polarssl_connect_step1(struct connectdata *conn, andre@998: @@ -300,7 +302,41 @@ polarssl_connect_step1(struct connectdata *conn, andre@998: net_recv, &conn->sock[sockindex], andre@998: net_send, &conn->sock[sockindex]); andre@998: andre@998: - ssl_set_ciphersuites(&connssl->ssl, ssl_list_ciphersuites()); andre@998: + if(!data->set.str[STRING_SSL_CIPHER_LIST]) andre@998: + ssl_set_ciphersuites(&connssl->ssl, ssl_list_ciphersuites()); andre@998: + else { andre@998: + /* Convert string input to polarssl cipher id's */ andre@998: + char *tmp, andre@998: + *token, andre@998: + *tok_buf; andre@998: + andre@998: + memset(ciphersuites, 0, MAX_CIPHERSUITES + 1); andre@998: + andre@998: + tmp = strdup (data->set.str[STRING_SSL_CIPHER_LIST]); andre@998: + if(!tmp) andre@998: + return CURLE_OUT_OF_MEMORY; andre@998: + andre@998: + i = 0; andre@998: + for (token = strtok_r(tmp, ":", &tok_buf); andre@998: + token != NULL; andre@998: + token = strtok_r(NULL, ":", &tok_buf)) { andre@998: + andre@998: + ciphersuites[i] = ssl_get_ciphersuite_id(token); andre@998: + if (!ciphersuites[i]) { andre@998: + infof(data, "WARNING: failed to set cipher: %s\n", token); andre@998: + /* Do not increase i as the first 0 is the end andre@998: + of the list so we overwrite it with the next andre@998: + valid cipher. Maybe we should fail? */ andre@998: + continue; andre@998: + } andre@998: + i++; andre@998: + } andre@998: + free(tmp); andre@998: + /* Beware, polarssl does not make a copy of the ciphersuites andre@998: + so the data needs to be valid during the call. */ andre@998: + ssl_set_ciphersuites(&connssl->ssl, ciphersuites); andre@998: + } andre@998: + andre@998: if(!Curl_ssl_getsessionid(conn, &old_session, &old_session_size)) { andre@998: memcpy(&connssl->ssn, old_session, old_session_size); andre@998: infof(data, "PolarSSL re-using session\n"); andre@998: -- andre@998: 1.9.1 andre@998: