Home | History | Annotate | Download | only in eap_server
      1 /*
      2  * EAP-TLS/PEAP/TTLS/FAST server common functions
      3  * Copyright (c) 2004-2009, 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 EAP_TLS_COMMON_H
     16 #define EAP_TLS_COMMON_H
     17 
     18 /**
     19  * struct eap_ssl_data - TLS data for EAP methods
     20  */
     21 struct eap_ssl_data {
     22 	/**
     23 	 * conn - TLS connection context data from tls_connection_init()
     24 	 */
     25 	struct tls_connection *conn;
     26 
     27 	/**
     28 	 * tls_out - TLS message to be sent out in fragments
     29 	 */
     30 	struct wpabuf *tls_out;
     31 
     32 	/**
     33 	 * tls_out_pos - The current position in the outgoing TLS message
     34 	 */
     35 	size_t tls_out_pos;
     36 
     37 	/**
     38 	 * tls_out_limit - Maximum fragment size for outgoing TLS messages
     39 	 */
     40 	size_t tls_out_limit;
     41 
     42 	/**
     43 	 * tls_in - Received TLS message buffer for re-assembly
     44 	 */
     45 	struct wpabuf *tls_in;
     46 
     47 	/**
     48 	 * phase2 - Whether this TLS connection is used in EAP phase 2 (tunnel)
     49 	 */
     50 	int phase2;
     51 
     52 	/**
     53 	 * eap - EAP state machine allocated with eap_server_sm_init()
     54 	 */
     55 	struct eap_sm *eap;
     56 
     57 	enum { MSG, FRAG_ACK, WAIT_FRAG_ACK } state;
     58 	struct wpabuf tmpbuf;
     59 };
     60 
     61 
     62 /* EAP TLS Flags */
     63 #define EAP_TLS_FLAGS_LENGTH_INCLUDED 0x80
     64 #define EAP_TLS_FLAGS_MORE_FRAGMENTS 0x40
     65 #define EAP_TLS_FLAGS_START 0x20
     66 #define EAP_TLS_VERSION_MASK 0x07
     67 
     68  /* could be up to 128 bytes, but only the first 64 bytes are used */
     69 #define EAP_TLS_KEY_LEN 64
     70 
     71 
     72 int eap_server_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
     73 			    int verify_peer);
     74 void eap_server_tls_ssl_deinit(struct eap_sm *sm, struct eap_ssl_data *data);
     75 u8 * eap_server_tls_derive_key(struct eap_sm *sm, struct eap_ssl_data *data,
     76 			       char *label, size_t len);
     77 struct wpabuf * eap_server_tls_build_msg(struct eap_ssl_data *data,
     78 					 int eap_type, int version, u8 id);
     79 struct wpabuf * eap_server_tls_build_ack(u8 id, int eap_type, int version);
     80 int eap_server_tls_phase1(struct eap_sm *sm, struct eap_ssl_data *data);
     81 struct wpabuf * eap_server_tls_encrypt(struct eap_sm *sm,
     82 				       struct eap_ssl_data *data,
     83 				       const struct wpabuf *plain);
     84 int eap_server_tls_process(struct eap_sm *sm, struct eap_ssl_data *data,
     85 			   struct wpabuf *respData, void *priv, int eap_type,
     86 			   int (*proc_version)(struct eap_sm *sm, void *priv,
     87 					       int peer_version),
     88 			   void (*proc_msg)(struct eap_sm *sm, void *priv,
     89 					    const struct wpabuf *respData));
     90 
     91 #endif /* EAP_TLS_COMMON_H */
     92