-Version ?.?.?
+Version 0.3.0 (17/12/2001)
- Corrected bug in new integer formatting (now we use the old again)
- Several corrections and usual cleanups
MAC\_SHA is used in the above example.
\end{itemize}
+The ciphersuite that will be used in the connection is negotiated at
+the handshake procedure. However you must note that \tlsI does not always
+negotiate the strongest available cipher suite. There are cases where
+a man in the middle attacker could make the two entities negotiate
+the least secure method they support. For that reason do not enable
+ciphers and algorithms that you consider weak.
+
\addvspace{1.5cm}
gnutls_write( state, MSG, strlen(MSG));
ret = gnutls_read( state, buffer, MAX_BUF);
- if (gnutls_is_fatal_error(ret) == 1 || ret == 0) {
+ if (gnutls_error_is_fatal(ret) == 1 || ret == 0) {
if (ret == 0) {
printf("- Peer has closed the GNUTLS connection\n");
goto end;
printf("* Received alert [%d]\n", gnutls_alert_get_last(state));
if (ret == GNUTLS_E_REHANDSHAKE) {
printf("* Received HelloRequest message (server asked to rehandshake)\n");
- gnutls_send_appropriate_alert( state, ret); /* we don't want rehandshake */
+ gnutls_alert_send_appropriate( state, ret); /* we don't want rehandshake */
}
}
gnutls_write( state, MSG, strlen(MSG));
ret = gnutls_read( state, buffer, MAX_BUF);
- if (gnutls_is_fatal_error(ret) == 1 || ret == 0) {
+ if (gnutls_error_is_fatal(ret) == 1 || ret == 0) {
if (ret == 0) {
printf("- Peer has closed the GNUTLS connection\n");
goto end;
printf("* Received alert [%d]\n", gnutls_alert_get_last(state));
if (ret == GNUTLS_E_REHANDSHAKE)
printf("* Received HelloRequest message (server asked to rehandshake)\n");
- gnutls_send_appropriate_alert( state, ret); /* we don't want rehandshake */
+ gnutls_alert_send_appropriate( state, ret); /* we don't want rehandshake */
}
if (ret > 0) {
bzero(buffer, MAX_BUF + 1);
ret = gnutls_read( state, buffer, MAX_BUF);
- if (gnutls_is_fatal_error(ret) == 1 || ret == 0) {
+ if (gnutls_error_is_fatal(ret) == 1 || ret == 0) {
if (ret == 0) {
printf
("\n- Peer has closed the GNUTLS connection\n");
gnutls_write( state, MSG, strlen(MSG));
ret = gnutls_read( state, buffer, MAX_BUF);
- if (gnutls_is_fatal_error(ret) == 1 || ret == 0) {
+ if (gnutls_error_is_fatal(ret) == 1 || ret == 0) {
if (ret == 0) {
printf("- Peer has closed the GNUTLS connection\n");
goto end;
/* internal functions */
int gnutls_init(GNUTLS_STATE * state, ConnectionEnd con_end);
-int gnutls_deinit(GNUTLS_STATE state);
+void gnutls_deinit(GNUTLS_STATE state);
int gnutls_bye( GNUTLS_STATE state, CloseRequest how);
int gnutls_handshake( GNUTLS_STATE state);
/* error functions */
-int gnutls_is_fatal_error( int error);
+int gnutls_error_is_fatal( int error);
+#define gnutls_is_fatal_error(x) gnutls_error_is_fatal(x)
+
void gnutls_perror( int error);
const char* gnutls_strerror( int error);
typedef void (*LOG_FUNC)( const char*);
-void gnutls_transport_set_push_function( GNUTLS_STATE, GNUTLS_PUSH_FUNC push_func);
-void gnutls_transport_set_pull_function( GNUTLS_STATE, GNUTLS_PULL_FUNC pull_func);
+void gnutls_transport_set_push_func( GNUTLS_STATE, GNUTLS_PUSH_FUNC push_func);
+void gnutls_transport_set_pull_func( GNUTLS_STATE, GNUTLS_PULL_FUNC pull_func);
+
+#define gnutls_transport_set_push_function gnutls_transport_set_push_func
+#define gnutls_transport_set_pull_function gnutls_transport_set_pull_func
size_t gnutls_record_get_max_size( GNUTLS_STATE state);
size_t gnutls_record_set_max_size( GNUTLS_STATE state, size_t size);
/* return immediately if we got an interrupt or eagain
* error.
*/
- if (ret < 0 && gnutls_is_fatal_error(ret)==0) {
+ if (ret < 0 && gnutls_error_is_fatal(ret)==0) {
return ret;
}
}
if (ret == (recvdata - recvlowat) && recvlowat > 0) {
ret2 = _gnutls_read( state, &buf[buf_pos], recvlowat, MSG_PEEK);
- if (ret2 < 0 && gnutls_is_fatal_error(ret2)==0) {
+ if (ret2 < 0 && gnutls_error_is_fatal(ret2)==0) {
return ret2;
}
* by one of these CAs. These names are DER encoded. To get a more
* meaningful value use the function gnutls_x509pki_extract_dn().
*
- * This function specifies what we (in case of a client) are going
+ * This function specifies what we, in case of a client, are going
* to do when we have to send a certificate. If this callback
* function is not provided then gnutls will automaticaly try to
* find an appropriate certificate to send.
* only to the return value of the callback function.
*
* The callback function should return the index of the certificate
- * choosen by the user (or -1 to indicate that the user
- * does not want to use client authentication).
+ * choosen by the user. -1 indicates that the user
+ * does not want to use client authentication.
*
* This function returns 0 on success.
**/
* 'server_cert' contains 'ncerts' gnutls_datum structures which hold
* the DER encoded X.509 certificates of the server.
*
- * This function specifies what we (in case of a server) are going
+ * This function specifies what we, in case of a server, are going
* to do when we have to send a certificate. If this callback
* function is not provided then gnutls will automaticaly try to
* find an appropriate certificate to send. (actually send the first in the list)
*
* The callback function will only be called once per handshake.
* The callback function should return the index of the certificate
- * choosen by the server (or -1 in case of an error)
+ * choosen by the server. -1 indicates an error.
*
**/
void gnutls_x509pki_set_server_cert_callback(GNUTLS_STATE state,
/**
- * gnutls_is_fatal_error - Returns non-zero in case of a fatal error
+ * gnutls_error_is_fatal - Returns non-zero in case of a fatal error
* @error: is an error returned by a gnutls function. Error should be a negative value.
*
* If a function returns a negative value you may feed that value
* error code manualy, since some non-fatal errors to the protocol
* may be fatal for you (your program).
**/
-int gnutls_is_fatal_error(int error)
+int gnutls_error_is_fatal(int error)
{
int ret = 0;
const char* gnutls_strerror(int error);
void gnutls_perror(int error);
-int gnutls_is_fatal_error( int error);
+int gnutls_error_is_fatal( int error);
void _gnutls_log( const char *fmt, ...);
*/
/**
- * gnutls_transport_set_pull_function - This function sets a read like function
+ * gnutls_transport_set_pull_func - This function sets a read like function
* @pull_func: it's a function like read
* @state: gnutls state
*
* PULL_FUNC is of the form,
* ssize_t (*PULL_FUNC)(GNUTLS_SOCKET_PTR, const void*, size_t);
**/
-void gnutls_transport_set_pull_function( GNUTLS_STATE state, PULL_FUNC pull_func) {
+void gnutls_transport_set_pull_func( GNUTLS_STATE state, PULL_FUNC pull_func) {
state->gnutls_internals._gnutls_pull_func = pull_func;
}
/**
- * gnutls_transport_set_push_function - This function sets the function to send data
+ * gnutls_transport_set_push_func - This function sets the function to send data
* @push_func: it's a function like write
* @state: gnutls state
*
* PUSH_FUNC is of the form,
* ssize_t (*PUSH_FUNC)(GNUTLS_SOCKET_PTR, const void*, size_t);
**/
-void gnutls_transport_set_push_function( GNUTLS_STATE state, PUSH_FUNC push_func) {
+void gnutls_transport_set_push_func( GNUTLS_STATE state, PUSH_FUNC push_func) {
state->gnutls_internals._gnutls_push_func = push_func;
}
* If the client does not wish to renegotiate parameters he
* will reply with an alert message, thus the return code will be
* GNUTLS_E_WARNING_ALERT_RECEIVED and the alert will be
- * GNUTLS_NO_RENEGOTIATION.
+ * GNUTLS_A_NO_RENEGOTIATION.
**/
int gnutls_rehandshake(GNUTLS_STATE state)
{
#define IMED_RET( str, ret) \
if (ret < 0) { \
- if (gnutls_is_fatal_error(ret)==0) return ret; \
+ if (gnutls_error_is_fatal(ret)==0) return ret; \
gnutls_assert(); \
ERR( str, ret); \
gnutls_clear_handshake_buffer(state); \
*
* This function clears all buffers associated with the &state.
**/
-int gnutls_deinit(GNUTLS_STATE state)
+void gnutls_deinit(GNUTLS_STATE state)
{
/* if the session has failed abnormally it has to be removed from the db */
if ( state->gnutls_internals.resumable==RESUME_FALSE) {
memset( state, 0, sizeof(struct GNUTLS_STATE_INT));
gnutls_free(state);
- return 0;
+
+ return;
}
inline
* In case of GNUTLS_SHUT_RDWR then the TLS connection gets terminated and
* further receives and sends will be disallowed. If the return
* value is zero you may continue using the connection.
- * (GNUTLS_SHUT_RDWR actually sends an alert containing a close request
- * and waits for the peer to reply with the same message)
+ * GNUTLS_SHUT_RDWR actually sends an alert containing a close request
+ * and waits for the peer to reply with the same message.
*
* In case of GNUTLS_SHUT_WR then the TLS connection gets terminated and
* further sends will be disallowed. In order to reuse the connection
* you should wait for an EOF from the peer.
- * (GNUTLS_SHUT_WR sends an alert containing a close request)
+ * GNUTLS_SHUT_WR sends an alert containing a close request.
*
* This function may also return GNUTLS_E_AGAIN, or GNUTLS_E_INTERRUPTED.
*
if ( ret != cipher_size) {
gnutls_free( cipher);
- if ( ret < 0 && gnutls_is_fatal_error(ret)==0) {
+ if ( ret < 0 && gnutls_error_is_fatal(ret)==0) {
/* If we have sent any data then return
* that value.
*/
* must be set to non blocking mode
*/
if ( (ret = _gnutls_read_buffered( state, &headers, header_size, -1)) != header_size) {
- if (ret < 0 && gnutls_is_fatal_error(ret)==0) return ret;
+ if (ret < 0 && gnutls_error_is_fatal(ret)==0) return ret;
state->gnutls_internals.valid_connection = VALID_FALSE;
if (type==GNUTLS_ALERT) {
/* check if we have that data into buffer.
*/
if ( (ret = _gnutls_read_buffered( state, &recv_data, header_size+length, recv_type)) != length+header_size) {
- if (ret<0 && gnutls_is_fatal_error(ret)==0) return ret;
+ if (ret<0 && gnutls_error_is_fatal(ret)==0) return ret;
state->gnutls_internals.valid_connection = VALID_FALSE;
state->gnutls_internals.resumable = RESUME_FALSE;
*
* Returns the current session id. This can be used if you want to check if
* the next session you tried to resume was actually resumed.
- * (resumed sessions have the same sessionID with the first session)
+ * This is because resumed sessions have the same sessionID with the
+ * original session.
*
* Session id is some data set by the server, that identify the current session.
* In TLS 1.0 session id should not be more than 32 bytes.
} while( ret==GNUTLS_E_INTERRUPTED || ret==GNUTLS_E_AGAIN);
/* remove new line */
- if (gnutls_is_fatal_error(ret) == 1 || ret==0) {
+ if (gnutls_error_is_fatal(ret) == 1 || ret==0) {
if (ret == 0) {
printf("- Peer has closed the GNUTLS connection\n");
break;
bzero(buffer, MAX_BUF + 1);
ret = read_request( state, buffer, MAX_BUF, (http==0)?1:2);
- if (gnutls_is_fatal_error(ret) == 1 || ret == 0) {
+ if (gnutls_error_is_fatal(ret) == 1 || ret == 0) {
fflush(stdout);
if (ret == 0) {
printf