00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TLSV1_CLIENT_I_H
00016 #define TLSV1_CLIENT_I_H
00017
00018 struct tlsv1_client {
00019 enum {
00020 CLIENT_HELLO, SERVER_HELLO, SERVER_CERTIFICATE,
00021 SERVER_KEY_EXCHANGE, SERVER_CERTIFICATE_REQUEST,
00022 SERVER_HELLO_DONE, CLIENT_KEY_EXCHANGE, CHANGE_CIPHER_SPEC,
00023 SERVER_CHANGE_CIPHER_SPEC, SERVER_FINISHED, ACK_FINISHED,
00024 ESTABLISHED, FAILED
00025 } state;
00026
00027 struct tlsv1_record_layer rl;
00028
00029 u8 session_id[TLS_SESSION_ID_MAX_LEN];
00030 size_t session_id_len;
00031 u8 client_random[TLS_RANDOM_LEN];
00032 u8 server_random[TLS_RANDOM_LEN];
00033 u8 master_secret[TLS_MASTER_SECRET_LEN];
00034
00035 u8 alert_level;
00036 u8 alert_description;
00037
00038 unsigned int certificate_requested:1;
00039 unsigned int session_resumed:1;
00040 unsigned int session_ticket_included:1;
00041 unsigned int use_session_ticket:1;
00042
00043 struct crypto_public_key *server_rsa_key;
00044
00045 struct tls_verify_hash verify;
00046
00047 #define MAX_CIPHER_COUNT 30
00048 u16 cipher_suites[MAX_CIPHER_COUNT];
00049 size_t num_cipher_suites;
00050
00051 u16 prev_cipher_suite;
00052
00053 u8 *client_hello_ext;
00054 size_t client_hello_ext_len;
00055
00056
00057 u8 *dh_p;
00058 size_t dh_p_len;
00059
00060 u8 *dh_g;
00061 size_t dh_g_len;
00062
00063 u8 *dh_ys;
00064 size_t dh_ys_len;
00065
00066 struct tlsv1_credentials *cred;
00067
00068 tlsv1_client_session_ticket_cb session_ticket_cb;
00069 void *session_ticket_cb_ctx;
00070 };
00071
00072
00073 void tls_alert(struct tlsv1_client *conn, u8 level, u8 description);
00074 void tlsv1_client_free_dh(struct tlsv1_client *conn);
00075 int tls_derive_pre_master_secret(u8 *pre_master_secret);
00076 int tls_derive_keys(struct tlsv1_client *conn,
00077 const u8 *pre_master_secret, size_t pre_master_secret_len);
00078 u8 * tls_send_client_hello(struct tlsv1_client *conn, size_t *out_len);
00079 u8 * tlsv1_client_send_alert(struct tlsv1_client *conn, u8 level,
00080 u8 description, size_t *out_len);
00081 u8 * tlsv1_client_handshake_write(struct tlsv1_client *conn, size_t *out_len,
00082 int no_appl_data);
00083 int tlsv1_client_process_handshake(struct tlsv1_client *conn, u8 ct,
00084 const u8 *buf, size_t *len,
00085 u8 **out_data, size_t *out_len);
00086
00087 #endif