From 0d6e51aae409ee666bc5f415867815ce06ef9a2a Mon Sep 17 00:00:00 2001 From: cameronrich Date: Sun, 12 Jun 2016 10:51:12 +0000 Subject: [PATCH] Removed RC4 from the list of negotiated ciphers as browsers don't support it anymore git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@252 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- crypto/aes.c | 7 +---- ssl/openssl.c | 9 ++---- ssl/tls1.c | 75 ++++---------------------------------------------- ssl/tls1.h | 4 --- ssl/tls1_svr.c | 73 +----------------------------------------------- 5 files changed, 10 insertions(+), 158 deletions(-) diff --git a/crypto/aes.c b/crypto/aes.c index 9b07e27ea..d573f7790 100644 --- a/crypto/aes.c +++ b/crypto/aes.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Cameron Rich + * Copyright (c) 2007-2016, Cameron Rich * * All rights reserved. * @@ -38,9 +38,6 @@ #include "os_port.h" #include "crypto.h" -/* all commented out in skeleton mode */ -#ifndef CONFIG_SSL_SKELETON_MODE - #define rot1(x) (((x) << 24) | ((x) >> 8)) #define rot2(x) (((x) << 16) | ((x) >> 16)) #define rot3(x) (((x) << 8) | ((x) >> 24)) @@ -453,5 +450,3 @@ static void AES_decrypt(const AES_CTX *ctx, uint32_t *data) data[row-1] = tmp[row-1] ^ *(--k); } } - -#endif diff --git a/ssl/openssl.c b/ssl/openssl.c index 6b5c4d8ee..52c3a4967 100644 --- a/ssl/openssl.c +++ b/ssl/openssl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Cameron Rich + * Copyright (c) 2007-2016, Cameron Rich * * All rights reserved. * @@ -49,10 +49,8 @@ static char *key_password = NULL; -void *SSLv23_server_method(void) { return NULL; } void *SSLv3_server_method(void) { return NULL; } void *TLSv1_server_method(void) { return NULL; } -void *SSLv23_client_method(void) { return NULL; } void *SSLv3_client_method(void) { return NULL; } void *TLSv1_client_method(void) { return NULL; } @@ -87,8 +85,7 @@ SSL * SSL_new(SSL_CTX *ssl_ctx) ssl_func_type = OPENSSL_CTX_ATTR->ssl_func_type; #ifdef CONFIG_SSL_ENABLE_CLIENT - if (ssl_func_type == SSLv23_client_method || - ssl_func_type == SSLv3_client_method || + if (ssl_func_type == SSLv3_client_method || ssl_func_type == TLSv1_client_method) { SET_SSL_FLAG(SSL_IS_CLIENT); @@ -231,8 +228,6 @@ void SSL_CTX_set_client_CA_list(SSL_CTX *ssl_ctx, void *file) ssl_obj_load(ssl_ctx, SSL_OBJ_X509_CERT, (const char *)file, NULL); } -void SSLv23_method(void) { } - void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, void *cb) { } void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u) diff --git a/ssl/tls1.c b/ssl/tls1.c index 1a13fc579..608d0e5fe 100644 --- a/ssl/tls1.c +++ b/ssl/tls1.c @@ -59,41 +59,19 @@ static int increase_bm_data_size(SSL *ssl, size_t size); * The server will pick the cipher based on the order that the order that the * ciphers are listed. This order is defined at compile time. */ -#ifdef CONFIG_SSL_SKELETON_MODE -const uint8_t ssl_prot_prefs[NUM_PROTOCOLS] = -{ SSL_RC4_128_SHA }; -#else static void session_free(SSL_SESSION *ssl_sessions[], int sess_index); -const uint8_t ssl_prot_prefs[NUM_PROTOCOLS] = -#ifdef CONFIG_SSL_PROT_LOW /* low security, fast speed */ -{ SSL_AES128_SHA, SSL_AES256_SHA}; +const uint8_t ssl_prot_prefs[NUM_PROTOCOLS] = +#ifdef CONFIG_SSL_PROT_LOW /* same as medium for now */ +{ SSL_AES128_SHA, SSL_AES256_SHA }; #elif CONFIG_SSL_PROT_MEDIUM /* medium security, medium speed */ -{ SSL_AES128_SHA, SSL_AES256_SHA}; +{ SSL_AES128_SHA, SSL_AES256_SHA }; #else /* CONFIG_SSL_PROT_HIGH */ /* high security, low speed */ -{ SSL_AES256_SHA, SSL_AES128_SHA}; +{ SSL_AES256_SHA, SSL_AES128_SHA }; #endif -#endif /* CONFIG_SSL_SKELETON_MODE */ - /** * The cipher map containing all the essentials for each cipher. */ -#ifdef CONFIG_SSL_SKELETON_MODE -static const cipher_info_t cipher_info[NUM_PROTOCOLS] = -{ - { /* RC4-SHA */ - SSL_RC4_128_SHA, /* RC4-SHA */ - 16, /* key size */ - 0, /* iv size */ - 2*(SHA1_SIZE+16), /* key block size */ - 0, /* no padding */ - SHA1_SIZE, /* digest size */ - hmac_sha1, /* hmac algorithm */ - (crypt_func)RC4_crypt, /* encrypt */ - (crypt_func)RC4_crypt /* decrypt */ - }, -}; -#else static const cipher_info_t cipher_info[NUM_PROTOCOLS] = { { /* AES128-SHA */ @@ -117,9 +95,8 @@ static const cipher_info_t cipher_info[NUM_PROTOCOLS] = hmac_sha1, /* hmac algorithm */ (crypt_func)AES_cbc_encrypt, /* encrypt */ (crypt_func)AES_cbc_decrypt /* decrypt */ - } + }, }; -#endif static void prf(const uint8_t *sec, int sec_len, uint8_t *seed, int seed_len, uint8_t *out, int olen); @@ -908,7 +885,6 @@ static void *crypt_new(SSL *ssl, uint8_t *key, uint8_t *iv, int is_decrypt, void { switch (ssl->cipher) { -#ifndef CONFIG_SSL_SKELETON_MODE case SSL_AES128_SHA: { AES_CTX *aes_ctx; @@ -943,20 +919,6 @@ static void *crypt_new(SSL *ssl, uint8_t *key, uint8_t *iv, int is_decrypt, void return (void *)aes_ctx; } - - case SSL_RC4_128_MD5: -#endif - case SSL_RC4_128_SHA: - { - RC4_CTX* rc4_ctx; - if (cached) - rc4_ctx = (RC4_CTX*) cached; - else - rc4_ctx = (RC4_CTX*) malloc(sizeof(RC4_CTX)); - - RC4_setup(rc4_ctx, key, 16); - return (void *)rc4_ctx; - } } return NULL; /* its all gone wrong */ @@ -1177,7 +1139,6 @@ static int set_key_block(SSL *ssl, int is_write) memcpy(server_key, q, ciph_info->key_size); q += ciph_info->key_size; -#ifndef CONFIG_SSL_SKELETON_MODE if (ciph_info->iv_size) /* RC4 has no IV, AES does */ { memcpy(client_iv, q, ciph_info->iv_size); @@ -1185,7 +1146,6 @@ static int set_key_block(SSL *ssl, int is_write) memcpy(server_iv, q, ciph_info->iv_size); q += ciph_info->iv_size; } -#endif // free(is_write ? ssl->encrypt_ctx : ssl->decrypt_ctx); @@ -1261,31 +1221,8 @@ int basic_read(SSL *ssl, uint8_t **in_data) /* check for sslv2 "client hello" */ if (buf[0] & 0x80 && buf[2] == 1) { -#ifdef CONFIG_SSL_ENABLE_V23_HANDSHAKE - uint8_t version = (buf[3] << 4) + buf[4]; - DISPLAY_BYTES(ssl, "ssl2 record", buf, 5); - - /* should be v3.1 (TLSv1) or better */ - ssl->version = ssl->client_version = version; - - if (version > SSL_PROTOCOL_VERSION_MAX) - { - /* use client's version */ - ssl->version = SSL_PROTOCOL_VERSION_MAX; - } - else if (version < SSL_PROTOCOL_MIN_VERSION) - { - ret = SSL_ERROR_INVALID_VERSION; - ssl_display_error(ret); - return ret; - } - - add_packet(ssl, &buf[2], 3); - ret = process_sslv23_client_hello(ssl); -#else printf("Error: no SSLv23 handshaking allowed\n"); TTY_FLUSH(); ret = SSL_ERROR_NOT_SUPPORTED; -#endif goto error; /* not an error - just get out of here */ } diff --git a/ssl/tls1.h b/ssl/tls1.h index abbc93393..e0a008c1b 100644 --- a/ssl/tls1.h +++ b/ssl/tls1.h @@ -79,11 +79,7 @@ extern "C" { #define RT_EXTRA 1024 #define BM_RECORD_OFFSET 5 -#ifdef CONFIG_SSL_SKELETON_MODE -#define NUM_PROTOCOLS 1 -#else #define NUM_PROTOCOLS 2 -#endif #define PARANOIA_CHECK(A, B) if (A < B) { \ ret = SSL_ERROR_INVALID_HANDSHAKE; goto error; } diff --git a/ssl/tls1_svr.c b/ssl/tls1_svr.c index b4b0f648d..9c0cec444 100644 --- a/ssl/tls1_svr.c +++ b/ssl/tls1_svr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Cameron Rich + * Copyright (c) 2007-2016, Cameron Rich * * All rights reserved. * @@ -178,77 +178,6 @@ error: return ret; } -#ifdef CONFIG_SSL_ENABLE_V23_HANDSHAKE -/* - * Some browsers use a hybrid SSLv2 "client hello" - */ -int process_sslv23_client_hello(SSL *ssl) -{ - uint8_t *buf = ssl->bm_data; - int bytes_needed = ((buf[0] & 0x7f) << 8) + buf[1]; - int ret = SSL_OK; - - /* we have already read 3 extra bytes so far */ - int read_len = SOCKET_READ(ssl->client_fd, buf, bytes_needed-3); - int cs_len = buf[1]; - int id_len = buf[3]; - int ch_len = buf[5]; - int i, j, offset = 8; /* start at first cipher */ - int random_offset = 0; - - DISPLAY_BYTES(ssl, "received %d bytes", buf, read_len, read_len); - - /* connection has gone, so die */ - if (read_len < 0) - { - return SSL_ERROR_CONN_LOST; - } - - add_packet(ssl, buf, read_len); - - /* now work out what cipher suite we are going to use */ - for (j = 0; j < NUM_PROTOCOLS; j++) - { - for (i = 0; i < cs_len; i += 3) - { - if (ssl_prot_prefs[j] == buf[offset+i]) - { - ssl->cipher = ssl_prot_prefs[j]; - goto server_hello; - } - } - } - - /* ouch! protocol is not supported */ - ret = SSL_ERROR_NO_CIPHER; - goto error; - -server_hello: - /* get the session id */ - offset += cs_len - 2; /* we've gone 2 bytes past the end */ -#ifndef CONFIG_SSL_SKELETON_MODE - ssl->session = ssl_session_update(ssl->ssl_ctx->num_sessions, - ssl->ssl_ctx->ssl_sessions, ssl, id_len ? &buf[offset] : NULL); -#endif - - /* get the client random data */ - offset += id_len; - - /* random can be anywhere between 16 and 32 bytes long - so it is padded - * with 0's to the left */ - if (ch_len == 0x10) - { - random_offset += 0x10; - } - - memcpy(&ssl->dc->client_random[random_offset], &buf[offset], ch_len); - ret = send_server_hello_sequence(ssl); - -error: - return ret; -} -#endif - /* * Send the entire server hello sequence */