*/
#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;
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:
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;
}
/* 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}
};
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
*/
/* 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
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);
#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
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();
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;
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
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;
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;
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",
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;