From: Nikos Mavrogiannopoulos Date: Thu, 12 Sep 2002 10:39:09 +0000 (+0000) Subject: Improved support for zlib. X-Git-Tag: gnutls_0_5_8~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=37083f4bd3bfe4e8f55784a75f84004877f99280;p=thirdparty%2Fgnutls.git Improved support for zlib. --- diff --git a/lib/gnutls.h.in.in b/lib/gnutls.h.in.in index 8399759c6e..eb68105bd0 100644 --- a/lib/gnutls.h.in.in +++ b/lib/gnutls.h.in.in @@ -58,7 +58,10 @@ typedef enum gnutls_digest_algorithm { GNUTLS_DIG_NULL=1, GNUTLS_DIG_MD5, GNUTLS */ #define GNUTLS_MAX_ALGORITHM_NUM 8 -typedef enum gnutls_compression_method { GNUTLS_COMP_NULL=1, GNUTLS_COMP_ZLIB } gnutls_compression_method; +#define GNUTLS_COMP_ZLIB GNUTLS_COMP_ZLIB_DEFAULT +typedef enum gnutls_compression_method { GNUTLS_COMP_NULL=1, + GNUTLS_COMP_ZLIB_DEFAULT, GNUTLS_COMP_ZLIB_CONSTRAINED +} gnutls_compression_method; typedef enum gnutls_connection_end { GNUTLS_SERVER=1, GNUTLS_CLIENT } gnutls_connection_end; diff --git a/lib/gnutls_alert.c b/lib/gnutls_alert.c index 6164fe936d..28a8a839ac 100644 --- a/lib/gnutls_alert.c +++ b/lib/gnutls_alert.c @@ -159,6 +159,7 @@ int ret = GNUTLS_E_UNIMPLEMENTED_FEATURE; ret = gnutls_alert_send( session, GNUTLS_AL_FATAL, GNUTLS_A_BAD_CERTIFICATE); break; case GNUTLS_E_UNKNOWN_CIPHER_SUITE: + case GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM: ret = gnutls_alert_send( session, GNUTLS_AL_FATAL, GNUTLS_A_HANDSHAKE_FAILURE); break; case GNUTLS_E_UNEXPECTED_PACKET: @@ -176,6 +177,9 @@ int ret = GNUTLS_E_UNIMPLEMENTED_FEATURE; case GNUTLS_E_UNEXPECTED_PACKET_LENGTH: ret = gnutls_alert_send( session, GNUTLS_AL_FATAL, GNUTLS_A_RECORD_OVERFLOW); break; + case GNUTLS_E_INTERNAL_ERROR: + ret = gnutls_alert_send( session, GNUTLS_AL_FATAL, GNUTLS_A_INTERNAL_ERROR); + break; } return ret; } diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c index 39dfa93328..7c16192d6d 100644 --- a/lib/gnutls_algorithms.c +++ b/lib/gnutls_algorithms.c @@ -132,20 +132,26 @@ static const gnutls_hash_entry hash_algorithms[] = { /* Compression Section */ -#define GNUTLS_COMPRESSION_ENTRY(name, id) \ - { #name, name, id } +#define GNUTLS_COMPRESSION_ENTRY(name, id, wb, ml, cl) \ + { #name, name, id, wb, ml, cl} struct gnutls_compression_entry { const char *name; gnutls_compression_method id; int num; /* the number reserved in TLS for the specific compression method */ + + /* used in zlib compressor */ + int window_bits; + int mem_level; + int comp_level; }; typedef struct gnutls_compression_entry gnutls_compression_entry; static const gnutls_compression_entry compression_algorithms[] = { - GNUTLS_COMPRESSION_ENTRY(GNUTLS_COMP_NULL, 0), + GNUTLS_COMPRESSION_ENTRY(GNUTLS_COMP_NULL, 0x00, 0, 0, 0), #ifdef HAVE_LIBZ - GNUTLS_COMPRESSION_ENTRY(GNUTLS_COMP_ZLIB, 0xfc), + GNUTLS_COMPRESSION_ENTRY(GNUTLS_COMP_ZLIB_DEFAULT, 0xf1, 15, 8, 3), + GNUTLS_COMPRESSION_ENTRY(GNUTLS_COMP_ZLIB_CONSTRAINED, 0xf2, 12, 5, 3), #endif {0} }; @@ -488,6 +494,30 @@ int _gnutls_compression_get_num(gnutls_compression_method algorithm) return ret; } +int _gnutls_compression_get_wbits(gnutls_compression_method algorithm) +{ + int ret = -1; + /* avoid prefix */ + GNUTLS_COMPRESSION_ALG_LOOP(ret = p->window_bits); + return ret; +} + +int _gnutls_compression_get_mem_level(gnutls_compression_method algorithm) +{ + int ret = -1; + /* avoid prefix */ + GNUTLS_COMPRESSION_ALG_LOOP(ret = p->mem_level); + return ret; +} + +int _gnutls_compression_get_comp_level(gnutls_compression_method algorithm) +{ + int ret = -1; + /* avoid prefix */ + GNUTLS_COMPRESSION_ALG_LOOP(ret = p->comp_level); + return ret; +} + /* returns the gnutls internal ID of the TLS compression * method num */ @@ -1152,7 +1182,7 @@ _gnutls_supported_ciphersuites(gnutls_session session, /* For compression */ -#define MIN_PRIVATE_COMP_ALGO 0x0F +#define MIN_PRIVATE_COMP_ALGO 0xEF /* returns the TLS numbers of the compression methods we support */ #define SUPPORTED_COMPRESSION_METHODS session->internals.compression_method_priority.algorithms diff --git a/lib/gnutls_algorithms.h b/lib/gnutls_algorithms.h index a86607946d..464e91d347 100644 --- a/lib/gnutls_algorithms.h +++ b/lib/gnutls_algorithms.h @@ -72,6 +72,10 @@ int _gnutls_compression_get_num(gnutls_compression_method algorithm); gnutls_compression_method _gnutls_compression_get_id(int num); const char *gnutls_compression_get_name(gnutls_compression_method algorithm); +int _gnutls_compression_get_mem_level(gnutls_compression_method algorithm); +int _gnutls_compression_get_comp_level(gnutls_compression_method algorithm); +int _gnutls_compression_get_wbits(gnutls_compression_method algorithm); + /* Type to KX mappings */ gnutls_kx_algorithm _gnutls_map_kx_get_kx(gnutls_credentials_type type); gnutls_credentials_type _gnutls_map_kx_get_cred(gnutls_kx_algorithm algorithm); diff --git a/lib/gnutls_compress_int.c b/lib/gnutls_compress_int.c index 3d28775ad7..4576717505 100644 --- a/lib/gnutls_compress_int.c +++ b/lib/gnutls_compress_int.c @@ -21,6 +21,7 @@ #include #include +#include #include "gnutls_errors.h" /* The flag d is the direction (compressed, decompress). Non zero is @@ -41,9 +42,17 @@ int err; ret->handle = NULL; #ifdef HAVE_LIBZ - if (method==GNUTLS_COMP_ZLIB) { + switch( method) { + case GNUTLS_COMP_ZLIB_DEFAULT: + case GNUTLS_COMP_ZLIB_CONSTRAINED: { + int window_bits, mem_level; + int comp_level; z_stream* zhandle; + window_bits = _gnutls_compression_get_wbits( method); + mem_level = _gnutls_compression_get_mem_level( method); + comp_level = _gnutls_compression_get_comp_level( method); + ret->handle = gnutls_malloc( sizeof( z_stream)); if (ret->handle==NULL) { gnutls_assert(); @@ -57,16 +66,21 @@ int err; zhandle->opaque = (voidpf)0; if (d) - err = inflateInit(zhandle); - else - err = deflateInit(zhandle, Z_DEFAULT_COMPRESSION); + err = inflateInit2(zhandle, window_bits); + else { + err = deflateInit2(zhandle, + comp_level, Z_DEFLATED, + window_bits, mem_level, Z_DEFAULT_STRATEGY); + } if (err!=Z_OK) { gnutls_assert(); gnutls_free( ret); gnutls_free( ret->handle); return NULL; } - + break; + } + default: } #endif return ret; @@ -78,7 +92,8 @@ int err; if (handle!=NULL) { switch( handle->algo) { #ifdef HAVE_LIBZ - case GNUTLS_COMP_ZLIB: + case GNUTLS_COMP_ZLIB_CONSTRAINED: + case GNUTLS_COMP_ZLIB_DEFAULT: if (d) err = inflateEnd( handle->handle); else @@ -111,7 +126,8 @@ int err; switch( handle->algo) { #ifdef HAVE_LIBZ - case GNUTLS_COMP_ZLIB: + case GNUTLS_COMP_ZLIB_DEFAULT: + case GNUTLS_COMP_ZLIB_CONSTRAINED: size = (plain_size*2)+10; *compressed=NULL; @@ -170,7 +186,8 @@ int cur_pos; switch(handle->algo) { #ifdef HAVE_LIBZ - case GNUTLS_COMP_ZLIB: + case GNUTLS_COMP_ZLIB_DEFAULT: + case GNUTLS_COMP_ZLIB_CONSTRAINED: *plain = NULL; out_size = compressed_size;; plain_size = 0; diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c index aaa053e806..2bf54d9659 100644 --- a/lib/gnutls_handshake.c +++ b/lib/gnutls_handshake.c @@ -640,8 +640,10 @@ int _gnutls_server_select_comp_method(gnutls_session session, opaque * data, for (j = 0; j < datalen; j++) { for (i = 0; i < x; i++) { if (ciphers[i] == data[j]) { - session->internals.compression_method = + gnutls_compression_method method = _gnutls_compression_get_id(ciphers[i]); + + session->internals.compression_method = method; gnutls_free(ciphers); _gnutls_handshake_log("HSK: Selected Compression Method: %s\n", diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 50a5e94564..cc97b8c132 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -160,7 +160,9 @@ typedef enum gnutls_kx_algorithm { GNUTLS_KX_RSA=1, GNUTLS_KX_DHE_DSS, typedef enum gnutls_mac_algorithm { GNUTLS_MAC_NULL=1, GNUTLS_MAC_MD5, GNUTLS_MAC_SHA } gnutls_mac_algorithm; -typedef enum gnutls_compression_method { GNUTLS_COMP_NULL=1, GNUTLS_COMP_ZLIB } gnutls_compression_method; +typedef enum gnutls_compression_method { GNUTLS_COMP_NULL=1, GNUTLS_COMP_ZLIB_DEFAULT, + GNUTLS_COMP_ZLIB_CONSTRAINED +} gnutls_compression_method; typedef enum gnutls_connection_end { GNUTLS_SERVER=1, GNUTLS_CLIENT } gnutls_connection_end;