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
| stf_status main_outI1(int whack_sock , struct connection *c , struct state *predecessor , so_serial_t *newstateno , lset_t policy , unsigned long try , enum crypto_importance importance , struct xfrm_user_sec_ctx_ike * uctx ) { struct state *st = new_state(); struct msg_digest md;
int numvidtosend = 1; #ifdef NAT_TRAVERSAL if (nat_traversal_enabled) { numvidtosend++; } #endif #if SEND_PLUTO_VID || defined(openpgp_peer) numvidtosend++; #endif #ifdef XAUTH if(c->spd.this.xauth_client || c->spd.this.xauth_server) { numvidtosend++; } #endif
get_cookie(TRUE, st->st_icookie, COOKIE_SIZE, &c->spd.that.host_addr);
initialize_new_state(st, c, policy, try, whack_sock, importance); if(newstateno) *newstateno = st->st_serialno;
st->st_ike_maj = IKEv1_MAJOR_VERSION; st->st_ike_min = IKEv1_MINOR_VERSION;
change_state(st, STATE_MAIN_I1);
if (HAS_IPSEC_POLICY(policy)) add_pending(dup_any(whack_sock), st, c, policy, 1 , predecessor == NULL? SOS_NOBODY : predecessor->st_serialno , uctx );
#ifdef HAVE_LABELED_IPSEC st->sec_ctx = NULL; #endif
if (predecessor == NULL) openswan_log("initiating Main Mode"); else openswan_log("initiating Main Mode to replace #%lu", predecessor->st_serialno);
zero(reply_buffer); init_pbs(&reply_stream, reply_buffer, sizeof(reply_buffer), "reply packet");
{ struct isakmp_hdr hdr;
zero(&hdr); hdr.isa_version = ISAKMP_MAJOR_VERSION << ISA_MAJ_SHIFT | ISAKMP_MINOR_VERSION; hdr.isa_np = ISAKMP_NEXT_SA; hdr.isa_xchg = ISAKMP_XCHG_IDPROT; memcpy(hdr.isa_icookie, st->st_icookie, COOKIE_SIZE); if (!out_struct(&hdr, &isakmp_hdr_desc, &reply_stream, &md.rbody)) { reset_cur_state(); return STF_INTERNAL_ERROR; } }
{ u_char *sa_start = md.rbody.cur; int policy_index = POLICY_ISAKMP(policy , c->spd.this.xauth_server , c->spd.this.xauth_client);
int np = numvidtosend > 0 ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if (!out_sa(&md.rbody , &oakley_sadb[policy_index], st, TRUE, FALSE, np)) { openswan_log("outsa fail"); reset_cur_state(); return STF_INTERNAL_ERROR; } passert(st->st_p1isa.ptr == NULL); clonetochunk(st->st_p1isa, sa_start, md.rbody.cur - sa_start , "sa in main_outI1"); }
if (SEND_PLUTO_VID || c->spd.this.cert.type == CERT_PGP) { char *vendorid = (c->spd.this.cert.type == CERT_PGP) ? pgp_vendorid : pluto_vendorid; int np = --numvidtosend > 0 ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE;
if (!out_generic_raw(np, &isakmp_vendor_id_desc, &md.rbody , vendorid, strlen(vendorid), "Vendor ID")) return STF_INTERNAL_ERROR; }
{ int np = --numvidtosend > 0 ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if(!out_vid(np, &md.rbody, VID_MISC_DPD)) { reset_cur_state(); return STF_INTERNAL_ERROR; } }
#ifdef NAT_TRAVERSAL DBG(DBG_NATT, DBG_log("nat traversal enabled: %d" , nat_traversal_enabled)); if (nat_traversal_enabled) { int np = --numvidtosend > 0 ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE;
if (!nat_traversal_insert_vid(np, &md.rbody, st)) { reset_cur_state(); return STF_INTERNAL_ERROR; } } #endif
#ifdef XAUTH if(c->spd.this.xauth_client || c->spd.this.xauth_server) { int np = --numvidtosend > 0 ? ISAKMP_NEXT_VID : ISAKMP_NEXT_NONE; if(!out_vid(np, &md.rbody, VID_MISC_XAUTH)) { reset_cur_state(); return STF_INTERNAL_ERROR; } } #endif
#ifdef DEBUG if(numvidtosend != 0) { openswan_log("payload alignment problem please check the code in main_inR1_outR2 (num=%d)", numvidtosend); } #endif
close_message(&md.rbody); close_output_pbs(&reply_stream);
TCLCALLOUT("avoidEmitting", st, st->st_connection, &md); clonetochunk(st->st_tpacket, reply_stream.start, pbs_offset(&reply_stream) , "reply packet for main_outI1");
send_packet(st, "main_outI1", TRUE);
TCLCALLOUT("adjustTimers", st, st->st_connection, &md);
#ifdef TPM tpm_stolen: tpm_ignore: #endif delete_event(st); event_schedule(EVENT_RETRANSMIT, EVENT_RETRANSMIT_DELAY_0, st);
if (predecessor != NULL) { update_pending(predecessor, st); whack_log(RC_NEW_STATE + STATE_MAIN_I1 , "%s: initiate, replacing #%lu" , enum_name(&state_names, st->st_state) , predecessor->st_serialno); } else { whack_log(RC_NEW_STATE + STATE_MAIN_I1 , "%s: initiate", enum_name(&state_names, st->st_state)); } reset_cur_state(); return STF_OK; }
|