]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Improved support for zlib.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 12 Sep 2002 10:39:09 +0000 (10:39 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 12 Sep 2002 10:39:09 +0000 (10:39 +0000)
lib/gnutls.h.in.in
lib/gnutls_alert.c
lib/gnutls_algorithms.c
lib/gnutls_algorithms.h
lib/gnutls_compress_int.c
lib/gnutls_handshake.c
lib/gnutls_int.h

index 8399759c6e52c1c4cd6dc7f43c40b61e7db39bb6..eb68105bd024942ce00d9535dcd00cdf8f245d92 100644 (file)
@@ -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;
 
index 6164fe936de4ce2dc758b7aca88138b114d40a81..28a8a839ac995aa906cb0b5d9c856fea5827690d 100644 (file)
@@ -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;
 }
index 39dfa93328c61389267d93f9a6c6556c32d77f0c..7c16192d6d61dbdf786b6a3123cfb140248e1273 100644 (file)
@@ -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
index a86607946d91699c17f916aa7d8567de2a4953e2..464e91d347eb98e4463ba65cc37545efbe5be8c4 100644 (file)
@@ -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);
index 3d28775ad7b9cda368dc4b764dfad15c38f05ac1..4576717505dc78e050bd9e2b0baa90b9a1d4a74d 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <gnutls_int.h>
 #include <gnutls_compress.h>
+#include <gnutls_algorithms.h>
 #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;
index aaa053e8064e50afb53ee8bedef6d7ff822eab5e..2bf54d9659bc8d682a3aa108cd3904443e2e0b4c 100644 (file)
@@ -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",
index 50a5e9456457f395452a15adc219e8dd7154027e..cc97b8c1327f0cc38402c500a5f7ef658f5aec38 100644 (file)
@@ -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;