xref: /freebsd-src/contrib/wpa/src/eap_common/eap_teap_common.h (revision 206b73d0429edb7c49b612537544e677fa568e83)
1*206b73d0SCy Schubert /*
2*206b73d0SCy Schubert  * EAP-TEAP definitions (RFC 7170)
3*206b73d0SCy Schubert  * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
4*206b73d0SCy Schubert  *
5*206b73d0SCy Schubert  * This software may be distributed under the terms of the BSD license.
6*206b73d0SCy Schubert  * See README for more details.
7*206b73d0SCy Schubert  */
8*206b73d0SCy Schubert 
9*206b73d0SCy Schubert #ifndef EAP_TEAP_H
10*206b73d0SCy Schubert #define EAP_TEAP_H
11*206b73d0SCy Schubert 
12*206b73d0SCy Schubert #define EAP_TEAP_VERSION 1
13*206b73d0SCy Schubert #define EAP_TEAP_KEY_LEN 64
14*206b73d0SCy Schubert #define EAP_TEAP_IMCK_LEN 60
15*206b73d0SCy Schubert #define EAP_TEAP_SIMCK_LEN 40
16*206b73d0SCy Schubert #define EAP_TEAP_CMK_LEN 20
17*206b73d0SCy Schubert #define EAP_TEAP_COMPOUND_MAC_LEN 20
18*206b73d0SCy Schubert #define EAP_TEAP_NONCE_LEN 32
19*206b73d0SCy Schubert 
20*206b73d0SCy Schubert #define TEAP_TLS_EXPORTER_LABEL_SKS "EXPORTER: teap session key seed"
21*206b73d0SCy Schubert 
22*206b73d0SCy Schubert #define TLS_EXT_PAC_OPAQUE 35
23*206b73d0SCy Schubert 
24*206b73d0SCy Schubert /*
25*206b73d0SCy Schubert  * RFC 7170: Section 4.2.12.1 - Formats for PAC Attributes
26*206b73d0SCy Schubert  * Note: bit 0x8000 (Mandatory) and bit 0x4000 (Reserved) are also defined
27*206b73d0SCy Schubert  * in the general TLV format (Section 4.2.1).
28*206b73d0SCy Schubert  */
29*206b73d0SCy Schubert #define PAC_TYPE_PAC_KEY 1
30*206b73d0SCy Schubert #define PAC_TYPE_PAC_OPAQUE 2
31*206b73d0SCy Schubert #define PAC_TYPE_CRED_LIFETIME 3
32*206b73d0SCy Schubert #define PAC_TYPE_A_ID 4
33*206b73d0SCy Schubert #define PAC_TYPE_I_ID 5
34*206b73d0SCy Schubert /* 6 - Reserved */
35*206b73d0SCy Schubert #define PAC_TYPE_A_ID_INFO 7
36*206b73d0SCy Schubert #define PAC_TYPE_PAC_ACKNOWLEDGEMENT 8
37*206b73d0SCy Schubert #define PAC_TYPE_PAC_INFO 9
38*206b73d0SCy Schubert #define PAC_TYPE_PAC_TYPE 10
39*206b73d0SCy Schubert 
40*206b73d0SCy Schubert #ifdef _MSC_VER
41*206b73d0SCy Schubert #pragma pack(push, 1)
42*206b73d0SCy Schubert #endif /* _MSC_VER */
43*206b73d0SCy Schubert 
44*206b73d0SCy Schubert struct pac_attr_hdr {
45*206b73d0SCy Schubert 	be16 type;
46*206b73d0SCy Schubert 	be16 len;
47*206b73d0SCy Schubert } STRUCT_PACKED;
48*206b73d0SCy Schubert 
49*206b73d0SCy Schubert struct teap_tlv_hdr {
50*206b73d0SCy Schubert 	be16 tlv_type;
51*206b73d0SCy Schubert 	be16 length;
52*206b73d0SCy Schubert } STRUCT_PACKED;
53*206b73d0SCy Schubert 
54*206b73d0SCy Schubert /* Result TLV and Intermediate-Result TLV */
55*206b73d0SCy Schubert struct teap_tlv_result {
56*206b73d0SCy Schubert 	be16 tlv_type;
57*206b73d0SCy Schubert 	be16 length;
58*206b73d0SCy Schubert 	be16 status;
59*206b73d0SCy Schubert 	/* for Intermediate-Result TLV, followed by optional TLVs */
60*206b73d0SCy Schubert } STRUCT_PACKED;
61*206b73d0SCy Schubert 
62*206b73d0SCy Schubert struct teap_tlv_nak {
63*206b73d0SCy Schubert 	be16 tlv_type;
64*206b73d0SCy Schubert 	be16 length;
65*206b73d0SCy Schubert 	be32 vendor_id;
66*206b73d0SCy Schubert 	be16 nak_type;
67*206b73d0SCy Schubert 	/* followed by optional TLVs */
68*206b73d0SCy Schubert } STRUCT_PACKED;
69*206b73d0SCy Schubert 
70*206b73d0SCy Schubert struct teap_tlv_crypto_binding {
71*206b73d0SCy Schubert 	be16 tlv_type; /* TLV Type[14b] and M/R flags */
72*206b73d0SCy Schubert 	be16 length;
73*206b73d0SCy Schubert 	u8 reserved;
74*206b73d0SCy Schubert 	u8 version;
75*206b73d0SCy Schubert 	u8 received_version;
76*206b73d0SCy Schubert 	u8 subtype; /* Flags[4b] and Sub-Type[4b] */
77*206b73d0SCy Schubert 	u8 nonce[EAP_TEAP_NONCE_LEN];
78*206b73d0SCy Schubert 	u8 emsk_compound_mac[EAP_TEAP_COMPOUND_MAC_LEN];
79*206b73d0SCy Schubert 	u8 msk_compound_mac[EAP_TEAP_COMPOUND_MAC_LEN];
80*206b73d0SCy Schubert } STRUCT_PACKED;
81*206b73d0SCy Schubert 
82*206b73d0SCy Schubert struct teap_tlv_request_action {
83*206b73d0SCy Schubert 	be16 tlv_type;
84*206b73d0SCy Schubert 	be16 length;
85*206b73d0SCy Schubert 	u8 status;
86*206b73d0SCy Schubert 	u8 action;
87*206b73d0SCy Schubert 	/* followed by optional TLVs */
88*206b73d0SCy Schubert } STRUCT_PACKED;
89*206b73d0SCy Schubert 
90*206b73d0SCy Schubert enum teap_request_action {
91*206b73d0SCy Schubert 	TEAP_REQUEST_ACTION_PROCESS_TLV = 1,
92*206b73d0SCy Schubert 	TEAP_REQUEST_ACTION_NEGOTIATE_EAP = 2,
93*206b73d0SCy Schubert };
94*206b73d0SCy Schubert 
95*206b73d0SCy Schubert /* PAC TLV with PAC-Acknowledgement TLV attribute */
96*206b73d0SCy Schubert struct teap_tlv_pac_ack {
97*206b73d0SCy Schubert 	be16 tlv_type;
98*206b73d0SCy Schubert 	be16 length;
99*206b73d0SCy Schubert 	be16 pac_type;
100*206b73d0SCy Schubert 	be16 pac_len;
101*206b73d0SCy Schubert 	be16 result;
102*206b73d0SCy Schubert } STRUCT_PACKED;
103*206b73d0SCy Schubert 
104*206b73d0SCy Schubert struct teap_attr_pac_type {
105*206b73d0SCy Schubert 	be16 type; /* PAC_TYPE_PAC_TYPE */
106*206b73d0SCy Schubert 	be16 length; /* 2 */
107*206b73d0SCy Schubert 	be16 pac_type;
108*206b73d0SCy Schubert } STRUCT_PACKED;
109*206b73d0SCy Schubert 
110*206b73d0SCy Schubert #ifdef _MSC_VER
111*206b73d0SCy Schubert #pragma pack(pop)
112*206b73d0SCy Schubert #endif /* _MSC_VER */
113*206b73d0SCy Schubert 
114*206b73d0SCy Schubert #define TEAP_CRYPTO_BINDING_SUBTYPE_REQUEST 0
115*206b73d0SCy Schubert #define TEAP_CRYPTO_BINDING_SUBTYPE_RESPONSE 1
116*206b73d0SCy Schubert 
117*206b73d0SCy Schubert #define TEAP_CRYPTO_BINDING_EMSK_CMAC 1
118*206b73d0SCy Schubert #define TEAP_CRYPTO_BINDING_MSK_CMAC 2
119*206b73d0SCy Schubert #define TEAP_CRYPTO_BINDING_EMSK_AND_MSK_CMAC 3
120*206b73d0SCy Schubert 
121*206b73d0SCy Schubert 
122*206b73d0SCy Schubert #define EAP_TEAP_PAC_KEY_LEN 48
123*206b73d0SCy Schubert 
124*206b73d0SCy Schubert /* RFC 7170: 4.2.12.6 PAC-Type TLV */
125*206b73d0SCy Schubert #define PAC_TYPE_TUNNEL_PAC 1
126*206b73d0SCy Schubert 
127*206b73d0SCy Schubert 
128*206b73d0SCy Schubert /* RFC 7170, 4.2.1: General TLV Format */
129*206b73d0SCy Schubert enum teap_tlv_types {
130*206b73d0SCy Schubert 	TEAP_TLV_AUTHORITY_ID = 1,
131*206b73d0SCy Schubert 	TEAP_TLV_IDENTITY_TYPE = 2,
132*206b73d0SCy Schubert 	TEAP_TLV_RESULT = 3,
133*206b73d0SCy Schubert 	TEAP_TLV_NAK = 4,
134*206b73d0SCy Schubert 	TEAP_TLV_ERROR = 5,
135*206b73d0SCy Schubert 	TEAP_TLV_CHANNEL_BINDING = 6,
136*206b73d0SCy Schubert 	TEAP_TLV_VENDOR_SPECIFIC = 7,
137*206b73d0SCy Schubert 	TEAP_TLV_REQUEST_ACTION = 8,
138*206b73d0SCy Schubert 	TEAP_TLV_EAP_PAYLOAD = 9,
139*206b73d0SCy Schubert 	TEAP_TLV_INTERMEDIATE_RESULT = 10,
140*206b73d0SCy Schubert 	TEAP_TLV_PAC = 11,
141*206b73d0SCy Schubert 	TEAP_TLV_CRYPTO_BINDING = 12,
142*206b73d0SCy Schubert 	TEAP_TLV_BASIC_PASSWORD_AUTH_REQ = 13,
143*206b73d0SCy Schubert 	TEAP_TLV_BASIC_PASSWORD_AUTH_RESP = 14,
144*206b73d0SCy Schubert 	TEAP_TLV_PKCS7 = 15,
145*206b73d0SCy Schubert 	TEAP_TLV_PKCS10 = 16,
146*206b73d0SCy Schubert 	TEAP_TLV_TRUSTED_SERVER_ROOT = 17,
147*206b73d0SCy Schubert };
148*206b73d0SCy Schubert 
149*206b73d0SCy Schubert enum teap_tlv_result_status {
150*206b73d0SCy Schubert 	TEAP_STATUS_SUCCESS = 1,
151*206b73d0SCy Schubert 	TEAP_STATUS_FAILURE = 2
152*206b73d0SCy Schubert };
153*206b73d0SCy Schubert 
154*206b73d0SCy Schubert #define TEAP_TLV_MANDATORY 0x8000
155*206b73d0SCy Schubert #define TEAP_TLV_TYPE_MASK 0x3fff
156*206b73d0SCy Schubert 
157*206b73d0SCy Schubert /* RFC 7170, 4.2.6: Error TLV */
158*206b73d0SCy Schubert enum teap_error_codes {
159*206b73d0SCy Schubert 	TEAP_ERROR_INNER_METHOD = 1001,
160*206b73d0SCy Schubert 	TEAP_ERROR_UNSPEC_AUTH_INFRA_PROBLEM = 1002,
161*206b73d0SCy Schubert 	TEAP_ERROR_UNSPEC_AUTHENTICATION_FAILURE = 1003,
162*206b73d0SCy Schubert 	TEAP_ERROR_UNSPEC_AUTHORIZATION_FAILURE = 1004,
163*206b73d0SCy Schubert 	TEAP_ERROR_USER_ACCOUNT_CRED_UNAVAILABLE = 1005,
164*206b73d0SCy Schubert 	TEAP_ERROR_USER_ACCOUNT_EXPIRED = 1006,
165*206b73d0SCy Schubert 	TEAP_ERROR_USER_ACCOUNT_LOCKED_TRY_AGAIN_LATER = 1007,
166*206b73d0SCy Schubert 	TEAP_ERROR_USER_ACCOUNT_LOCKED_ADMIN_REQ = 1008,
167*206b73d0SCy Schubert 	TEAP_ERROR_TUNNEL_COMPROMISE_ERROR = 2001,
168*206b73d0SCy Schubert 	TEAP_ERROR_UNEXPECTED_TLVS_EXCHANGED = 2002,
169*206b73d0SCy Schubert };
170*206b73d0SCy Schubert 
171*206b73d0SCy Schubert struct wpabuf;
172*206b73d0SCy Schubert struct tls_connection;
173*206b73d0SCy Schubert 
174*206b73d0SCy Schubert struct eap_teap_tlv_parse {
175*206b73d0SCy Schubert 	u8 *eap_payload_tlv;
176*206b73d0SCy Schubert 	size_t eap_payload_tlv_len;
177*206b73d0SCy Schubert 	struct teap_tlv_crypto_binding *crypto_binding;
178*206b73d0SCy Schubert 	size_t crypto_binding_len;
179*206b73d0SCy Schubert 	int iresult;
180*206b73d0SCy Schubert 	int result;
181*206b73d0SCy Schubert 	u8 *nak;
182*206b73d0SCy Schubert 	size_t nak_len;
183*206b73d0SCy Schubert 	u8 request_action;
184*206b73d0SCy Schubert 	u8 request_action_status;
185*206b73d0SCy Schubert 	u8 *pac;
186*206b73d0SCy Schubert 	size_t pac_len;
187*206b73d0SCy Schubert 	u8 *basic_auth_req;
188*206b73d0SCy Schubert 	size_t basic_auth_req_len;
189*206b73d0SCy Schubert 	u8 *basic_auth_resp;
190*206b73d0SCy Schubert 	size_t basic_auth_resp_len;
191*206b73d0SCy Schubert };
192*206b73d0SCy Schubert 
193*206b73d0SCy Schubert void eap_teap_put_tlv_hdr(struct wpabuf *buf, u16 type, u16 len);
194*206b73d0SCy Schubert void eap_teap_put_tlv(struct wpabuf *buf, u16 type, const void *data, u16 len);
195*206b73d0SCy Schubert void eap_teap_put_tlv_buf(struct wpabuf *buf, u16 type,
196*206b73d0SCy Schubert 			  const struct wpabuf *data);
197*206b73d0SCy Schubert struct wpabuf * eap_teap_tlv_eap_payload(struct wpabuf *buf);
198*206b73d0SCy Schubert int eap_teap_derive_eap_msk(const u8 *simck, u8 *msk);
199*206b73d0SCy Schubert int eap_teap_derive_eap_emsk(const u8 *simck, u8 *emsk);
200*206b73d0SCy Schubert int eap_teap_derive_cmk_basic_pw_auth(const u8 *s_imck_msk, u8 *cmk);
201*206b73d0SCy Schubert int eap_teap_derive_imck(const u8 *prev_s_imck_msk, const u8 *prev_s_imck_emsk,
202*206b73d0SCy Schubert 			 const u8 *msk, size_t msk_len,
203*206b73d0SCy Schubert 			 const u8 *emsk, size_t emsk_len,
204*206b73d0SCy Schubert 			 u8 *s_imck_msk, u8 *cmk_msk,
205*206b73d0SCy Schubert 			 u8 *s_imck_emsk, u8 *cmk_emsk);
206*206b73d0SCy Schubert int eap_teap_compound_mac(u16 tls_cs, const struct teap_tlv_crypto_binding *cb,
207*206b73d0SCy Schubert 			  const struct wpabuf *server_outer_tlvs,
208*206b73d0SCy Schubert 			  const struct wpabuf *peer_outer_tlvs,
209*206b73d0SCy Schubert 			  const u8 *cmk, u8 *compound_mac);
210*206b73d0SCy Schubert int eap_teap_parse_tlv(struct eap_teap_tlv_parse *tlv,
211*206b73d0SCy Schubert 		       int tlv_type, u8 *pos, size_t len);
212*206b73d0SCy Schubert const char * eap_teap_tlv_type_str(enum teap_tlv_types type);
213*206b73d0SCy Schubert struct wpabuf * eap_teap_tlv_result(int status, int intermediate);
214*206b73d0SCy Schubert struct wpabuf * eap_teap_tlv_error(enum teap_error_codes error);
215*206b73d0SCy Schubert int eap_teap_allowed_anon_prov_phase2_method(u8 type);
216*206b73d0SCy Schubert int eap_teap_allowed_anon_prov_cipher_suite(u16 cs);
217*206b73d0SCy Schubert 
218*206b73d0SCy Schubert #endif /* EAP_TEAP_H */
219