Accept NULL identities passed to peer config enumeration
[strongswan.git] / src / libcharon / config / proposal.h
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup proposal proposal
18 * @{ @ingroup config
19 */
20
21 #ifndef PROPOSAL_H_
22 #define PROPOSAL_H_
23
24 typedef enum protocol_id_t protocol_id_t;
25 typedef enum extended_sequence_numbers_t extended_sequence_numbers_t;
26 typedef struct proposal_t proposal_t;
27
28 #include <library.h>
29 #include <utils/identification.h>
30 #include <utils/linked_list.h>
31 #include <utils/host.h>
32 #include <crypto/transform.h>
33 #include <crypto/crypters/crypter.h>
34 #include <crypto/signers/signer.h>
35 #include <crypto/diffie_hellman.h>
36 #include <selectors/traffic_selector.h>
37
38 /**
39 * Protocol ID of a proposal.
40 */
41 enum protocol_id_t {
42 PROTO_NONE = 0,
43 PROTO_IKE = 1,
44 PROTO_AH = 2,
45 PROTO_ESP = 3,
46 };
47
48 /**
49 * enum names for protocol_id_t
50 */
51 extern enum_name_t *protocol_id_names;
52
53 /**
54 * Stores a set of algorithms used for an SA.
55 *
56 * A proposal stores algorithms for a specific
57 * protocol. It can store algorithms for one protocol.
58 * Proposals with multiple protocols are not supported,
59 * as it's not specified in RFC4301 anymore.
60 */
61 struct proposal_t {
62
63 /**
64 * Add an algorithm to the proposal.
65 *
66 * The algorithms are stored by priority, first added
67 * is the most preferred.
68 * Key size is only needed for encryption algorithms
69 * with variable key size (such as AES). Must be set
70 * to zero if key size is not specified.
71 * The alg parameter accepts encryption_algorithm_t,
72 * integrity_algorithm_t, dh_group_number_t and
73 * extended_sequence_numbers_t.
74 *
75 * @param type kind of algorithm
76 * @param alg identifier for algorithm
77 * @param key_size key size to use
78 */
79 void (*add_algorithm) (proposal_t *this, transform_type_t type,
80 u_int16_t alg, u_int16_t key_size);
81
82 /**
83 * Get an enumerator over algorithms for a specifc algo type.
84 *
85 * @param type kind of algorithm
86 * @return enumerator over u_int16_t alg, u_int16_t key_size
87 */
88 enumerator_t *(*create_enumerator) (proposal_t *this, transform_type_t type);
89
90 /**
91 * Get the algorithm for a type to use.
92 *
93 * If there are multiple algorithms, only the first is returned.
94 *
95 * @param type kind of algorithm
96 * @param alg pointer which receives algorithm
97 * @param key_size pointer which receives the key size
98 * @return TRUE if algorithm of this kind available
99 */
100 bool (*get_algorithm) (proposal_t *this, transform_type_t type,
101 u_int16_t *alg, u_int16_t *key_size);
102
103 /**
104 * Check if the proposal has a specific DH group.
105 *
106 * @param group group to check for
107 * @return TRUE if algorithm included
108 */
109 bool (*has_dh_group) (proposal_t *this, diffie_hellman_group_t group);
110
111 /**
112 * Strip DH groups from proposal to use it without PFS.
113 */
114 void (*strip_dh)(proposal_t *this);
115
116 /**
117 * Compare two proposal, and select a matching subset.
118 *
119 * If the proposals are for the same protocols (AH/ESP), they are
120 * compared. If they have at least one algorithm of each type
121 * in common, a resulting proposal of this kind is created.
122 *
123 * @param other proposal to compare against
124 * @param private accepts algorithms allocated in a private range
125 * @return selected proposal, NULL if proposals don't match
126 */
127 proposal_t *(*select) (proposal_t *this, proposal_t *other, bool private);
128
129 /**
130 * Get the protocol ID of the proposal.
131 *
132 * @return protocol of the proposal
133 */
134 protocol_id_t (*get_protocol) (proposal_t *this);
135
136 /**
137 * Get the SPI of the proposal.
138 *
139 * @return spi for proto
140 */
141 u_int64_t (*get_spi) (proposal_t *this);
142
143 /**
144 * Set the SPI of the proposal.
145 *
146 * @param spi spi to set for proto
147 */
148 void (*set_spi) (proposal_t *this, u_int64_t spi);
149
150 /**
151 * Get the proposal number, as encoded in SA payload
152 *
153 * @return proposal number
154 */
155 u_int (*get_number)(proposal_t *this);
156
157 /**
158 * Check for the eqality of two proposals.
159 *
160 * @param other other proposal to check for equality
161 * @return TRUE if other equal to this
162 */
163 bool (*equals)(proposal_t *this, proposal_t *other);
164
165 /**
166 * Clone a proposal.
167 *
168 * @return clone of proposal
169 */
170 proposal_t *(*clone) (proposal_t *this);
171
172 /**
173 * Destroys the proposal object.
174 */
175 void (*destroy) (proposal_t *this);
176 };
177
178 /**
179 * Create a child proposal for AH, ESP or IKE.
180 *
181 * @param protocol protocol, such as PROTO_ESP
182 * @param number proposal number, as encoded in SA payload
183 * @return proposal_t object
184 */
185 proposal_t *proposal_create(protocol_id_t protocol, u_int number);
186
187 /**
188 * Create a default proposal if nothing further specified.
189 *
190 * @param protocol protocol, such as PROTO_ESP
191 * @return proposal_t object
192 */
193 proposal_t *proposal_create_default(protocol_id_t protocol);
194
195 /**
196 * Create a proposal from a string identifying the algorithms.
197 *
198 * The string is in the same form as a in the ipsec.conf file.
199 * E.g.: aes128-sha2_256-modp2048
200 * 3des-md5
201 * An additional '!' at the end of the string forces this proposal,
202 * without it the peer may choose another algorithm we support.
203 *
204 * @param protocol protocol, such as PROTO_ESP
205 * @param algs algorithms as string
206 * @return proposal_t object
207 */
208 proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs);
209
210 /**
211 * printf hook function for proposal_t.
212 *
213 * Arguments are:
214 * proposal_t *proposal
215 * With the #-specifier, arguments are:
216 * linked_list_t *list containing proposal_t*
217 */
218 int proposal_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
219 const void *const *args);
220
221 #endif /** PROPOSAL_H_ @}*/