| 1 |
/* $OpenBSD: common.c,v 1.9 2020/11/26 22:29:32 tobhe Exp $ */ |
| 2 |
/* |
| 3 |
* A bunch of stub functions so we can compile and link ikev2_pld.c |
| 4 |
* in a standalone program for testing purposes. |
| 5 |
* |
| 6 |
* Placed in the public domain |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <sys/socket.h> |
| 10 |
#include <sys/time.h> |
| 11 |
#include <sys/uio.h> |
| 12 |
|
| 13 |
#include <event.h> |
| 14 |
#include <limits.h> |
| 15 |
#include <string.h> |
| 16 |
|
| 17 |
#include "iked.h" |
| 18 |
#include "types.h" |
| 19 |
|
| 20 |
#define IKEV2_FLAG_INITIATOR 0x08 /* Sent by the initiator */ |
| 21 |
|
| 22 |
int eap_parse(struct iked *, const struct iked_sa *, |
| 23 |
struct iked_message *, void *, int); |
| 24 |
int ikev2_msg_frompeer(struct iked_message *); |
| 25 |
int ikev2_send_ike_e(struct iked *, struct iked_sa *, struct ibuf *, |
| 26 |
u_int8_t, u_int8_t, int); |
| 27 |
void ikev2_ikesa_recv_delete(struct iked *, struct iked_sa *); |
| 28 |
struct iked_childsa * |
| 29 |
childsa_lookup(struct iked_sa *, u_int64_t, u_int8_t); |
| 30 |
int ikev2_childsa_delete(struct iked *, struct iked_sa *, |
| 31 |
u_int8_t, u_int64_t, u_int64_t *, int); |
| 32 |
int sa_stateok(const struct iked_sa *, int); |
| 33 |
void sa_state(struct iked *, struct iked_sa *, int); |
| 34 |
void ikev2_disable_rekeying(struct iked *, struct iked_sa *); |
| 35 |
void ikev2_init_ike_sa(struct iked *, void *); |
| 36 |
struct dh_group * |
| 37 |
group_get(u_int32_t); |
| 38 |
void timer_set(struct iked *, struct iked_timer *, |
| 39 |
void (*)(struct iked *, void *), void *); |
| 40 |
void timer_add(struct iked *, struct iked_timer *, int); |
| 41 |
void timer_del(struct iked *, struct iked_timer *); |
| 42 |
ssize_t ikev2_nat_detection(struct iked *, struct iked_message *, |
| 43 |
void *, size_t, u_int, int); |
| 44 |
int ca_setreq(struct iked *, struct iked_sa *, struct iked_static_id *, |
| 45 |
u_int8_t, u_int8_t, u_int8_t *, size_t, enum privsep_procid); |
| 46 |
int ikev2_print_id(struct iked_id *, char *, size_t); |
| 47 |
int config_add_transform(struct iked_proposal *, u_int, u_int, u_int, |
| 48 |
u_int); |
| 49 |
struct iked_proposal * |
| 50 |
config_add_proposal(struct iked_proposals *, u_int, u_int); |
| 51 |
void config_free_proposal(struct iked_proposals *, struct iked_proposal *); |
| 52 |
int ikev2_send_informational(struct iked *, struct iked_message *); |
| 53 |
struct ibuf * |
| 54 |
ikev2_msg_decrypt(struct iked *, struct iked_sa *, struct ibuf *, |
| 55 |
struct ibuf *); |
| 56 |
void ikev2_msg_cleanup(struct iked *, struct iked_message *); |
| 57 |
|
| 58 |
int |
| 59 |
eap_parse(struct iked *env, const struct iked_sa *sa, struct iked_message *msg, |
| 60 |
void *data, int response) |
| 61 |
{ |
| 62 |
return (0); |
| 63 |
} |
| 64 |
|
| 65 |
/* Copied from ikev2_msg.c for better coverage */ |
| 66 |
int |
| 67 |
ikev2_msg_frompeer(struct iked_message *msg) |
| 68 |
{ |
| 69 |
struct iked_sa *sa = msg->msg_sa; |
| 70 |
struct ike_header *hdr; |
| 71 |
|
| 72 |
msg = msg->msg_parent; |
| 73 |
|
| 74 |
if (sa == NULL || |
| 75 |
(hdr = ibuf_seek(msg->msg_data, 0, sizeof(*hdr))) == NULL) |
| 76 |
return (0); |
| 77 |
|
| 78 |
if (!sa->sa_hdr.sh_initiator && |
| 79 |
(hdr->ike_flags & IKEV2_FLAG_INITIATOR)) |
| 80 |
return (1); |
| 81 |
else if (sa->sa_hdr.sh_initiator && |
| 82 |
(hdr->ike_flags & IKEV2_FLAG_INITIATOR) == 0) |
| 83 |
return (1); |
| 84 |
|
| 85 |
return (0); |
| 86 |
} |
| 87 |
|
| 88 |
int |
| 89 |
ikev2_send_ike_e(struct iked *env, struct iked_sa *sa, struct ibuf *buf, |
| 90 |
u_int8_t firstpayload, u_int8_t exchange, int response) |
| 91 |
{ |
| 92 |
return (0); |
| 93 |
} |
| 94 |
|
| 95 |
void |
| 96 |
ikev2_ikesa_recv_delete(struct iked *env, struct iked_sa *sa) |
| 97 |
{ |
| 98 |
} |
| 99 |
|
| 100 |
const char * |
| 101 |
ikev2_ikesa_info(uint64_t spi, const char *msg) |
| 102 |
{ |
| 103 |
return ""; |
| 104 |
} |
| 105 |
|
| 106 |
struct iked_childsa * |
| 107 |
childsa_lookup(struct iked_sa *a, u_int64_t b, u_int8_t c) |
| 108 |
{ |
| 109 |
return (NULL); |
| 110 |
} |
| 111 |
|
| 112 |
int |
| 113 |
ikev2_childsa_delete(struct iked *a, struct iked_sa *b, u_int8_t c, |
| 114 |
u_int64_t d, u_int64_t *e , int f) |
| 115 |
{ |
| 116 |
return (0); |
| 117 |
} |
| 118 |
|
| 119 |
int |
| 120 |
sa_stateok(const struct iked_sa *a, int b) |
| 121 |
{ |
| 122 |
return (0); |
| 123 |
} |
| 124 |
|
| 125 |
void |
| 126 |
sa_state(struct iked * a, struct iked_sa *b, int c) |
| 127 |
{ |
| 128 |
} |
| 129 |
|
| 130 |
void |
| 131 |
ikev2_disable_rekeying(struct iked *a, struct iked_sa *b) |
| 132 |
{ |
| 133 |
} |
| 134 |
|
| 135 |
void |
| 136 |
ikev2_init_ike_sa(struct iked *a, void *b) |
| 137 |
{ |
| 138 |
} |
| 139 |
|
| 140 |
const struct group_id * |
| 141 |
group_getid(u_int32_t id) |
| 142 |
{ |
| 143 |
return (NULL); |
| 144 |
} |
| 145 |
|
| 146 |
void |
| 147 |
timer_set(struct iked *env, struct iked_timer *tmr, |
| 148 |
void (*cb)(struct iked *, void *), void *arg) |
| 149 |
{ |
| 150 |
} |
| 151 |
|
| 152 |
void |
| 153 |
timer_add(struct iked *env, struct iked_timer *tmr, int timeout) |
| 154 |
{ |
| 155 |
} |
| 156 |
|
| 157 |
void |
| 158 |
timer_del(struct iked *env, struct iked_timer *tmr) |
| 159 |
{ |
| 160 |
} |
| 161 |
|
| 162 |
ssize_t |
| 163 |
ikev2_nat_detection(struct iked *env, struct iked_message *msg, |
| 164 |
void *ptr, size_t len, u_int type, int frompeer) |
| 165 |
{ |
| 166 |
bzero(ptr, len); |
| 167 |
return (0); |
| 168 |
} |
| 169 |
|
| 170 |
int |
| 171 |
ca_setreq(struct iked *env, struct iked_sa *sh, struct iked_static_id *localid, |
| 172 |
u_int8_t type, u_int8_t more, u_int8_t *data, size_t len, |
| 173 |
enum privsep_procid procid) |
| 174 |
{ |
| 175 |
return (0); |
| 176 |
} |
| 177 |
|
| 178 |
int |
| 179 |
ikev2_print_id(struct iked_id *id, char *idstr, size_t idstrlen) |
| 180 |
{ |
| 181 |
return (0); |
| 182 |
} |
| 183 |
|
| 184 |
int |
| 185 |
config_add_transform(struct iked_proposal *prop, u_int type, |
| 186 |
u_int id, u_int length, u_int keylength) |
| 187 |
{ |
| 188 |
return (0); |
| 189 |
} |
| 190 |
|
| 191 |
struct iked_proposal * |
| 192 |
config_add_proposal(struct iked_proposals *head, u_int id, u_int proto) |
| 193 |
{ |
| 194 |
return (NULL); |
| 195 |
} |
| 196 |
|
| 197 |
void |
| 198 |
config_free_proposal(struct iked_proposals *head, struct iked_proposal *prop) |
| 199 |
{ |
| 200 |
return; |
| 201 |
} |
| 202 |
|
| 203 |
void config_free_fragments(struct iked_frag *frag) |
| 204 |
{ |
| 205 |
return; |
| 206 |
} |
| 207 |
|
| 208 |
int |
| 209 |
ikev2_send_informational(struct iked *env, struct iked_message *msg) |
| 210 |
{ |
| 211 |
return (0); |
| 212 |
} |
| 213 |
|
| 214 |
struct ibuf * |
| 215 |
ikev2_msg_decrypt(struct iked *env, struct iked_sa *sa, |
| 216 |
struct ibuf *msg, struct ibuf *src) |
| 217 |
{ |
| 218 |
if (src == NULL){ |
| 219 |
fprintf(stderr, "%s\n", "msg_decrypt: src == NULL!"); |
| 220 |
exit(-1); |
| 221 |
} |
| 222 |
|
| 223 |
/* |
| 224 |
* Free src as caller uses ikev2_msg_decrypt() like this: |
| 225 |
* src = ikev2_msg_decrypt(..., src); |
| 226 |
*/ |
| 227 |
ibuf_free(src); |
| 228 |
return (NULL); |
| 229 |
} |
| 230 |
|
| 231 |
void |
| 232 |
ikev2_ike_sa_setreason(struct iked_sa *sa, char *r) |
| 233 |
{ |
| 234 |
} |
| 235 |
|
| 236 |
void |
| 237 |
ikev2_msg_dispose(struct iked *env, struct iked_msgqueue *queue, |
| 238 |
struct iked_msg_retransmit *mr) |
| 239 |
{ |
| 240 |
} |
| 241 |
|
| 242 |
struct iked_msg_retransmit * |
| 243 |
ikev2_msg_lookup(struct iked *env, struct iked_msgqueue *queue, |
| 244 |
struct iked_message *msg, uint8_t exchange) |
| 245 |
{ |
| 246 |
return NULL; |
| 247 |
} |
| 248 |
|
| 249 |
/* copied from ikev2_msg.c */ |
| 250 |
void |
| 251 |
ikev2_msg_cleanup(struct iked *env, struct iked_message *msg) |
| 252 |
{ |
| 253 |
struct iked_certreq *cr; |
| 254 |
struct iked_proposal *prop, *proptmp; |
| 255 |
int i; |
| 256 |
|
| 257 |
if (msg == msg->msg_parent) { |
| 258 |
ibuf_free(msg->msg_nonce); |
| 259 |
ibuf_free(msg->msg_ke); |
| 260 |
ibuf_free(msg->msg_auth.id_buf); |
| 261 |
ibuf_free(msg->msg_peerid.id_buf); |
| 262 |
ibuf_free(msg->msg_localid.id_buf); |
| 263 |
ibuf_free(msg->msg_cert.id_buf); |
| 264 |
for (i = 0; i < IKED_SCERT_MAX; i++) |
| 265 |
ibuf_free(msg->msg_scert[i].id_buf); |
| 266 |
ibuf_free(msg->msg_cookie); |
| 267 |
ibuf_free(msg->msg_cookie2); |
| 268 |
ibuf_free(msg->msg_del_buf); |
| 269 |
free(msg->msg_eap.eam_user); |
| 270 |
free(msg->msg_cp_addr); |
| 271 |
free(msg->msg_cp_addr6); |
| 272 |
free(msg->msg_cp_dns); |
| 273 |
|
| 274 |
TAILQ_FOREACH_SAFE(prop, &msg->msg_proposals, prop_entry, |
| 275 |
proptmp) { |
| 276 |
TAILQ_REMOVE(&msg->msg_proposals, prop, prop_entry); |
| 277 |
if (prop->prop_nxforms) |
| 278 |
free(prop->prop_xforms); |
| 279 |
free(prop); |
| 280 |
} |
| 281 |
|
| 282 |
msg->msg_nonce = NULL; |
| 283 |
msg->msg_ke = NULL; |
| 284 |
msg->msg_auth.id_buf = NULL; |
| 285 |
msg->msg_peerid.id_buf = NULL; |
| 286 |
msg->msg_localid.id_buf = NULL; |
| 287 |
msg->msg_cert.id_buf = NULL; |
| 288 |
for (i = 0; i < IKED_SCERT_MAX; i++) |
| 289 |
msg->msg_scert[i].id_buf = NULL; |
| 290 |
msg->msg_cookie = NULL; |
| 291 |
msg->msg_cookie2 = NULL; |
| 292 |
msg->msg_del_buf = NULL; |
| 293 |
msg->msg_eap.eam_user = NULL; |
| 294 |
msg->msg_cp_addr = NULL; |
| 295 |
msg->msg_cp_addr6 = NULL; |
| 296 |
msg->msg_cp_dns = NULL; |
| 297 |
|
| 298 |
while ((cr = SIMPLEQ_FIRST(&msg->msg_certreqs))) { |
| 299 |
ibuf_free(cr->cr_data); |
| 300 |
SIMPLEQ_REMOVE_HEAD(&msg->msg_certreqs, cr_entry); |
| 301 |
free(cr); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
if (msg->msg_data != NULL) { |
| 306 |
ibuf_free(msg->msg_data); |
| 307 |
msg->msg_data = NULL; |
| 308 |
} |
| 309 |
} |