1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
stf_status main_inI1_outR1(struct msg_digest *md) { #ifdef DMALLOC if (_dm_initialized != 0) { dmalloc_log_changed(_dm_mark, 1, 0, 1); dmalloc_log_stats (); } _dm_mark = dmalloc_mark() ; _dm_initialized = 1; #endif
struct payload_digest *const sa_pd = md->chain[ISAKMP_NEXT_SA]; struct state *st; struct connection *c;
pb_stream r_sa_pbs; lset_t policy_hint = 0;
bool openpgp_peer = FALSE;
int next; int numvidtosend = 1;
#ifdef NAT_TRAVERSAL if (md->quirks.nat_traversal_vid && nat_traversal_enabled) { DBG(DBG_NATT, DBG_log("nat-t detected, sending nat-t VID")); numvidtosend++; } #endif
#if SEND_PLUTO_VID || defined(openpgp_peer) numvidtosend++; #endif
#if defined(openpgp_peer) { struct payload_digest *p; for (p = md->chain[ISAKMP_NEXT_VID]; p != NULL; p = p->next) { int vid_len = sizeof(pgp_vendorid) - 1 < pbs_left(&p->pbs) ? sizeof(pgp_vendorid) - 1 : pbs_left(&p->pbs);
if (memcmp(pgp_vendorid, p->pbs.cur, vid_len) == 0) { openpgp_peer = TRUE; DBG(DBG_PARSING, DBG_log("we have an OpenPGP peer") ) } } } #endif
c = find_host_connection(ANY_MATCH, &md->iface->ip_addr, pluto_port500 , KH_IPADDR , &md->sender , md->sender_port, LEMPTY, POLICY_IKEV1_DISABLE, &policy_hint);
if (c == NULL) { pb_stream pre_sa_pbs = sa_pd->pbs; lset_t policy = preparse_isakmp_sa_body(&pre_sa_pbs);
if (md->quirks.xauth_vid == TRUE) { policy |= POLICY_XAUTH; }
{ struct connection *d; d = find_host_connection(ANY_MATCH, &md->iface->ip_addr, pluto_port500 , KH_ANY , (ip_address*)NULL , md->sender_port, policy, POLICY_IKEV1_DISABLE, &policy_hint); for (; d != NULL; d = d->IPhp_next) { if (d->kind == CK_GROUP) { } else { if (d->kind == CK_TEMPLATE && !(d->policy & POLICY_OPPO)) { c = d; break; }
if (addrinsubnet(&md->sender, &d->spd.that.client) && (c == NULL || !subnetinsubnet(&c->spd.that.client, &d->spd.that.client))) c = d; } } } if (c == NULL) { loglog(RC_LOG_SERIOUS, "initial Main Mode message received on %s:%u" " but no connection has been authorized%s%s" , ip_str(&md->iface->ip_addr), ntohs(portof(&md->iface->ip_addr)) , (policy != LEMPTY) ? " with policy=" : "" , (policy != LEMPTY) ? bitnamesof(sa_policy_bit_names, policy) : "");
if(policy_hint & POLICY_IKEV1_DISABLE) { md->note = INVALID_MAJOR_VERSION; return STF_FAIL; }
return STF_IGNORE; } else if (c->kind != CK_TEMPLATE) { loglog(RC_LOG_SERIOUS, "initial Main Mode message received on %s:%u" " but \"%s\" forbids connection" , ip_str(&md->iface->ip_addr), pluto_port500, c->name); return STF_IGNORE; } else {
DBG(DBG_CONTROL, DBG_log("instantiating \"%s\" for initial Main Mode message received on %s:%u" , c->name, ip_str(&md->iface->ip_addr), pluto_port500)); c = rw_instantiate(c, &md->sender , NULL, NULL); } } else { if ((c->kind == CK_TEMPLATE) && c->spd.that.virt) { DBG(DBG_CONTROL, DBG_log("local endpoint has virt (vnet/vhost) set without wildcards - needs instantiation")); c = rw_instantiate(c,&md->sender,NULL,NULL); } }
#ifdef XAUTH if(c->spd.this.xauth_server || c->spd.this.xauth_client) { numvidtosend++; } #endif
md->st = st = new_state(); #ifdef XAUTH passert(st->st_oakley.xauth == 0); #endif st->st_connection = c; st->st_remoteaddr = md->sender; st->st_remoteport = md->sender_port; st->st_localaddr = md->iface->ip_addr; st->st_localport = md->iface->port; st->st_interface = md->iface;
st->st_ike_maj = md->maj; st->st_ike_min = md->min;
set_cur_state(st); st->st_try = 0; st->st_policy = c->policy & ~POLICY_IPSEC_MASK; change_state(st, STATE_MAIN_R0);
memcpy(st->st_icookie, md->hdr.isa_icookie, COOKIE_SIZE);
get_cookie(FALSE, st->st_rcookie, COOKIE_SIZE, &md->sender);
insert_state(st);
st->st_doi = ISAKMP_DOI_IPSEC; st->st_situation = SIT_IDENTITY_ONLY;
copy_quirks(&st->quirks,&md->quirks);
if ((c->kind == CK_INSTANCE) && (c->spd.that.host_port_specific)) { openswan_log("responding to Main Mode from unknown peer %s:%u" , ip_str(&c->spd.that.host_addr), c->spd.that.host_port); } else if (c->kind == CK_INSTANCE) { openswan_log("responding to Main Mode from unknown peer %s" , ip_str(&c->spd.that.host_addr)); } else { openswan_log("responding to Main Mode"); }
zero(reply_buffer); init_pbs(&reply_stream, reply_buffer, sizeof(reply_buffer), "reply packet"); { struct isakmp_hdr r_hdr = md->hdr;
r_hdr.isa_flags &= ~ISAKMP_FLAG_COMMIT; memcpy(r_hdr.isa_rcookie, st->st_rcookie, COOKIE_SIZE); r_hdr.isa_np = ISAKMP_NEXT_SA; if (!out_struct(&r_hdr, &isakmp_hdr_desc, &reply_stream, &md->rbody)) return STF_INTERNAL_ERROR; } { struct isakmp_sa r_sa = sa_pd->payload.sa;
r_sa.isasa_np = numvidtosend ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if (!out_struct(&r_sa, &isakmp_sa_desc, &md->rbody, &r_sa_pbs)) return STF_INTERNAL_ERROR; }
RETURN_STF_FAILURE(parse_isakmp_sa_body(&sa_pd->pbs, &sa_pd->payload.sa , &r_sa_pbs, FALSE, st));
if (SEND_PLUTO_VID || openpgp_peer) { char *vendorid = (openpgp_peer) ? pgp_vendorid : pluto_vendorid;
next = --numvidtosend ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if (!out_generic_raw(next, &isakmp_vendor_id_desc, &md->rbody , vendorid, strlen(vendorid), "Vendor ID")) return STF_INTERNAL_ERROR; }
next = --numvidtosend ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if( !out_vid(next, &md->rbody, VID_MISC_DPD)) return STF_INTERNAL_ERROR;
#ifdef XAUTH if(c->spd.this.xauth_server || c->spd.this.xauth_client) { next = --numvidtosend ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if (!out_vendorid(next, &md->rbody, VID_MISC_XAUTH)) return STF_INTERNAL_ERROR; } #endif #ifdef NAT_TRAVERSAL DBG(DBG_NATT, DBG_log("sender checking NAT-T: %d and %d" , nat_traversal_enabled , md->quirks.nat_traversal_vid)); if (md->quirks.nat_traversal_vid && nat_traversal_enabled) {
next = --numvidtosend ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; st->hidden_variables.st_nat_traversal = nat_traversal_vid_to_method(md->quirks.nat_traversal_vid); if ((st->hidden_variables.st_nat_traversal) && (!out_vendorid(next, &md->rbody, md->quirks.nat_traversal_vid))) { return STF_INTERNAL_ERROR; } } #endif
#ifdef DEBUG if(numvidtosend != 0) { openswan_log("payload alignment problem please check the code in main_inI1_outR1 (num=%d)", numvidtosend); } #endif
close_message(&md->rbody);
clonereplacechunk(st->st_p1isa, sa_pd->pbs.start, pbs_room(&sa_pd->pbs), "sa in main_inI1_outR1()");
return STF_OK; }
|