wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ikev2_common.h
Go to the documentation of this file.
1 
5 #ifndef IKEV2_COMMON_H
6 #define IKEV2_COMMON_H
7 
8 /*
9  * Nonce length must be at least 16 octets. It must also be at least half the
10  * key size of the negotiated PRF.
11  */
12 #define IKEV2_NONCE_MIN_LEN 16
13 #define IKEV2_NONCE_MAX_LEN 256
14 
15 /* IKE Header - RFC 4306, Sect. 3.1 */
16 #ifdef _MSC_VER
17 #pragma pack(push, 1)
18 #endif /* _MSC_VER */
19 
20 #define IKEV2_SPI_LEN 8
21 
22 struct ikev2_hdr {
23  u8 i_spi[IKEV2_SPI_LEN]; /* IKE_SA Initiator's SPI */
24  u8 r_spi[IKEV2_SPI_LEN]; /* IKE_SA Responder's SPI */
25  u8 next_payload;
26  u8 version; /* MjVer | MnVer */
27  u8 exchange_type;
28  u8 flags;
29  u8 message_id[4];
30  u8 length[4]; /* total length of HDR + payloads */
31 } STRUCT_PACKED;
32 
34  u8 next_payload;
35  u8 flags;
36  u8 payload_length[2]; /* this payload, including the payload header */
37 } STRUCT_PACKED;
38 
40  u8 type; /* 0 (last) or 2 (more) */
41  u8 reserved;
42  u8 proposal_length[2]; /* including all transform and attributes */
43  u8 proposal_num;
44  u8 protocol_id; /* IKEV2_PROTOCOL_* */
45  u8 spi_size;
46  u8 num_transforms;
47  /* SPI of spi_size octets */
48  /* Transforms */
49 } STRUCT_PACKED;
50 
52  u8 type; /* 0 (last) or 3 (more) */
53  u8 reserved;
54  u8 transform_length[2]; /* including Header and Attributes */
55  u8 transform_type;
56  u8 reserved2;
57  u8 transform_id[2];
58  /* Transform Attributes */
59 } STRUCT_PACKED;
60 
61 #ifdef _MSC_VER
62 #pragma pack(pop)
63 #endif /* _MSC_VER */
64 
65 
66 /* Current IKEv2 version from RFC 4306 */
67 #define IKEV2_MjVer 2
68 #define IKEV2_MnVer 0
69 #define IKEV2_VERSION (((IKEV2_MjVer) << 4) | (IKEV2_MnVer))
70 
71 /* IKEv2 Exchange Types */
72 enum {
73  /* 0-33 RESERVED */
74  IKE_SA_INIT = 34,
75  IKE_SA_AUTH = 35,
76  CREATE_CHILD_SA = 36,
77  INFORMATION = 37
78  /* 38-239 RESERVED TO IANA */
79  /* 240-255 Reserved for private use */
80 };
81 
82 /* IKEv2 Flags */
83 #define IKEV2_HDR_INITIATOR 0x08
84 #define IKEV2_HDR_VERSION 0x10
85 #define IKEV2_HDR_RESPONSE 0x20
86 
87 /* Payload Header Flags */
88 #define IKEV2_PAYLOAD_FLAGS_CRITICAL 0x01
89 
90 
91 /* EAP-IKEv2 Payload Types (in Next Payload Type field)
92  * http://www.iana.org/assignments/eap-ikev2-payloads */
93 enum {
94  IKEV2_PAYLOAD_NO_NEXT_PAYLOAD = 0,
95  IKEV2_PAYLOAD_SA = 33,
96  IKEV2_PAYLOAD_KEY_EXCHANGE = 34,
97  IKEV2_PAYLOAD_IDi = 35,
98  IKEV2_PAYLOAD_IDr = 36,
99  IKEV2_PAYLOAD_CERTIFICATE = 37,
100  IKEV2_PAYLOAD_CERT_REQ = 38,
101  IKEV2_PAYLOAD_AUTHENTICATION = 39,
102  IKEV2_PAYLOAD_NONCE = 40,
103  IKEV2_PAYLOAD_NOTIFICATION = 41,
104  IKEV2_PAYLOAD_VENDOD_ID = 43,
105  IKEV2_PAYLOAD_ENCRYPTED = 46,
106  IKEV2_PAYLOAD_NEXT_FAST_ID = 121
107 };
108 
109 
110 /* IKEv2 Proposal - Protocol ID */
111 enum {
112  IKEV2_PROTOCOL_RESERVED = 0,
113  IKEV2_PROTOCOL_IKE = 1, /* IKE is the only one allowed for EAP-IKEv2 */
114  IKEV2_PROTOCOL_AH = 2,
115  IKEV2_PROTOCOL_ESP = 3
116 };
117 
118 
119 /* IKEv2 Transform Types */
120 enum {
121  IKEV2_TRANSFORM_ENCR = 1,
122  IKEV2_TRANSFORM_PRF = 2,
123  IKEV2_TRANSFORM_INTEG = 3,
124  IKEV2_TRANSFORM_DH = 4,
125  IKEV2_TRANSFORM_ESN = 5
126 };
127 
128 /* IKEv2 Transform Type 1 (Encryption Algorithm) */
129 enum {
130  ENCR_DES_IV64 = 1,
131  ENCR_DES = 2,
132  ENCR_3DES = 3,
133  ENCR_RC5 = 4,
134  ENCR_IDEA = 5,
135  ENCR_CAST = 6,
136  ENCR_BLOWFISH = 7,
137  ENCR_3IDEA = 8,
138  ENCR_DES_IV32 = 9,
139  ENCR_NULL = 11,
140  ENCR_AES_CBC = 12,
141  ENCR_AES_CTR = 13
142 };
143 
144 /* IKEv2 Transform Type 2 (Pseudo-random Function) */
145 enum {
146  PRF_HMAC_MD5 = 1,
147  PRF_HMAC_SHA1 = 2,
148  PRF_HMAC_TIGER = 3,
149  PRF_AES128_XCBC = 4
150 };
151 
152 /* IKEv2 Transform Type 3 (Integrity Algorithm) */
153 enum {
154  AUTH_HMAC_MD5_96 = 1,
155  AUTH_HMAC_SHA1_96 = 2,
156  AUTH_DES_MAC = 3,
157  AUTH_KPDK_MD5 = 4,
158  AUTH_AES_XCBC_96 = 5
159 };
160 
161 /* IKEv2 Transform Type 4 (Diffie-Hellman Group) */
162 enum {
163  DH_GROUP1_768BIT_MODP = 1, /* RFC 4306 */
164  DH_GROUP2_1024BIT_MODP = 2, /* RFC 4306 */
165  DH_GROUP5_1536BIT_MODP = 5, /* RFC 3526 */
166  DH_GROUP5_2048BIT_MODP = 14, /* RFC 3526 */
167  DH_GROUP5_3072BIT_MODP = 15, /* RFC 3526 */
168  DH_GROUP5_4096BIT_MODP = 16, /* RFC 3526 */
169  DH_GROUP5_6144BIT_MODP = 17, /* RFC 3526 */
170  DH_GROUP5_8192BIT_MODP = 18 /* RFC 3526 */
171 };
172 
173 
174 /* Identification Data Types (RFC 4306, Sect. 3.5) */
175 enum {
176  ID_IPV4_ADDR = 1,
177  ID_FQDN = 2,
178  ID_RFC822_ADDR = 3,
179  ID_IPV6_ADDR = 5,
180  ID_DER_ASN1_DN = 9,
181  ID_DER_ASN1_GN= 10,
182  ID_KEY_ID = 11
183 };
184 
185 
186 /* Certificate Encoding (RFC 4306, Sect. 3.6) */
187 enum {
188  CERT_ENCODING_PKCS7_X509 = 1,
189  CERT_ENCODING_PGP_CERT = 2,
190  CERT_ENCODING_DNS_SIGNED_KEY = 3,
191  /* X.509 Certificate - Signature: DER encoded X.509 certificate whose
192  * public key is used to validate the sender's AUTH payload */
193  CERT_ENCODING_X509_CERT_SIGN = 4,
194  CERT_ENCODING_KERBEROS_TOKEN = 6,
195  /* DER encoded X.509 certificate revocation list */
196  CERT_ENCODING_CRL = 7,
197  CERT_ENCODING_ARL = 8,
198  CERT_ENCODING_SPKI_CERT = 9,
199  CERT_ENCODING_X509_CERT_ATTR = 10,
200  /* PKCS #1 encoded RSA key */
201  CERT_ENCODING_RAW_RSA_KEY = 11,
202  CERT_ENCODING_HASH_AND_URL_X509_CERT = 12,
203  CERT_ENCODING_HASH_AND_URL_X509_BUNDLE = 13
204 };
205 
206 
207 /* Authentication Method (RFC 4306, Sect. 3.8) */
208 enum {
209  AUTH_RSA_SIGN = 1,
210  AUTH_SHARED_KEY_MIC = 2,
211  AUTH_DSS_SIGN = 3
212 };
213 
214 
215 /* Notify Message Types (RFC 4306, Sect. 3.10.1) */
216 enum {
217  UNSUPPORTED_CRITICAL_PAYLOAD = 1,
218  INVALID_IKE_SPI = 4,
219  INVALID_MAJOR_VERSION = 5,
220  INVALID_SYNTAX = 7,
221  INVALID_MESSAGE_ID = 9,
222  INVALID_SPI = 11,
223  NO_PROPOSAL_CHOSEN = 14,
224  INVALID_KE_PAYLOAD = 17,
225  AUTHENTICATION_FAILED = 24,
226  SINGLE_PAIR_REQUIRED = 34,
227  NO_ADDITIONAL_SAS = 35,
228  INTERNAL_ADDRESS_FAILURE = 36,
229  FAILED_CP_REQUIRED = 37,
230  TS_UNACCEPTABLE = 38,
231  INVALID_SELECTORS = 39
232 };
233 
234 
235 struct ikev2_keys {
236  u8 *SK_d, *SK_ai, *SK_ar, *SK_ei, *SK_er, *SK_pi, *SK_pr;
237  size_t SK_d_len, SK_integ_len, SK_encr_len, SK_prf_len;
238 };
239 
240 
241 int ikev2_keys_set(struct ikev2_keys *keys);
242 void ikev2_free_keys(struct ikev2_keys *keys);
243 
244 
245 /* Maximum hash length for supported hash algorithms */
246 #define IKEV2_MAX_HASH_LEN 20
247 
249  int id;
250  size_t key_len;
251  size_t hash_len;
252 };
253 
255  int id;
256  size_t key_len;
257  size_t hash_len;
258 };
259 
261  int id;
262  size_t key_len;
263  size_t block_size;
264 };
265 
266 const struct ikev2_integ_alg * ikev2_get_integ(int id);
267 int ikev2_integ_hash(int alg, const u8 *key, size_t key_len, const u8 *data,
268  size_t data_len, u8 *hash);
269 const struct ikev2_prf_alg * ikev2_get_prf(int id);
270 int ikev2_prf_hash(int alg, const u8 *key, size_t key_len,
271  size_t num_elem, const u8 *addr[], const size_t *len,
272  u8 *hash);
273 int ikev2_prf_plus(int alg, const u8 *key, size_t key_len,
274  const u8 *data, size_t data_len,
275  u8 *out, size_t out_len);
276 const struct ikev2_encr_alg * ikev2_get_encr(int id);
277 int ikev2_encr_encrypt(int alg, const u8 *key, size_t key_len, const u8 *iv,
278  const u8 *plain, u8 *crypt, size_t len);
279 int ikev2_encr_decrypt(int alg, const u8 *key, size_t key_len, const u8 *iv,
280  const u8 *crypt, u8 *plain, size_t len);
281 
282 int ikev2_derive_auth_data(int prf_alg, const struct wpabuf *sign_msg,
283  const u8 *ID, size_t ID_len, u8 ID_type,
284  struct ikev2_keys *keys, int initiator,
285  const u8 *shared_secret, size_t shared_secret_len,
286  const u8 *nonce, size_t nonce_len,
287  const u8 *key_pad, size_t key_pad_len,
288  u8 *auth_data);
289 
290 
292  const u8 *sa;
293  size_t sa_len;
294  const u8 *ke;
295  size_t ke_len;
296  const u8 *idi;
297  size_t idi_len;
298  const u8 *idr;
299  size_t idr_len;
300  const u8 *cert;
301  size_t cert_len;
302  const u8 *auth;
303  size_t auth_len;
304  const u8 *nonce;
305  size_t nonce_len;
306  const u8 *encrypted;
307  size_t encrypted_len;
308  u8 encr_next_payload;
309  const u8 *notification;
310  size_t notification_len;
311 };
312 
313 int ikev2_parse_payloads(struct ikev2_payloads *payloads,
314  u8 next_payload, const u8 *pos, const u8 *end);
315 
316 u8 * ikev2_decrypt_payload(int encr_id, int integ_id, struct ikev2_keys *keys,
317  int initiator, const struct ikev2_hdr *hdr,
318  const u8 *encrypted, size_t encrypted_len,
319  size_t *res_len);
320 void ikev2_update_hdr(struct wpabuf *msg);
321 int ikev2_build_encrypted(int encr_id, int integ_id, struct ikev2_keys *keys,
322  int initiator, struct wpabuf *msg,
323  struct wpabuf *plain, u8 next_payload);
324 int ikev2_derive_sk_keys(const struct ikev2_prf_alg *prf,
325  const struct ikev2_integ_alg *integ,
326  const struct ikev2_encr_alg *encr,
327  const u8 *skeyseed, const u8 *data, size_t data_len,
328  struct ikev2_keys *keys);
329 
330 #endif /* IKEV2_COMMON_H */
Definition: ikev2_common.h:51
Definition: ikev2_common.h:260
Definition: wpabuf.h:16
Definition: ikev2_common.h:235
Definition: ikev2_common.h:291
Definition: ikev2_common.h:248
Definition: ikev2_common.h:33
Definition: ikev2_common.h:22
Definition: ikev2_common.h:39
Definition: ikev2_common.h:254