Home | History | Annotate | Download | only in tls
      1 /*
      2  * TLSv1 client - internal structures
      3  * Copyright (c) 2006-2011, Jouni Malinen <j (at) w1.fi>
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License version 2 as
      7  * published by the Free Software Foundation.
      8  *
      9  * Alternatively, this software may be distributed under the terms of BSD
     10  * license.
     11  *
     12  * See README and COPYING for more details.
     13  */
     14 
     15 #ifndef TLSV1_CLIENT_I_H
     16 #define TLSV1_CLIENT_I_H
     17 
     18 struct tlsv1_client {
     19 	enum {
     20 		CLIENT_HELLO, SERVER_HELLO, SERVER_CERTIFICATE,
     21 		SERVER_KEY_EXCHANGE, SERVER_CERTIFICATE_REQUEST,
     22 		SERVER_HELLO_DONE, CLIENT_KEY_EXCHANGE, CHANGE_CIPHER_SPEC,
     23 		SERVER_CHANGE_CIPHER_SPEC, SERVER_FINISHED, ACK_FINISHED,
     24 		ESTABLISHED, FAILED
     25 	} state;
     26 
     27 	struct tlsv1_record_layer rl;
     28 
     29 	u8 session_id[TLS_SESSION_ID_MAX_LEN];
     30 	size_t session_id_len;
     31 	u8 client_random[TLS_RANDOM_LEN];
     32 	u8 server_random[TLS_RANDOM_LEN];
     33 	u8 master_secret[TLS_MASTER_SECRET_LEN];
     34 
     35 	u8 alert_level;
     36 	u8 alert_description;
     37 
     38 	unsigned int certificate_requested:1;
     39 	unsigned int session_resumed:1;
     40 	unsigned int session_ticket_included:1;
     41 	unsigned int use_session_ticket:1;
     42 	unsigned int disable_time_checks:1;
     43 
     44 	struct crypto_public_key *server_rsa_key;
     45 
     46 	struct tls_verify_hash verify;
     47 
     48 #define MAX_CIPHER_COUNT 30
     49 	u16 cipher_suites[MAX_CIPHER_COUNT];
     50 	size_t num_cipher_suites;
     51 
     52 	u16 prev_cipher_suite;
     53 
     54 	u8 *client_hello_ext;
     55 	size_t client_hello_ext_len;
     56 
     57 	/* The prime modulus used for Diffie-Hellman */
     58 	u8 *dh_p;
     59 	size_t dh_p_len;
     60 	/* The generator used for Diffie-Hellman */
     61 	u8 *dh_g;
     62 	size_t dh_g_len;
     63 	/* The server's Diffie-Hellman public value */
     64 	u8 *dh_ys;
     65 	size_t dh_ys_len;
     66 
     67 	struct tlsv1_credentials *cred;
     68 
     69 	tlsv1_client_session_ticket_cb session_ticket_cb;
     70 	void *session_ticket_cb_ctx;
     71 };
     72 
     73 
     74 void tls_alert(struct tlsv1_client *conn, u8 level, u8 description);
     75 void tlsv1_client_free_dh(struct tlsv1_client *conn);
     76 int tls_derive_pre_master_secret(u8 *pre_master_secret);
     77 int tls_derive_keys(struct tlsv1_client *conn,
     78 		    const u8 *pre_master_secret, size_t pre_master_secret_len);
     79 u8 * tls_send_client_hello(struct tlsv1_client *conn, size_t *out_len);
     80 u8 * tlsv1_client_send_alert(struct tlsv1_client *conn, u8 level,
     81 			     u8 description, size_t *out_len);
     82 u8 * tlsv1_client_handshake_write(struct tlsv1_client *conn, size_t *out_len,
     83 				  int no_appl_data);
     84 int tlsv1_client_process_handshake(struct tlsv1_client *conn, u8 ct,
     85 				   const u8 *buf, size_t *len,
     86 				   u8 **out_data, size_t *out_len);
     87 
     88 #endif /* TLSV1_CLIENT_I_H */
     89