gnutls_handshake.c File Reference

#include "MHD_config.h"
#include "gnutls_int.h"
#include "gnutls_errors.h"
#include "gnutls_dh.h"
#include "debug.h"
#include "gnutls_algorithms.h"
#include "gnutls_cipher.h"
#include "gnutls_buffers.h"
#include "gnutls_kx.h"
#include "gnutls_handshake.h"
#include "gnutls_num.h"
#include "gnutls_hash_int.h"
#include "gnutls_extensions.h"
#include "gnutls_supplemental.h"
#include "gnutls_auth_int.h"
#include "auth_cert.h"
#include "gnutls_cert.h"
#include "gnutls_constate.h"
#include "gnutls_record.h"
#include "gnutls_state.h"
#include "gnutls_rsa_export.h"
#include "gc.h"
Include dependency graph for gnutls_handshake.c:

Go to the source code of this file.

Defines

#define ERR(x, y)
#define TRUE   1
#define FALSE   0
#define MAX_EXT_DATA_LENGTH   1024
#define SSL3_CLIENT_MSG   "CLNT"
#define SSL3_SERVER_MSG   "SRVR"
#define SSL_MSG_LEN   4
#define SERVER_MSG   "server finished"
#define CLIENT_MSG   "client finished"
#define TLS_MSG_LEN   15
#define SSL2_HEADERS   1
#define MHD__gnutls_handshake_header_buffer_clear(session)   session->internals.handshake_header_buffer.header_size = 0
#define IMED_RET(str, ret)

Functions

static int MHD_gtls_remove_unwanted_ciphersuites (MHD_gtls_session_t session, cipher_suite_st **cipherSuites, int numCipherSuites, enum MHD_GNUTLS_PublicKeyAlgorithm)
static int MHD_gtls_server_select_suite (MHD_gtls_session_t session, opaque *data, int datalen)
static int MHD_gtls_generate_session_id (opaque *session_id, uint8_t *len)
static int MHD_gtls_handshake_common (MHD_gtls_session_t session)
static int MHD_gtls_handshake_server (MHD_gtls_session_t session)
static int MHD__gnutls_server_select_comp_method (MHD_gtls_session_t session, opaque *data, int datalen)
static void MHD__gnutls_handshake_hash_buffers_clear (MHD_gtls_session_t session)
void MHD__gnutls_handshake_set_max_packet_length (MHD_gtls_session_t session, size_t max)
static void MHD_gtls_set_server_random (MHD_gtls_session_t session, uint8_t *rnd)
static void MHD_gtls_set_client_random (MHD_gtls_session_t session, uint8_t *rnd)
static int MHD__gnutls_ssl3_finished (MHD_gtls_session_t session, int type, opaque *ret)
static int MHD__gnutls_finished (MHD_gtls_session_t session, int type, void *ret)
static int MHD_gtls_tls_create_random (opaque *dst)
static int MHD_gtls_negotiate_version (MHD_gtls_session_t session, enum MHD_GNUTLS_Protocol adv_version)
static int MHD__gnutls_read_client_hello (MHD_gtls_session_t session, opaque *data, int datalen)
static int MHD__gnutls_handshake_hash_pending (MHD_gtls_session_t session)
static int MHD__gnutls_send_finished (MHD_gtls_session_t session, int again)
static int MHD__gnutls_recv_finished (MHD_gtls_session_t session)
static int MHD__gnutls_server_find_pk_algos_in_ciphersuites (const opaque *data, int datalen)
static int MHD__gnutls_send_empty_handshake (MHD_gtls_session_t session, MHD_gnutls_handshake_description_t type, int again)
static int MHD__gnutls_handshake_hash_add_sent (MHD_gtls_session_t session, MHD_gnutls_handshake_description_t type, opaque *dataptr, uint32_t datalen)
int MHD_gtls_send_handshake (MHD_gtls_session_t session, void *i_data, uint32_t i_datasize, MHD_gnutls_handshake_description_t type)
static int MHD__gnutls_recv_handshake_header (MHD_gtls_session_t session, MHD_gnutls_handshake_description_t type, MHD_gnutls_handshake_description_t *recv_type)
static int MHD__gnutls_handshake_hash_add_recvd (MHD_gtls_session_t session, MHD_gnutls_handshake_description_t recv_type, opaque *header, uint16_t header_size, opaque *dataptr, uint32_t datalen)
int MHD_gtls_recv_handshake (MHD_gtls_session_t session, uint8_t **data, int *datalen, MHD_gnutls_handshake_description_t type, Optional optional)
static int MHD__gnutls_send_server_hello (MHD_gtls_session_t session, int again)
int MHD_gtls_send_hello (MHD_gtls_session_t session, int again)
int MHD_gtls_recv_hello (MHD_gtls_session_t session, opaque *data, int datalen)
int MHD__gnutls_rehandshake (MHD_gtls_session_t session)
static int MHD__gnutls_abort_handshake (MHD_gtls_session_t session, int ret)
static int MHD__gnutls_handshake_hash_init (MHD_gtls_session_t session)
static int MHD__gnutls_send_supplemental (MHD_gtls_session_t session, int again)
static int MHD__gnutls_recv_supplemental (MHD_gtls_session_t session)
int MHD__gnutls_handshake (MHD_gtls_session_t session)
static int MHD__gnutls_send_handshake_final (MHD_gtls_session_t session, int init)
static int MHD__gnutls_recv_handshake_final (MHD_gtls_session_t session, int init)
int MHD_gtls_recv_hello_request (MHD_gtls_session_t session, void *data, uint32_t data_size)
static int check_server_params (MHD_gtls_session_t session, enum MHD_GNUTLS_KeyExchangeAlgorithm kx, enum MHD_GNUTLS_KeyExchangeAlgorithm *alg, int alg_size)
enum MHD_GNUTLS_Protocol MHD_gtls_get_adv_version (MHD_gtls_session_t session)

Define Documentation

#define CLIENT_MSG   "client finished"

Definition at line 185 of file gnutls_handshake.c.

Referenced by MHD__gnutls_finished().

#define ERR ( x,
 ) 
#define FALSE   0

Definition at line 58 of file gnutls_handshake.c.

Referenced by MHD_gtls_handshake_common().

#define IMED_RET ( str,
ret   ) 
Value:
do { \
        if (ret < 0) { \
                if (MHD_gtls_error_is_fatal(ret)==0) return ret; \
                MHD_gnutls_assert(); \
                ERR( str, ret); \
                MHD__gnutls_handshake_hash_buffers_clear(session); \
                return ret; \
        } } while (0)

Definition at line 2173 of file gnutls_handshake.c.

Referenced by MHD_gtls_handshake_common(), and MHD_gtls_handshake_server().

#define MAX_EXT_DATA_LENGTH   1024

Definition at line 64 of file gnutls_handshake.c.

Referenced by MHD__gnutls_send_server_hello().

#define MHD__gnutls_handshake_header_buffer_clear ( session   )     session->internals.handshake_header_buffer.header_size = 0

Definition at line 1034 of file gnutls_handshake.c.

Referenced by MHD_gtls_recv_handshake().

#define SERVER_MSG   "server finished"

Definition at line 184 of file gnutls_handshake.c.

Referenced by MHD__gnutls_finished().

#define SSL2_HEADERS   1

Definition at line 905 of file gnutls_handshake.c.

Referenced by MHD__gnutls_recv_handshake_header().

#define SSL3_CLIENT_MSG   "CLNT"

Definition at line 135 of file gnutls_handshake.c.

Referenced by MHD__gnutls_ssl3_finished().

#define SSL3_SERVER_MSG   "SRVR"

Definition at line 136 of file gnutls_handshake.c.

Referenced by MHD__gnutls_ssl3_finished().

#define SSL_MSG_LEN   4

Definition at line 137 of file gnutls_handshake.c.

Referenced by MHD__gnutls_ssl3_finished().

#define TLS_MSG_LEN   15

Definition at line 186 of file gnutls_handshake.c.

Referenced by MHD__gnutls_finished().

#define TRUE   1

Function Documentation

static int check_server_params ( MHD_gtls_session_t  session,
enum MHD_GNUTLS_KeyExchangeAlgorithm  kx,
enum MHD_GNUTLS_KeyExchangeAlgorithm alg,
int  alg_size 
) [inline, static]
static int MHD__gnutls_abort_handshake ( MHD_gtls_session_t  session,
int  ret 
) [inline, static]

Definition at line 1992 of file gnutls_handshake.c.

References GNUTLS_A_NO_RENEGOTIATION, GNUTLS_E_GOT_APPLICATION_DATA, GNUTLS_E_INTERNAL_ERROR, GNUTLS_E_WARNING_ALERT_RECEIVED, and MHD_gnutls_alert_get().

Referenced by MHD__gnutls_handshake().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD__gnutls_finished ( MHD_gtls_session_t  session,
int  type,
void *  ret 
) [static]
int MHD__gnutls_handshake ( MHD_gtls_session_t  session  ) 

MHD__gnutls_handshake - This is the main function in the handshake protocol. : is a MHD_gtls_session_t structure.

This function does the handshake of the TLS/SSL protocol, and initializes the TLS connection.

This function will fail if any problem is encountered, and will return a negative error code. In case of a client, if the client has asked to resume a session, but the server couldn't, then a full handshake will be performed.

The non-fatal errors such as GNUTLS_E_AGAIN and GNUTLS_E_INTERRUPTED interrupt the handshake procedure, which should be later be resumed. Call this function again, until it returns 0; cf. MHD__gnutls_record_get_direction() and MHD_gtls_error_is_fatal().

If this function is called by a server after a rehandshake request then GNUTLS_E_GOT_APPLICATION_DATA or GNUTLS_E_WARNING_ALERT_RECEIVED may be returned. Note that these are non fatal errors, only in the specific case of a rehandshake. Their meaning is that the client rejected the rehandshake request.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Definition at line 2124 of file gnutls_handshake.c.

References MHD_gtls_security_param_st::entity, GNUTLS_CLIENT, MHD__gnutls_abort_handshake(), MHD__gnutls_handshake_hash_init(), MHD__gnutls_handshake_io_buffer_clear, MHD_gnutls_assert, MHD_gtls_handshake_common(), MHD_gtls_handshake_internal_state_clear(), MHD_gtls_handshake_server(), MHD_gtls_session_int::security_parameters, STATE, and STATE0.

Referenced by MHD_tls_connection_handle_read().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD__gnutls_handshake_hash_add_recvd ( MHD_gtls_session_t  session,
MHD_gnutls_handshake_description_t  recv_type,
opaque header,
uint16_t  header_size,
opaque dataptr,
uint32_t  datalen 
) [static]

Definition at line 1040 of file gnutls_handshake.c.

References GNUTLS_HANDSHAKE_HELLO_REQUEST, MHD__gnutls_handshake_hash_pending(), MHD_gnutls_assert, and MHD_gtls_handshake_buffer_put().

Referenced by MHD_gtls_recv_handshake().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD__gnutls_handshake_hash_add_sent ( MHD_gtls_session_t  session,
MHD_gnutls_handshake_description_t  type,
opaque dataptr,
uint32_t  datalen 
) [static]
static void MHD__gnutls_handshake_hash_buffers_clear ( MHD_gtls_session_t  session  )  [static]

Definition at line 94 of file gnutls_handshake.c.

References MHD_gtls_internals_st::handshake_mac_handle_md5, MHD_gtls_internals_st::handshake_mac_handle_sha, MHD_gtls_session_int::internals, MHD_gnutls_hash_deinit(), and MHD_gtls_handshake_buffer_clear().

Referenced by MHD_gtls_handshake_common().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD__gnutls_handshake_hash_init ( MHD_gtls_session_t  session  )  [inline, static]
static int MHD__gnutls_handshake_hash_pending ( MHD_gtls_session_t  session  )  [static]
void MHD__gnutls_handshake_set_max_packet_length ( MHD_gtls_session_t  session,
size_t  max 
)

gnutls_handshake_set_max_packet_length - This function will set the maximum length of a handshake message : is a gnutls_session_t structure. : is the maximum number.

This function will set the maximum size of a handshake message. Handshake messages over this size are rejected. The default value is 16kb which is large enough. Set this to 0 if you do not want to set an upper limit.

Definition at line 115 of file gnutls_handshake.c.

References MHD_gtls_session_int::internals, and MHD_gtls_internals_st::max_handshake_data_buffer_size.

Referenced by MHD__gnutls_init().

Here is the caller graph for this function:

static int MHD__gnutls_read_client_hello ( MHD_gtls_session_t  session,
opaque data,
int  datalen 
) [static]
static int MHD__gnutls_recv_finished ( MHD_gtls_session_t  session  )  [static]
static int MHD__gnutls_recv_handshake_final ( MHD_gtls_session_t  session,
int  init 
) [static]
static int MHD__gnutls_recv_handshake_header ( MHD_gtls_session_t  session,
MHD_gnutls_handshake_description_t  type,
MHD_gnutls_handshake_description_t recv_type 
) [static]
static int MHD__gnutls_recv_supplemental ( MHD_gtls_session_t  session  )  [static]

Definition at line 2067 of file gnutls_handshake.c.

References GNUTLS_HANDSHAKE_SUPPLEMENTAL, MHD__gnutls_debug_log, MHD__gnutls_parse_supplemental(), MHD_gnutls_assert, MHD_gnutls_free, MHD_gtls_recv_handshake(), and OPTIONAL_PACKET.

Referenced by MHD_gtls_handshake_server().

Here is the call graph for this function:

Here is the caller graph for this function:

int MHD__gnutls_rehandshake ( MHD_gtls_session_t  session  ) 

MHD__gnutls_rehandshake - This function will renegotiate security parameters : is a MHD_gtls_session_t structure.

This function will renegotiate security parameters with the client. This should only be called in case of a server.

This message informs the peer that we want to renegotiate parameters (perform a handshake).

If this function succeeds (returns 0), you must call the MHD__gnutls_handshake() function in order to negotiate the new parameters.

If the client does not wish to renegotiate parameters he will should with an alert message, thus the return code will be GNUTLS_E_WARNING_ALERT_RECEIVED and the alert will be GNUTLS_A_NO_RENEGOTIATION. A client may also choose to ignore this message.

Returns: GNUTLS_E_SUCCESS on success, otherwise an error.

Definition at line 1972 of file gnutls_handshake.c.

References AGAIN, GNUTLS_HANDSHAKE_HELLO_REQUEST, MHD__gnutls_send_empty_handshake(), MHD_gnutls_assert, STATE, STATE0, and STATE50.

Here is the call graph for this function:

static int MHD__gnutls_send_empty_handshake ( MHD_gtls_session_t  session,
MHD_gnutls_handshake_description_t  type,
int  again 
) [static]

Definition at line 783 of file gnutls_handshake.c.

References MHD_gtls_send_handshake().

Referenced by MHD__gnutls_rehandshake(), and MHD_gtls_handshake_server().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD__gnutls_send_finished ( MHD_gtls_session_t  session,
int  again 
) [static]
static int MHD__gnutls_send_handshake_final ( MHD_gtls_session_t  session,
int  init 
) [static]

Definition at line 2294 of file gnutls_handshake.c.

References AGAIN, ERR, MHD__gnutls_send_finished(), MHD_gnutls_assert, MHD_gtls_connection_state_init(), MHD_gtls_send_change_cipher_spec(), MHD_gtls_write_connection_state_init(), STATE, STATE0, STATE20, STATE21, and TRUE.

Referenced by MHD_gtls_handshake_common().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD__gnutls_send_server_hello ( MHD_gtls_session_t  session,
int  again 
) [static]
static int MHD__gnutls_send_supplemental ( MHD_gtls_session_t  session,
int  again 
) [static]
static int MHD__gnutls_server_find_pk_algos_in_ciphersuites ( const opaque data,
int  datalen 
) [static]
static int MHD__gnutls_server_select_comp_method ( MHD_gtls_session_t  session,
opaque data,
int  datalen 
) [static]
static int MHD__gnutls_ssl3_finished ( MHD_gtls_session_t  session,
int  type,
opaque ret 
) [static]
static int MHD_gtls_generate_session_id ( opaque session_id,
uint8_t *  len 
) [static]

Definition at line 2553 of file gnutls_handshake.c.

References GC_OK, GNUTLS_E_RANDOM_FAILED, MHD_gc_nonce(), MHD_gnutls_assert, and TLS_MAX_SESSION_ID_SIZE.

Referenced by MHD__gnutls_read_client_hello().

Here is the call graph for this function:

Here is the caller graph for this function:

enum MHD_GNUTLS_Protocol MHD_gtls_get_adv_version ( MHD_gtls_session_t  session  ) 

Definition at line 2800 of file gnutls_handshake.c.

References MHD__gnutls_get_adv_version_major, MHD__gnutls_get_adv_version_minor, and MHD_gtls_version_get().

Referenced by MHD__gnutls_gen_rsa_client_kx().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD_gtls_handshake_common ( MHD_gtls_session_t  session  )  [static]
static int MHD_gtls_handshake_server ( MHD_gtls_session_t  session  )  [static]
static int MHD_gtls_negotiate_version ( MHD_gtls_session_t  session,
enum MHD_GNUTLS_Protocol  adv_version 
) [static]

Definition at line 272 of file gnutls_handshake.c.

References MHD_gtls_set_current_version(), MHD_gtls_version_is_supported(), and MHD_gtls_version_max().

Referenced by MHD__gnutls_read_client_hello().

Here is the call graph for this function:

Here is the caller graph for this function:

int MHD_gtls_recv_handshake ( MHD_gtls_session_t  session,
uint8_t **  data,
int *  datalen,
MHD_gnutls_handshake_description_t  type,
Optional  optional 
)
int MHD_gtls_recv_hello ( MHD_gtls_session_t  session,
opaque data,
int  datalen 
)

Definition at line 1897 of file gnutls_handshake.c.

References MHD_gtls_security_param_st::entity, GNUTLS_CLIENT, MHD__gnutls_read_client_hello(), MHD_gnutls_assert, and MHD_gtls_session_int::security_parameters.

Referenced by MHD_gtls_recv_handshake().

Here is the call graph for this function:

Here is the caller graph for this function:

int MHD_gtls_recv_hello_request ( MHD_gtls_session_t  session,
void *  data,
uint32_t  data_size 
)
static int MHD_gtls_remove_unwanted_ciphersuites ( MHD_gtls_session_t  session,
cipher_suite_st **  cipherSuites,
int  numCipherSuites,
enum MHD_GNUTLS_PublicKeyAlgorithm  requested_pk_algo 
) [static]
int MHD_gtls_send_handshake ( MHD_gtls_session_t  session,
void *  i_data,
uint32_t  i_datasize,
MHD_gnutls_handshake_description_t  type 
)
int MHD_gtls_send_hello ( MHD_gtls_session_t  session,
int  again 
)

Definition at line 1874 of file gnutls_handshake.c.

References MHD_gtls_security_param_st::entity, GNUTLS_CLIENT, MHD__gnutls_send_server_hello(), and MHD_gtls_session_int::security_parameters.

Referenced by MHD_gtls_handshake_server().

Here is the call graph for this function:

Here is the caller graph for this function:

static int MHD_gtls_server_select_suite ( MHD_gtls_session_t  session,
opaque data,
int  datalen 
) [static]
static void MHD_gtls_set_client_random ( MHD_gtls_session_t  session,
uint8_t *  rnd 
) [static]

Definition at line 129 of file gnutls_handshake.c.

References MHD_gtls_security_param_st::client_random, MHD_gtls_session_int::security_parameters, and TLS_RANDOM_SIZE.

Referenced by MHD__gnutls_read_client_hello().

Here is the caller graph for this function:

static void MHD_gtls_set_server_random ( MHD_gtls_session_t  session,
uint8_t *  rnd 
) [static]

Definition at line 123 of file gnutls_handshake.c.

References MHD_gtls_session_int::security_parameters, MHD_gtls_security_param_st::server_random, and TLS_RANDOM_SIZE.

Referenced by MHD__gnutls_read_client_hello().

Here is the caller graph for this function:

static int MHD_gtls_tls_create_random ( opaque dst  )  [static]

Definition at line 247 of file gnutls_handshake.c.

References GC_OK, GNUTLS_E_RANDOM_FAILED, MHD_gc_nonce(), MHD_gnutls_assert, MHD_gtls_write_uint32(), and TLS_RANDOM_SIZE.

Referenced by MHD__gnutls_read_client_hello().

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208