fixed typo
[strongswan.git] / src / libstrongswan / utils / identification.h
1 /**
2 * @file identification.h
3 *
4 * @brief Interface of identification_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24
25 #ifndef IDENTIFICATION_H_
26 #define IDENTIFICATION_H_
27
28 typedef enum id_type_t id_type_t;
29 typedef struct identification_t identification_t;
30
31 #include <library.h>
32
33 #define MAX_WILDCARDS 14
34
35 /**
36 * @brief ID Types in a ID payload.
37 *
38 * @ingroup utils
39 */
40 enum id_type_t {
41
42 /**
43 * private type which matches any other id.
44 */
45 ID_ANY = 0,
46
47 /**
48 * ID data is a single four (4) octet IPv4 address.
49 */
50 ID_IPV4_ADDR = 1,
51
52 /**
53 * ID data is a fully-qualified domain name string.
54 * An example of a ID_FQDN is "example.com".
55 * The string MUST not contain any terminators (e.g., NULL, CR, etc.).
56 */
57 ID_FQDN = 2,
58
59 /**
60 * ID data is a fully-qualified RFC822 email address string.
61 * An example of an ID_RFC822_ADDR is "jsmith@example.com".
62 * The string MUST NOT contain any terminators.
63 */
64 ID_RFC822_ADDR = 3,
65
66 /**
67 * ID data is an IPv4 subnet (IKEv1 only)
68 */
69 ID_IPV4_ADDR_SUBNET = 4,
70
71 /**
72 * ID data is a single sixteen (16) octet IPv6 address.
73 */
74 ID_IPV6_ADDR = 5,
75
76 /**
77 * ID data is an IPv6 subnet (IKEv1 only)
78 */
79 ID_IPV6_ADDR_SUBNET = 6,
80
81 /**
82 * ID data is an IPv4 address range (IKEv1 only)
83 */
84 ID_IPV4_ADDR_RANGE = 7,
85
86 /**
87 * ID data is an IPv6 address range (IKEv1 only)
88 */
89 ID_IPV6_ADDR_RANGE = 8,
90
91 /**
92 * ID data is the binary DER encoding of an ASN.1 X.501 Distinguished Name
93 */
94 ID_DER_ASN1_DN = 9,
95
96 /**
97 * ID data is the binary DER encoding of an ASN.1 X.509 GeneralName
98 */
99 ID_DER_ASN1_GN = 10,
100
101 /**
102 * ID data is an opaque octet stream which may be used to pass vendor-
103 * specific information necessary to do certain proprietary
104 * types of identification.
105 */
106 ID_KEY_ID = 11,
107
108 /**
109 * private type which represents a GeneralName of type URI
110 */
111 ID_DER_ASN1_GN_URI = 201,
112
113 };
114
115 /**
116 * enum names for id_type_t.
117 */
118 extern enum_name_t *id_type_names;
119
120 /**
121 * @brief Generic identification, such as used in ID payload.
122 *
123 * The following types are possible:
124 * - ID_IPV4_ADDR
125 * - ID_FQDN
126 * - ID_RFC822_ADDR
127 * - ID_IPV6_ADDR
128 * - ID_DER_ASN1_DN
129 * - ID_DER_ASN1_GN
130 * - ID_KEY_ID
131 * - ID_DER_ASN1_GN_URI
132 *
133 * @b Constructors:
134 * - identification_create_from_string()
135 * - identification_create_from_encoding()
136 *
137 * @todo Support for ID_DER_ASN1_GN is minimal right now. Comparison
138 * between them and ID_IPV4_ADDR/RFC822_ADDR would be nice.
139 *
140 * @ingroup utils
141 */
142 struct identification_t {
143
144 /**
145 * @brief Get the encoding of this id, to send over
146 * the network.
147 *
148 * @warning Result points to internal data, do NOT free!
149 *
150 * @param this the identification_t object
151 * @return a chunk containing the encoded bytes
152 */
153 chunk_t (*get_encoding) (identification_t *this);
154
155 /**
156 * @brief Get the type of this identification.
157 *
158 * @param this the identification_t object
159 * @return id_type_t
160 */
161 id_type_t (*get_type) (identification_t *this);
162
163 /**
164 * @brief Check if two identification_t objects are equal.
165 *
166 * @param this the identification_t object
167 * @param other other identification_t object
168 * @return TRUE if the IDs are equal
169 */
170 bool (*equals) (identification_t *this, identification_t *other);
171
172 /**
173 * @brief Check if an ID matches a wildcard ID.
174 *
175 * An identification_t may contain wildcards, such as
176 * *@strongswan.org. This call checks if a given ID
177 * (e.g. tester@strongswan.org) belongs to a such wildcard
178 * ID. Returns TRUE if
179 * - IDs are identical
180 * - other is of type ID_ANY
181 * - other contains a wildcard and matches this
182 *
183 * @param this the ID without wildcard
184 * @param other the ID containing a wildcard
185 * @param wildcards returns the number of wildcards, may be NULL
186 * @return TRUE if match is found
187 */
188 bool (*matches) (identification_t *this, identification_t *other, int *wildcards);
189
190 /**
191 * @brief Check if an ID is a wildcard ID.
192 *
193 * If the ID represents multiple IDs (with wildcards, or
194 * as the type ID_ANY), TRUE is returned. If it is unique,
195 * FALSE is returned.
196 *
197 * @param this identification_t object
198 * @return TRUE if ID contains wildcards
199 */
200 bool (*contains_wildcards) (identification_t *this);
201
202 /**
203 * @brief Clone a identification_t instance.
204 *
205 * @param this the identification_t object to clone
206 * @return clone of this
207 */
208 identification_t *(*clone) (identification_t *this);
209
210 /**
211 * @brief Destroys a identification_t object.
212 *
213 * @param this identification_t object
214 */
215 void (*destroy) (identification_t *this);
216 };
217
218 /**
219 * @brief Creates an identification_t object from a string.
220 *
221 * @param string input string, which will be converted
222 * @return
223 * - created identification_t object, or
224 * - NULL if unsupported string supplied.
225 *
226 * The input string may be e.g. one of the following:
227 * - ID_IPV4_ADDR: 192.168.0.1
228 * - ID_IPV6_ADDR: 2001:0db8:85a3:08d3:1319:8a2e:0370:7345
229 * - ID_FQDN: @www.strongswan.org (@indicates FQDN)
230 * - ID_RFC822_ADDR: alice@wonderland.org
231 * - ID_DER_ASN1_DN: C=CH, O=Linux strongSwan, CN=bob
232 *
233 * In favour of pluto, domainnames are prepended with an @, since
234 * pluto resolves domainnames without an @ to IPv4 addresses. Since
235 * we use a seperate host_t class for addresses, this doesn't
236 * make sense for us.
237 *
238 * A distinguished name may contain one or more of the following RDNs:
239 * ND, UID, DC, CN, S, SN, serialNumber, C, L, ST, O, OU, T, D,
240 * N, G, I, ID, EN, EmployeeNumber, E, Email, emailAddress, UN,
241 * unstructuredName, TCGID.
242 *
243 * @ingroup utils
244 */
245 identification_t * identification_create_from_string(char *string);
246
247 /**
248 * @brief Creates an identification_t object from an encoded chunk.
249 *
250 * @param type type of this id, such as ID_IPV4_ADDR
251 * @param encoded encoded bytes, such as from identification_t.get_encoding
252 * @return identification_t object
253 *
254 * In contrast to identification_create_from_string(), this constructor never
255 * returns NULL, even when the conversion to a string representation fails.
256 *
257 * @ingroup utils
258 */
259 identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
260
261 #endif /* IDENTIFICATION_H_ */