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