FD.io VPP  v16.06
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 <vnet/ipsec/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 {
51 
52 typedef struct {
54  u8 * data;
55  u8 hex; /* hex encoding of the shared secret */
56  EVP_PKEY * key;
57 } ikev2_auth_t;
58 
59 typedef enum {
63 
64 typedef struct {
66  union {
73  };
74  u8 * attrs;
79  int nid;
80  const char * dh_p;
81  const char * dh_g;
82  const void * md;
83  const void * cipher;
85 
86 typedef struct {
88  ikev2_protocol_id_t protocol_id:8;
92 
93 typedef struct {
101 } ikev2_ts_t;
102 
103 typedef struct {
105  u8 * data;
106 } ikev2_id_t;
107 
108 typedef struct {
109  /* sa proposals vectors */
112 
113  /* Traffic Selectors */
116 
117  /* keys */
123 
124 typedef struct {
126  u32 spi; /*for ESP and AH SPI size is 4, for IKE size is 0 */
128 
129 typedef struct {
136 } ikev2_rekey_t;
137 
138 typedef struct {
142  u8 * data;
144 
145 
146 typedef struct {
156 
157  /* DH data */
162 
163  /* sa proposals vectors */
166 
167  /* keys */
168  u8 * sk_d;
175 
176  /* auth */
179 
180  /* ID */
183 
184  /* pending deletes */
186 
187  /* pending rekeyings */
189 
190  /* packet data */
193 
194  /* retransmit */
197 
199 } ikev2_sa_t;
200 
201 typedef struct {
202  u8 * name;
204 
211 
212 typedef struct {
213  /* pool of IKEv2 Security Associations */
215 
216  /* pool of IKEv2 profiles */
218 
219  /* vector of supported transform types */
221 
222  /* hashes */
225 
226  /* local private key */
227  EVP_PKEY * pkey;
228 
229  /* convenience */
232 } ikev2_main_t;
233 
235 
239 
240 /* ikev2_crypto.c */
241 v8 * ikev2_calc_prf(ikev2_sa_transform_t * tr, v8 * key, v8 * data);
242 u8 * ikev2_calc_prfplus(ikev2_sa_transform_t * tr, u8 * key, u8 * seed, int len);
243 v8 * ikev2_calc_integr(ikev2_sa_transform_t * tr, v8 * key, u8 * data, int len);
244 v8 * ikev2_decrypt_data(ikev2_sa_t * sa, u8 * data, int len);
245 int ikev2_encrypt_data(ikev2_sa_t * sa, v8 * src, u8 * dst);
247 int ikev2_verify_sign(EVP_PKEY *pkey, u8 * sigbuf, u8 * data);
248 u8 * ikev2_calc_sign(EVP_PKEY *pkey, u8 * data);
249 EVP_PKEY * ikev2_load_cert_file(u8 * file);
250 EVP_PKEY * ikev2_load_key_file(u8 * file);
251 void ikev2_crypto_init (ikev2_main_t * km);
252 
253 /* ikev2_payload.c */
254 typedef struct {
257  u8 * data;
259 
260 #define ikev2_payload_new_chain(V) vec_validate (V, 0)
261 #define ikev2_payload_destroy_chain(V) do { \
262  vec_free((V)->data); \
263  vec_free(V); \
264 } while (0)
265 
266 void ikev2_payload_add_notify(ikev2_payload_chain_t * c, u16 msg_type, u8 * data);
268 void ikev2_payload_add_ke(ikev2_payload_chain_t * c, u16 dh_group, u8 * dh_data);
275 void ikev2_parse_vendor_payload(ike_payload_header_t * ikep);
276 ikev2_sa_proposal_t * ikev2_parse_sa_payload(ike_payload_header_t * ikep);
277 ikev2_ts_t * ikev2_parse_ts_payload(ike_payload_header_t * ikep);
278 ikev2_delete_t * ikev2_parse_delete_payload(ike_payload_header_t * ikep);
279 ikev2_notify_t * ikev2_parse_notify_payload(ike_payload_header_t * ikep);
280 
281 #endif /* __included_ikev2_priv_h__ */
282 
u8 * dh_shared_key
Definition: ikev2_priv.h:159
Definition: mhash.h:46
ikev2_transform_type_t type
Definition: ikev2_priv.h:65
void ikev2_payload_add_sa(ikev2_payload_chain_t *c, ikev2_sa_proposal_t *proposals)
ikev2_id_t r_id
Definition: ikev2_priv.h:182
void ikev2_payload_add_notify(ikev2_payload_chain_t *c, u16 msg_type, u8 *data)
ikev2_transform_integ_type_t
Definition: ikev2.h:257
EVP_PKEY * pkey
Definition: ikev2_priv.h:227
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
u8 * ikev2_calc_prfplus(ikev2_sa_transform_t *tr, u8 *key, u8 *seed, int len)
Definition: ikev2_crypto.c:278
ikev2_auth_method_t
Definition: ikev2.h:326
ikev2_sa_transform_t * ikev2_sa_get_td_for_type(ikev2_sa_proposal_t *p, ikev2_transform_type_t type)
Definition: ikev2.c:185
ikev2_profile_t * profiles
Definition: ikev2_priv.h:217
u8 v8
Definition: ikev2.h:27
ikev2_state_t state
Definition: ikev2_priv.h:147
u8 * sk_pi
Definition: ikev2_priv.h:173
ikev2_main_t ikev2_main
Definition: ikev2_priv.h:234
u8 initial_contact
Definition: ikev2_priv.h:149
ikev2_ts_t * tsi
Definition: ikev2_priv.h:134
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:178
u8 * last_sa_init_res_packet_data
Definition: ikev2_priv.h:192
ikev2_auth_t auth
Definition: ikev2_priv.h:205
ikev2_ts_t * tsr
Definition: ikev2_priv.h:135
ikev2_ts_t * ikev2_parse_ts_payload(ike_payload_header_t *ikep)
ikev2_id_t rem_id
Definition: ikev2_priv.h:207
ikev2_transform_dh_type_t
Definition: ikev2.h:306
EVP_PKEY * ikev2_load_cert_file(u8 *file)
Definition: ikev2_crypto.c:499
void ikev2_payload_add_ts(ikev2_payload_chain_t *c, ikev2_ts_t *ts, u8 type)
u32 last_msg_id
Definition: ikev2_priv.h:195
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:111
ip4_address_t start_addr
Definition: ikev2_priv.h:99
u16 selector_len
Definition: ikev2_priv.h:96
EVP_PKEY * ikev2_load_key_file(u8 *file)
Definition: ikev2_crypto.c:529
unsigned long u64
Definition: types.h:89
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:164
int ikev2_verify_sign(EVP_PKEY *pkey, u8 *sigbuf, u8 *data)
Definition: ikev2_crypto.c:470
ikev2_auth_t i_auth
Definition: ikev2_priv.h:177
ikev2_id_t loc_id
Definition: ikev2_priv.h:206
ikev2_sa_transform_t * transforms
Definition: ikev2_priv.h:90
u8 * sk_ar
Definition: ikev2_priv.h:170
u8 * r_dh_data
Definition: ikev2_priv.h:161
u8 * last_sa_init_req_packet_data
Definition: ikev2_priv.h:191
ikev2_ts_t rem_ts
Definition: ikev2_priv.h:209
u8 * i_dh_data
Definition: ikev2_priv.h:160
uword * sa_by_rspi
Definition: ikev2_priv.h:223
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:110
u8 * r_nonce
Definition: ikev2_priv.h:155
mhash_t profile_index_by_name
Definition: ikev2_priv.h:224
u16 end_port
Definition: ikev2_priv.h:98
ikev2_sa_transform_t * supported_transforms
Definition: ikev2_priv.h:220
ikev2_rekey_t * rekey
Definition: ikev2_priv.h:188
void ikev2_payload_chain_add_padding(ikev2_payload_chain_t *c, int bs)
ikev2_protocol_id_t
Definition: ikev2.h:102
ip4_address_t end_addr
Definition: ikev2_priv.h:100
ip4_address_t iaddr
Definition: ikev2_priv.h:150
u8 * ikev2_calc_sign(EVP_PKEY *pkey, u8 *data)
Definition: ikev2_crypto.c:481
v8 * ikev2_calc_prf(ikev2_sa_transform_t *tr, v8 *key, v8 *data)
Definition: ikev2_crypto.c:260
u8 * i_nonce
Definition: ikev2_priv.h:154
u8 * sk_ei
Definition: ikev2_priv.h:171
ikev2_delete_t * ikev2_parse_delete_payload(ike_payload_header_t *ikep)
ikev2_sa_proposal_t * ikev2_parse_sa_payload(ike_payload_header_t *ikep)
ikev2_transform_encr_type_t
Definition: ikev2.h:218
ikev2_delete_t * del
Definition: ikev2_priv.h:185
ikev2_ts_t * tsi
Definition: ikev2_priv.h:114
v8 * ikev2_decrypt_data(ikev2_sa_t *sa, u8 *data, int len)
Definition: ikev2_crypto.c:340
void ikev2_payload_add_nonce(ikev2_payload_chain_t *c, u8 *nonce)
ikev2_sa_t * sas
Definition: ikev2_priv.h:214
ip4_address_t raddr
Definition: ikev2_priv.h:151
u8 * sk_er
Definition: ikev2_priv.h:172
const void * cipher
Definition: ikev2_priv.h:83
ikev2_ts_t loc_ts
Definition: ikev2_priv.h:208
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:165
u8 protocol_id
Definition: ikev2_priv.h:95
unsigned int u32
Definition: types.h:88
vnet_main_t * vnet_main
Definition: ikev2_priv.h:231
ikev2_id_type_t
Definition: ikev2.h:341
ikev2_notify_t * ikev2_parse_notify_payload(ike_payload_header_t *ikep)
ikev2_transform_esn_type_t
Definition: ikev2.h:316
ikev2_sa_proposal_t * r_proposal
Definition: ikev2_priv.h:133
u8 * sk_ai
Definition: ikev2_priv.h:169
v8 * ikev2_calc_integr(ikev2_sa_transform_t *tr, v8 *key, u8 *data, int len)
Definition: ikev2_crypto.c:317
u16 dh_group
Definition: ikev2_priv.h:158
ikev2_sa_proposal_t * i_proposal
Definition: ikev2_priv.h:132
const char * dh_p
Definition: ikev2_priv.h:80
EVP_PKEY * key
Definition: ikev2_priv.h:56
ikev2_dh_group_t
Definition: ikev2_priv.h:59
u64 uword
Definition: types.h:112
const void * md
Definition: ikev2_priv.h:82
void ikev2_crypto_init(ikev2_main_t *km)
Definition: ikev2_crypto.c:551
u8 * last_res_packet_data
Definition: ikev2_priv.h:196
const char * dh_g
Definition: ikev2_priv.h:81
unsigned short u16
Definition: types.h:57
void ikev2_payload_add_auth(ikev2_payload_chain_t *c, ikev2_auth_t *auth)
u16 start_port
Definition: ikev2_priv.h:97
void ikev2_payload_add_ke(ikev2_payload_chain_t *c, u16 dh_group, u8 *dh_data)
unsigned char u8
Definition: types.h:56
u8 * sk_pr
Definition: ikev2_priv.h:174
ikev2_id_t i_id
Definition: ikev2_priv.h:181
ikev2_ts_t * tsr
Definition: ikev2_priv.h:115
ikev2_child_sa_t * childs
Definition: ikev2_priv.h:198
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:370
void ikev2_payload_add_delete(ikev2_payload_chain_t *c, ikev2_delete_t *d)
ikev2_transform_prf_type_t
Definition: ikev2.h:234
u8 unsupported_cp
Definition: ikev2_priv.h:148
void ikev2_sa_free_proposal_vector(ikev2_sa_proposal_t **v)
Definition: ikev2.c:214
ikev2_transform_type_t
Definition: ikev2.h:196
void ikev2_generate_dh(ikev2_sa_t *sa, ikev2_sa_transform_t *t)
Definition: ikev2_crypto.c:396
vlib_main_t * vlib_main
Definition: ikev2_priv.h:230
ikev2_state_t
Definition: ikev2_priv.h:41