FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
ikev2_priv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __included_ikev2_priv_h__
16 #define __included_ikev2_priv_h__
17 
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/ethernet/ethernet.h>
21 
22 #include <plugins/ikev2/ikev2.h>
23 
24 #include <vppinfra/hash.h>
25 #include <vppinfra/elog.h>
26 #include <vppinfra/error.h>
27 
28 #include <openssl/rand.h>
29 #include <openssl/dh.h>
30 #include <openssl/hmac.h>
31 #include <openssl/evp.h>
32 
33 #define IKEV2_DEBUG_PAYLOAD 1
34 
35 #if IKEV2_DEBUG_PAYLOAD == 1
36 #define DBG_PLD(my_args...) clib_warning(my_args)
37 #else
38 #define DBG_PLD(my_args...)
39 #endif
40 
41 typedef enum
42 {
52 
53 typedef struct
54 {
56  u8 *data;
57  u8 hex; /* hex encoding of the shared secret */
58  EVP_PKEY *key;
59 } ikev2_auth_t;
60 
61 typedef enum
62 {
66 
67 typedef struct
68 {
70  union
71  {
78  };
84  int nid;
85  const char *dh_p;
86  const char *dh_g;
87  const void *md;
88  const void *cipher;
90 
91 typedef struct
92 {
98 
99 typedef struct
100 {
108 } ikev2_ts_t;
109 
110 typedef struct
111 {
115 
116 typedef struct
117 {
123 
124 
125 typedef struct
126 {
129 } ikev2_id_t;
130 
131 typedef struct
132 {
133  /* sa proposals vectors */
136 
137  /* Traffic Selectors */
140 
141  /* keys */
148 
149  /* installed data */
152 
153  /* lifetime data */
158 
159 typedef struct
160 {
162  u32 spi; /*for ESP and AH SPI size is 4, for IKE size is 0 */
164 
165 typedef struct
166 {
174 } ikev2_rekey_t;
175 
176 typedef struct
177 {
183 
184 typedef struct
185 {
188 
202 
203 typedef struct
204 {
214 
215  /* DH data */
221 
222  /* sa proposals vectors */
225 
226  /* keys */
234 
235  /* auth */
238 
239  /* ID */
242 
243  /* pending deletes */
245 
246  /* pending rekeyings */
248 
249  /* packet data */
252 
253  /* retransmit */
256 
261 
263 } ikev2_sa_t;
264 
265 
266 typedef struct
267 {
268  /* pool of IKEv2 Security Associations */
270 
271  /* hash */
274 
275 typedef struct
276 {
277  /* pool of IKEv2 profiles */
279 
280  /* vector of supported transform types */
282 
283  /* hash */
285 
286  /* local private key */
287  EVP_PKEY *pkey;
288 
289  /* convenience */
292 
293  /* pool of IKEv2 Security Associations created in initiator mode */
295  /* hash */
297 
299 
300  /* interface indices managed by IKE */
302 
303  /* API message ID base */
305 } ikev2_main_t;
306 
307 extern ikev2_main_t ikev2_main;
308 
312 
313 /* ikev2_crypto.c */
316  int len);
318  int len);
319 v8 *ikev2_decrypt_data (ikev2_sa_t * sa, u8 * data, int len);
320 int ikev2_encrypt_data (ikev2_sa_t * sa, v8 * src, u8 * dst);
323 int ikev2_verify_sign (EVP_PKEY * pkey, u8 * sigbuf, u8 * data);
324 u8 *ikev2_calc_sign (EVP_PKEY * pkey, u8 * data);
325 EVP_PKEY *ikev2_load_cert_file (u8 * file);
326 EVP_PKEY *ikev2_load_key_file (u8 * file);
327 void ikev2_crypto_init (ikev2_main_t * km);
328 
329 /* ikev2_payload.c */
330 typedef struct
331 {
336 
337 #define ikev2_payload_new_chain(V) vec_validate (V, 0)
338 #define ikev2_payload_destroy_chain(V) do { \
339  vec_free((V)->data); \
340  vec_free(V); \
341 } while (0)
342 
344  u8 * data);
346  u8 * data, ikev2_notify_t * notify);
348  ikev2_sa_proposal_t * proposals);
350  u8 * dh_data);
353  u8 type);
356  u8 type);
359 void ikev2_parse_vendor_payload (ike_payload_header_t * ikep);
360 ikev2_sa_proposal_t *ikev2_parse_sa_payload (ike_payload_header_t * ikep);
361 ikev2_ts_t *ikev2_parse_ts_payload (ike_payload_header_t * ikep);
362 ikev2_delete_t *ikev2_parse_delete_payload (ike_payload_header_t * ikep);
363 ikev2_notify_t *ikev2_parse_notify_payload (ike_payload_header_t * ikep);
364 
365 #endif /* __included_ikev2_priv_h__ */
366 
367 
368 /*
369  * fd.io coding-style-patch-verification: ON
370  *
371  * Local Variables:
372  * eval: (c-set-style "gnu")
373  * End:
374  */
ikev2_main_per_thread_data_t * per_thread_data
Definition: ikev2_priv.h:298
u8 * dh_shared_key
Definition: ikev2_priv.h:217
ikev2_sa_t * sais
Definition: ikev2_priv.h:294
Definition: mhash.h:46
u8 * dh_private_key
Definition: ikev2_priv.h:218
ikev2_transform_type_t type
Definition: ikev2_priv.h:69
void ikev2_payload_add_sa(ikev2_payload_chain_t *c, ikev2_sa_proposal_t *proposals)
ikev2_id_t r_id
Definition: ikev2_priv.h:241
ikev2_id_type_t type
Definition: ikev2_priv.h:127
ikev2_transforms_set ike_ts
Definition: ikev2_priv.h:195
void ikev2_payload_add_notify(ikev2_payload_chain_t *c, u16 msg_type, u8 *data)
ikev2_transform_integ_type_t
Definition: ikev2.h:268
EVP_PKEY * pkey
Definition: ikev2_priv.h:287
u8 * ikev2_calc_prfplus(ikev2_sa_transform_t *tr, u8 *key, u8 *seed, int len)
Definition: ikev2_crypto.c:287
ikev2_auth_method_t
Definition: ikev2.h:340
u32 last_init_msg_id
Definition: ikev2_priv.h:258
ikev2_sa_transform_t * ikev2_sa_get_td_for_type(ikev2_sa_proposal_t *p, ikev2_transform_type_t type)
Definition: ikev2.c:197
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:120
ikev2_profile_t * profiles
Definition: ikev2_priv.h:278
unsigned long u64
Definition: types.h:89
u8 v8
Definition: ikev2.h:27
ikev2_transform_esn_type_t esn_type
Definition: ikev2_priv.h:77
ikev2_state_t state
Definition: ikev2_priv.h:205
vl_api_address_t src
Definition: gre.api:60
ikev2_transform_encr_type_t crypto_alg
Definition: ikev2_priv.h:118
u8 * sk_pi
Definition: ikev2_priv.h:232
ikev2_main_t ikev2_main
Definition: ikev2.c:32
ip4_address_t ip4
Definition: ikev2_priv.h:113
u8 initial_contact
Definition: ikev2_priv.h:207
ikev2_ts_t * tsi
Definition: ikev2_priv.h:172
void ikev2_payload_add_id(ikev2_payload_chain_t *c, ikev2_id_t *id, u8 type)
ikev2_auth_t r_auth
Definition: ikev2_priv.h:237
u8 * last_sa_init_res_packet_data
Definition: ikev2_priv.h:251
unsigned char u8
Definition: types.h:56
ikev2_auth_t auth
Definition: ikev2_priv.h:189
double f64
Definition: types.h:142
ikev2_ts_t * tsr
Definition: ikev2_priv.h:173
ikev2_ts_t * ikev2_parse_ts_payload(ike_payload_header_t *ikep)
ikev2_id_t rem_id
Definition: ikev2_priv.h:191
ikev2_transform_dh_type_t
Definition: ikev2.h:318
EVP_PKEY * ikev2_load_cert_file(u8 *file)
Definition: ikev2_crypto.c:766
void ikev2_payload_add_ts(ikev2_payload_chain_t *c, ikev2_ts_t *ts, u8 type)
u32 last_msg_id
Definition: ikev2_priv.h:254
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:135
ip4_address_t start_addr
Definition: ikev2_priv.h:106
u16 selector_len
Definition: ikev2_priv.h:103
EVP_PKEY * ikev2_load_key_file(u8 *file)
Definition: ikev2_crypto.c:796
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:223
uword * sw_if_indices
Definition: ikev2_priv.h:301
int ikev2_verify_sign(EVP_PKEY *pkey, u8 *sigbuf, u8 *data)
Definition: ikev2_crypto.c:703
ikev2_transform_integ_type_t integ_alg
Definition: ikev2_priv.h:119
unsigned int u32
Definition: types.h:88
ikev2_auth_t i_auth
Definition: ikev2_priv.h:236
ikev2_id_t loc_id
Definition: ikev2_priv.h:190
ikev2_sa_transform_t * transforms
Definition: ikev2_priv.h:96
u8 * sk_ar
Definition: ikev2_priv.h:229
u8 * r_dh_data
Definition: ikev2_priv.h:220
ikev2_responder_t responder
Definition: ikev2_priv.h:194
vl_api_fib_path_type_t type
Definition: fib_types.api:123
u8 * last_sa_init_req_packet_data
Definition: ikev2_priv.h:250
ikev2_ts_t rem_ts
Definition: ikev2_priv.h:193
u8 * i_dh_data
Definition: ikev2_priv.h:219
unsigned short u16
Definition: types.h:57
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:134
u8 * r_nonce
Definition: ikev2_priv.h:213
mhash_t profile_index_by_name
Definition: ikev2_priv.h:284
u16 end_port
Definition: ikev2_priv.h:105
ikev2_sa_transform_t * supported_transforms
Definition: ikev2_priv.h:281
ikev2_rekey_t * rekey
Definition: ikev2_priv.h:247
void ikev2_payload_chain_add_padding(ikev2_payload_chain_t *c, int bs)
signed char i8
Definition: types.h:45
ikev2_protocol_id_t
Definition: ikev2.h:107
vl_api_address_t dst
Definition: gre.api:61
ip4_address_t end_addr
Definition: ikev2_priv.h:107
ip4_address_t iaddr
Definition: ikev2_priv.h:208
u8 * ikev2_calc_sign(EVP_PKEY *pkey, u8 *data)
Definition: ikev2_crypto.c:732
v8 * ikev2_calc_prf(ikev2_sa_transform_t *tr, v8 *key, v8 *data)
Definition: ikev2_crypto.c:257
u8 * i_nonce
Definition: ikev2_priv.h:212
u8 len
Definition: ip_types.api:91
u8 * sk_ei
Definition: ikev2_priv.h:230
ikev2_delete_t * ikev2_parse_delete_payload(ike_payload_header_t *ikep)
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:76
svmdb_client_t * c
ikev2_sa_proposal_t * ikev2_parse_sa_payload(ike_payload_header_t *ikep)
ikev2_auth_method_t method
Definition: ikev2_priv.h:55
ikev2_transform_encr_type_t
Definition: ikev2.h:227
ikev2_delete_t * del
Definition: ikev2_priv.h:244
ikev2_ts_t * tsi
Definition: ikev2_priv.h:138
v8 * ikev2_decrypt_data(ikev2_sa_t *sa, u8 *data, int len)
Definition: ikev2_crypto.c:373
void ikev2_payload_add_nonce(ikev2_payload_chain_t *c, u8 *nonce)
ip4_address_t raddr
Definition: ikev2_priv.h:209
u8 * sk_er
Definition: ikev2_priv.h:231
u8 is_initiator
Definition: ikev2_priv.h:257
const void * cipher
Definition: ikev2_priv.h:88
ikev2_ts_t loc_ts
Definition: ikev2_priv.h:192
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:224
ikev2_protocol_id_t protocol_id
Definition: ikev2_priv.h:94
u8 protocol_id
Definition: ikev2_priv.h:102
vnet_main_t * vnet_main
Definition: ikev2_priv.h:291
ikev2_id_type_t
Definition: ikev2.h:356
ikev2_notify_t * ikev2_parse_notify_payload(ike_payload_header_t *ikep)
u8 data[128]
Definition: ipsec_types.api:87
void ikev2_complete_dh(ikev2_sa_t *sa, ikev2_sa_transform_t *t)
Definition: ikev2_crypto.c:603
ikev2_transform_esn_type_t
Definition: ikev2.h:329
ikev2_sa_proposal_t * r_proposal
Definition: ikev2_priv.h:171
u8 * sk_ai
Definition: ikev2_priv.h:228
v8 * ikev2_calc_integr(ikev2_sa_transform_t *tr, v8 *key, u8 *data, int len)
Definition: ikev2_crypto.c:329
u16 dh_group
Definition: ikev2_priv.h:216
ikev2_sa_proposal_t * i_proposal
Definition: ikev2_priv.h:170
const char * dh_p
Definition: ikev2_priv.h:85
EVP_PKEY * key
Definition: ikev2_priv.h:58
ikev2_dh_group_t
Definition: ikev2_priv.h:61
const void * md
Definition: ikev2_priv.h:87
void ikev2_crypto_init(ikev2_main_t *km)
Definition: ikev2_crypto.c:818
typedef key
Definition: ipsec_types.api:83
ikev2_transform_encr_type_t encr_type
Definition: ikev2_priv.h:73
u8 * last_res_packet_data
Definition: ikev2_priv.h:255
const char * dh_g
Definition: ikev2_priv.h:86
ikev2_transform_integ_type_t integ_type
Definition: ikev2_priv.h:75
void ikev2_payload_add_auth(ikev2_payload_chain_t *c, ikev2_auth_t *auth)
u16 start_port
Definition: ikev2_priv.h:104
void ikev2_payload_add_ke(ikev2_payload_chain_t *c, u16 dh_group, u8 *dh_data)
u8 * sk_pr
Definition: ikev2_priv.h:233
u64 uword
Definition: types.h:112
ikev2_id_t i_id
Definition: ikev2_priv.h:240
ikev2_ts_t * tsr
Definition: ikev2_priv.h:139
void ikev2_payload_add_notify_2(ikev2_payload_chain_t *c, u16 msg_type, u8 *data, ikev2_notify_t *notify)
ikev2_child_sa_t * childs
Definition: ikev2_priv.h:262
ikev2_transform_prf_type_t prf_type
Definition: ikev2_priv.h:74
void ikev2_parse_vendor_payload(ike_payload_header_t *ikep)
int ikev2_encrypt_data(ikev2_sa_t *sa, v8 *src, u8 *dst)
Definition: ikev2_crypto.c:425
void ikev2_payload_add_delete(ikev2_payload_chain_t *c, ikev2_delete_t *d)
ikev2_transform_prf_type_t
Definition: ikev2.h:244
uword * sa_by_ispi
Definition: ikev2_priv.h:296
u8 unsupported_cp
Definition: ikev2_priv.h:206
u8 is_profile_index_set
Definition: ikev2_priv.h:259
void ikev2_sa_free_proposal_vector(ikev2_sa_proposal_t **v)
Definition: ikev2.c:230
u32 profile_index
Definition: ikev2_priv.h:260
ikev2_transform_type_t
Definition: ikev2.h:203
ikev2_transforms_set esp_ts
Definition: ikev2_priv.h:196
void ikev2_generate_dh(ikev2_sa_t *sa, ikev2_sa_transform_t *t)
Definition: ikev2_crypto.c:462
vlib_main_t * vlib_main
Definition: ikev2_priv.h:290
ikev2_state_t
Definition: ikev2_priv.h:41