1 /* $OpenBSD: exchange.h,v 1.34 2015/01/16 06:39:58 deraadt Exp $ */ 2 /* $EOM: exchange.h,v 1.28 2000/09/28 12:54:28 niklas Exp $ */ 3 4 /* 5 * Copyright (c) 1998, 1999, 2001 Niklas Hallqvist. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * This code was written under funding by Ericsson Radio Systems. 30 */ 31 32 #ifndef _EXCHANGE_H_ 33 #define _EXCHANGE_H_ 34 35 #include <sys/types.h> 36 #include <sys/queue.h> 37 38 #include "exchange_num.h" 39 #include "isakmp.h" 40 41 /* Remove an exchange if it has not been fully negotiated in this time. */ 42 #define EXCHANGE_MAX_TIME 120 43 44 struct crypto_xf; 45 struct certreq_aca; 46 struct doi; 47 struct event; 48 struct keystate; 49 struct message; 50 struct payload; 51 struct transport; 52 struct sa; 53 54 struct exchange { 55 /* Link to exchanges with the same hash value. */ 56 LIST_ENTRY(exchange) link; 57 58 /* A name of the SAs this exchange will result in. XXX non unique? */ 59 char *name; 60 61 /* 62 * A name of the major policy deciding offers and acceptable 63 * proposals. 64 */ 65 char *policy; 66 67 /* 68 * A function with a polymorphic argument called after the exchange 69 * has been run to its end, successfully. The 2nd argument is true 70 * if the finalization hook is called due to the exchange not running 71 * to its end normally. 72 */ 73 void (*finalize)(struct exchange *, void *, int); 74 void *finalize_arg; 75 76 /* When several SA's are being negotiated we keep them here. */ 77 TAILQ_HEAD(sa_head, sa) sa_list; 78 79 /* 80 * The event that will occur when it has taken too long time to try to 81 * run the exchange and which will trigger auto-destruction. 82 */ 83 struct event *death; 84 85 /* 86 * Both initiator and responder cookies. 87 * XXX For code clarity we might split this into two fields. 88 */ 89 u_int8_t cookies[ISAKMP_HDR_COOKIES_LEN]; 90 91 /* The message ID signifying phase 2 exchanges. */ 92 u_int8_t message_id[ISAKMP_HDR_MESSAGE_ID_LEN]; 93 94 /* The exchange type we are using. */ 95 u_int8_t type; 96 97 /* Phase is 1 for ISAKMP SA exchanges, and 2 for application ones. */ 98 u_int8_t phase; 99 100 /* The "step counter" of the exchange, starting from zero. */ 101 u_int8_t step; 102 103 /* 1 if we are the initiator, 0 if we are the responder. */ 104 u_int8_t initiator; 105 106 /* Various flags, look below for descriptions. */ 107 u_int32_t flags; 108 109 /* The DOI that is to handle DOI-specific issues for this exchange. */ 110 struct doi *doi; 111 112 /* 113 * A "program counter" into the script that validate message contents 114 * for this exchange. 115 */ 116 int16_t *exch_pc; 117 118 /* The last message received, used for checking for duplicates. */ 119 struct message *last_received; 120 121 /* The last message sent, to be acked when something new is received. */ 122 struct message *last_sent; 123 124 /* 125 * If some message is queued up for sending, we want to be able to 126 * remove it from the queue, when the exchange is deleted. 127 */ 128 struct message *in_transit; 129 130 /* 131 * Initiator's & responder's nonces respectively, with lengths. 132 * XXX Should this be in the DOI-specific parts instead? 133 */ 134 u_int8_t *nonce_i; 135 size_t nonce_i_len; 136 u_int8_t *nonce_r; 137 size_t nonce_r_len; 138 139 /* 140 * The ID payload contents for the initiator & responder, 141 * respectively. 142 */ 143 u_int8_t *id_i; 144 size_t id_i_len; 145 u_int8_t *id_r; 146 size_t id_r_len; 147 148 /* Policy session identifier, where applicable. */ 149 int policy_id; 150 151 /* Crypto info needed to encrypt/decrypt packets in this exchange. */ 152 struct crypto_xf *crypto; 153 size_t key_length; 154 struct keystate *keystate; 155 156 /* 157 * Used only by KeyNote, to cache the key used to authenticate Phase 158 * 1 159 */ 160 char *keynote_key; /* printable format */ 161 162 /* 163 * Received certificate - used to verify signatures on packet, 164 * stored here for later policy processing. 165 * 166 * The rules for the recv_* and sent_* fields are: 167 * - recv_cert stores the credential (if any) received from the peer; 168 * the kernel may pass us one, but we ignore it. We pass it to the 169 * kernel so processes can peek at it. When doing passphrase 170 * authentication in Phase 1, this is empty. 171 * - recv_key stores the key (public or private) used by the peer 172 * to authenticate. Otherwise, same properties as recv_cert except 173 * that we don't tell the kernel about passphrases (so we don't 174 * reveal system-wide passphrases). Processes that used passphrase 175 * authentication already know the passphrase! We ignore it if/when 176 * received from the kernel (meaningless). 177 * - sent_cert stores the credential, if any, we used to authenticate 178 * with the peer. It may be passed to us by the kernel, or we may 179 * have found it in our certificate storage. In either case, there's 180 * no point passing it to the kernel, so we don't. 181 * - sent key stores the private key we used for authentication with 182 * the peer (private key or passphrase). This may have been received 183 * from the kernel, or may be a system-wide setting. In either case, 184 * we don't pass it to the kernel, to avoid revealing such information 185 * to processes (processes either already know it, or have no business 186 * knowing it). 187 */ 188 int recv_certtype, recv_keytype; 189 void *recv_cert; /* Certificate received from peer, 190 * native format */ 191 void *recv_key; /* Key peer used to authenticate, 192 * native format */ 193 194 /* Likewise, for certificates we use. */ 195 int sent_certtype, sent_keytype; 196 void *sent_cert; /* Certificate (to be) sent to peer, 197 * native format */ 198 199 /* ACQUIRE sequence number. */ 200 u_int32_t seq; 201 202 /* XXX This is no longer necessary, it is covered by policy. */ 203 204 /* Acceptable authorities for cert requests. */ 205 TAILQ_HEAD(aca_head, certreq_aca) aca_list; 206 207 /* DOI-specific opaque data. */ 208 void *data; 209 }; 210 211 /* The flag bits. */ 212 #define EXCHANGE_FLAG_I_COMMITTED 0x0001 213 #define EXCHANGE_FLAG_HE_COMMITTED 0x0002 214 #define EXCHANGE_FLAG_COMMITTED (EXCHANGE_FLAG_I_COMMITTED \ 215 | EXCHANGE_FLAG_HE_COMMITTED) 216 #define EXCHANGE_FLAG_ENCRYPT 0x0004 217 #define EXCHANGE_FLAG_NAT_T_CAP_PEER 0x0008 /* Peer is NAT capable. */ 218 #define EXCHANGE_FLAG_NAT_T_ENABLE 0x0010 /* We are doing NAT-T. */ 219 #define EXCHANGE_FLAG_NAT_T_KEEPALIVE 0x0020 /* We are the NAT:ed peer. */ 220 #define EXCHANGE_FLAG_DPD_CAP_PEER 0x0040 /* Peer is DPD capable. */ 221 #define EXCHANGE_FLAG_NAT_T_RFC 0x0080 /* Peer does RFC NAT-T. */ 222 #define EXCHANGE_FLAG_NAT_T_DRAFT 0x0100 /* Peer does draft NAT-T.*/ 223 #define EXCHANGE_FLAG_OPENBSD 0x0200 /* Peer is OpenBSD */ 224 225 extern int exchange_add_certs(struct message *); 226 extern int exchange_add_certreqs(struct message *); 227 extern void exchange_finalize(struct message *); 228 extern void exchange_free(struct exchange *); 229 extern void exchange_free_aca_list(struct exchange *); 230 extern void exchange_establish(char *name, void (*)(struct exchange *, 231 void *, int), void *, int); 232 extern void exchange_establish_p1(struct transport *, u_int8_t, u_int32_t, 233 char *, void *, void (*)(struct exchange *, void *, int), 234 void *, int); 235 extern void exchange_establish_p2(struct sa *, u_int8_t, char *, void *, 236 void (*)(struct exchange *, void *, int), void *); 237 extern int exchange_gen_nonce(struct message *, size_t); 238 extern void exchange_init(void); 239 extern struct exchange *exchange_lookup(u_int8_t *, int); 240 extern struct exchange *exchange_lookup_by_name(char *, int); 241 extern struct exchange *exchange_lookup_from_icookie(u_int8_t *); 242 extern void exchange_report(void); 243 extern void exchange_run(struct message *); 244 extern int exchange_save_nonce(struct message *); 245 extern int exchange_save_certreq(struct message *); 246 extern int16_t *exchange_script(struct exchange *); 247 extern struct exchange *exchange_setup_p1(struct message *, u_int32_t); 248 extern struct exchange *exchange_setup_p2(struct message *, u_int8_t); 249 extern void exchange_upgrade_p1(struct message *); 250 251 #endif /* _EXCHANGE_H_ */ 252