diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-03-17 20:53:18 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-03-17 20:53:18 +0000 |
commit | 8d910aec3e62bd6d14262de1fde5107dad8314be (patch) | |
tree | 1c27e1e040da33d1257c99dc9113599bea8071fe | |
parent | 4774c696589d75ad94cc3f85c05233f01dfc5443 (diff) | |
download | gnutls-8d910aec3e62bd6d14262de1fde5107dad8314be.tar.gz |
several bugfixes and cleanups
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | lib/auth_anon.c | 9 | ||||
-rw-r--r-- | lib/auth_dhe_dss.c | 4 | ||||
-rw-r--r-- | lib/debug.c | 42 | ||||
-rw-r--r-- | lib/gnutls_buffers.c | 20 | ||||
-rw-r--r-- | lib/gnutls_handshake.c | 10 | ||||
-rw-r--r-- | lib/gnutls_int.h | 5 | ||||
-rw-r--r-- | lib/gnutls_kx.c | 2 | ||||
-rw-r--r-- | src/serv.c | 3 |
9 files changed, 69 insertions, 28 deletions
@@ -1,5 +1,7 @@ Version 0.0.8 (28/01/2001) - GNUTLS is a gnu library +- Added some support for TLS extensions. +- Added some support for SRP Version 0.0.7 (11/01/2001) - Added server side session resuming (using gdbm) diff --git a/lib/auth_anon.c b/lib/auth_anon.c index 73b69426e4..5eb716169d 100644 --- a/lib/auth_anon.c +++ b/lib/auth_anon.c @@ -53,7 +53,6 @@ int gen_anon_server_kx( GNUTLS_KEY key, opaque** data) { uint8 *data_p; uint8 *data_g; uint8 *data_X; - int ret = 0; X = gnutls_calc_dh_secret(&x); key->dh_secret = x; @@ -92,16 +91,13 @@ int gen_anon_server_kx( GNUTLS_KEY key, opaque** data) { #else memmove(data_X, &_n_X, 2); #endif - ret = n_p+n_g+n_X+6; - - return ret; + return n_p+n_g+n_X+6; } int gen_anon_client_kx( GNUTLS_KEY key, opaque** data) { GNUTLS_MPI x, X; size_t n_X; uint16 _n_X; -int data_size; X = _gnutls_calc_dh_secret(&x, key->client_g, key->client_p); @@ -120,7 +116,6 @@ int data_size; #else memmove(&(*data)[0], &_n_X, 2); #endif - data_size = _n_X+2; /* calculate the key after calculating the message */ key->KEY = _gnutls_calc_dh_key(key->client_Y, x, key->client_p); @@ -133,7 +128,7 @@ int data_size; key->client_p = NULL; key->client_g = NULL; - return data_size; + return n_X+2; } int proc_anon_server_kx( GNUTLS_KEY key, opaque* data, int data_size) { diff --git a/lib/auth_dhe_dss.c b/lib/auth_dhe_dss.c index 5e0b156878..2b47ee44fc 100644 --- a/lib/auth_dhe_dss.c +++ b/lib/auth_dhe_dss.c @@ -103,7 +103,6 @@ int gen_dhe_dss_client_kx( GNUTLS_KEY key, opaque** data) { GNUTLS_MPI x, X; size_t n_X; uint16 _n_X; -int data_size; X = _gnutls_calc_dh_secret(&x, key->client_g, key->client_p); @@ -122,7 +121,6 @@ int data_size; #else memmove(&(*data)[0], &_n_X, 2); #endif - data_size = _n_X+2; /* calculate the key after calculating the message */ key->KEY = _gnutls_calc_dh_key(key->client_Y, x, key->client_p); @@ -135,7 +133,7 @@ int data_size; key->client_p = NULL; key->client_g = NULL; - return data_size; + return n_X+2; } int proc_dhe_dss_server_kx( GNUTLS_KEY key, opaque* data, int data_size) { diff --git a/lib/debug.c b/lib/debug.c index 7cff3d8e24..c5b0e1674a 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -225,4 +225,46 @@ static char str[512]; return str; } + +char* _gnutls_handshake2str( int handshake) { +static char str[512]; + + switch(handshake) { + case GNUTLS_HELLO_REQUEST: + strcpy(str, "HELLO REQUEST"); + break; + case GNUTLS_CLIENT_HELLO: + strcpy(str, "CLIENT HELLO"); + break; + case GNUTLS_SERVER_HELLO: + strcpy(str, "SERVER HELLO"); + break; + case GNUTLS_CERTIFICATE: + strcpy(str, "CERTIFICATE"); + break; + case GNUTLS_SERVER_KEY_EXCHANGE: + strcpy(str, "SERVER KEY EXCHANGE"); + break; + case GNUTLS_CERTIFICATE_REQUEST: + strcpy(str, "CERTIFICATE REQUEST"); + break; + case GNUTLS_SERVER_HELLO_DONE: + strcpy(str, "SERVER HELLO DONE"); + break; + case GNUTLS_CERTIFICATE_VERIFY: + strcpy(str, "CERTIFICATE VERIFY"); + break; + case GNUTLS_CLIENT_KEY_EXCHANGE: + strcpy(str, "CLIENT KEY EXCHANGE"); + break; + case GNUTLS_FINISHED: + strcpy(str, "FINISHED"); + break; + default: + strcpy(str, "Unknown Handshake"); + + } + return str; + +} #endif diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c index f3608de60d..71b966e5a1 100644 --- a/lib/gnutls_buffers.c +++ b/lib/gnutls_buffers.c @@ -26,11 +26,12 @@ int gnutls_insertDataBuffer(ContentType type, GNUTLS_STATE state, char *data, in { int old_buffer; + if (length==0) return 0; if (type == GNUTLS_APPLICATION_DATA) { old_buffer = state->gnutls_internals.bufferSize; state->gnutls_internals.bufferSize += length; -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Inserted %d bytes of Data(%d) into buffer\n", length, type); #endif state->gnutls_internals.buffer = @@ -42,7 +43,7 @@ int gnutls_insertDataBuffer(ContentType type, GNUTLS_STATE state, char *data, in old_buffer = state->gnutls_internals.bufferSize_handshake; state->gnutls_internals.bufferSize_handshake += length; -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Inserted %d bytes of Data(%d) into buffer\n", length, type); #endif state->gnutls_internals.buffer_handshake = @@ -75,7 +76,7 @@ int gnutls_getDataFromBuffer(ContentType type, GNUTLS_STATE state, char *data, i if (length > state->gnutls_internals.bufferSize) { length = state->gnutls_internals.bufferSize; } -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Read %d bytes of Data(%d) from buffer\n", length, type); #endif state->gnutls_internals.bufferSize -= length; @@ -93,7 +94,7 @@ int gnutls_getDataFromBuffer(ContentType type, GNUTLS_STATE state, char *data, i if (length > state->gnutls_internals.bufferSize_handshake) { length = state->gnutls_internals.bufferSize_handshake; } -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Read %d bytes of Data(%d) from buffer\n", length, type); #endif state->gnutls_internals.bufferSize_handshake -= length; @@ -234,11 +235,12 @@ ssize_t _gnutls_Recv_int(int fd, GNUTLS_STATE state, ContentType type, void *ipt int gnutls_insertHashDataBuffer( GNUTLS_STATE state, char *data, int length) { int old_buffer; - + + if (length==0) return 0; old_buffer = state->gnutls_internals.hash_bufferSize; state->gnutls_internals.hash_bufferSize += length; -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Inserted %d bytes of Hash Data into buffer\n", length); #endif state->gnutls_internals.hash_buffer = @@ -260,7 +262,7 @@ int gnutls_getHashDataFromBuffer( GNUTLS_STATE state, char *data, int length) if (length > state->gnutls_internals.hash_bufferSize) { length = state->gnutls_internals.hash_bufferSize; } -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Got %d bytes of Hash Data from buffer\n", length); #endif state->gnutls_internals.hash_bufferSize -= length; @@ -282,7 +284,7 @@ int gnutls_readHashDataFromBuffer( GNUTLS_STATE state, char *data, int length) if (length > state->gnutls_internals.hash_bufferSize) { length = state->gnutls_internals.hash_bufferSize; } -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Read %d bytes of Hash Data from buffer\n", length); #endif memmove(data, state->gnutls_internals.hash_buffer, length); @@ -294,7 +296,7 @@ int gnutls_readHashDataFromBuffer( GNUTLS_STATE state, char *data, int length) int gnutls_clearHashDataBuffer( GNUTLS_STATE state) { -#ifdef HARD_DEBUG +#ifdef BUFFERS_DEBUG fprintf(stderr, "Cleared Hash Data from buffer\n"); #endif state->gnutls_internals.hash_bufferSize = 0; diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c index c49b674d57..36166188e8 100644 --- a/lib/gnutls_handshake.c +++ b/lib/gnutls_handshake.c @@ -300,7 +300,7 @@ int _gnutls_send_handshake(int cd, GNUTLS_STATE state, void *i_data, memmove(&data[pos], i_data, i_datasize - 4); #ifdef HANDSHAKE_DEBUG - fprintf(stderr, "Send HANDSHAKE[%d] of %ld bytes\n", type, i_datasize+4); + fprintf(stderr, "%s was send [%ld bytes]\n", _gnutls_handshake2str(type), i_datasize); #endif /* Here we keep the handshake messages in order to hash them later! @@ -370,7 +370,7 @@ int _gnutls_recv_handshake(int cd, GNUTLS_STATE state, uint8 **data, length32 = byteswap32(length32); #endif #ifdef HANDSHAKE_DEBUG - fprintf(stderr, "Received HANDSHAKE[%d] of %ld bytes\n", dataptr[0], length32+4); + fprintf(stderr, "%s was received [%ld bytes]\n", _gnutls_handshake2str(dataptr[0]), length32+HANDSHAKE_HEADERS_SIZE); #endif dataptr = gnutls_realloc( dataptr, length32+HANDSHAKE_HEADERS_SIZE); @@ -753,10 +753,10 @@ int _gnutls_recv_hello(int cd, GNUTLS_STATE state, char *data, int datalen) gnutls_free(cipher_suites); gnutls_free(compression_methods); - z = _gnutls_parse_extensions( state, &data[pos], datalen); /* datalen is the rest of the parsed length */ - if (z < 0) { + ret = _gnutls_parse_extensions( state, &data[pos], datalen); /* datalen is the rest of the parsed length */ + if (ret < 0) { gnutls_assert(); - return z; + return ret; } } else { /* Server side reading a client hello */ diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index 968a2be320..84b5e1ad2b 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -26,9 +26,10 @@ #define HANDSHAKE_DEBUG #define READ_DEBUG #define WRITE_DEBUG -#define HARD_DEBUG*/ +#define BUFFERS_DEBUG +#define HARD_DEBUG #define DEBUG - +*/ #define MAX32 4294967295 #define MAX24 16777215 diff --git a/lib/gnutls_kx.c b/lib/gnutls_kx.c index ffa7a18c0a..fa8023a5a1 100644 --- a/lib/gnutls_kx.c +++ b/lib/gnutls_kx.c @@ -249,7 +249,7 @@ int _gnutls_recv_client_kx_message(int cd, GNUTLS_STATE state) } secure_free(premaster); #ifdef HARD_DEBUG - fprintf(stderr, "master secret: %s\n", _gnutls_bin2hex(master, 48)); + fprintf(stderr, "MASTER SECRET: %s\n", _gnutls_bin2hex(master, 48)); #endif memmove(state->security_parameters.master_secret, master, 48); secure_free(master); diff --git a/src/serv.c b/src/serv.c index c0e3fbe803..521c4dd18d 100644 --- a/src/serv.c +++ b/src/serv.c @@ -43,7 +43,7 @@ int main() char topbuf[512]; GNUTLS_STATE state; char buffer[MAX_BUF+1]; - + int optval = 1; listen_sd = socket(AF_INET, SOCK_STREAM, 0); ERR(listen_sd, "socket"); @@ -53,6 +53,7 @@ int main() sa_serv.sin_addr.s_addr = INADDR_ANY; sa_serv.sin_port = htons(PORT); /* Server Port number */ + setsockopt( listen_sd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)); err = bind(listen_sd, (SA *) & sa_serv, sizeof(sa_serv)); ERR(err, "bind"); err = listen(listen_sd, 1024); |