2 * @file identification.h
4 * @brief Interface of identification_t.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
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>.
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
25 #ifndef IDENTIFICATION_H_
26 #define IDENTIFICATION_H_
28 typedef enum id_type_t id_type_t
;
29 typedef struct identification_t identification_t
;
33 #define MAX_WILDCARDS 14
36 * @brief ID Types in a ID payload.
43 * private type which matches any other id.
48 * ID data is a single four (4) octet IPv4 address.
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.).
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.
67 * ID data is an IPv4 subnet (IKEv1 only)
69 ID_IPV4_ADDR_SUBNET
= 4,
72 * ID data is a single sixteen (16) octet IPv6 address.
77 * ID data is an IPv6 subnet (IKEv1 only)
79 ID_IPV6_ADDR_SUBNET
= 6,
82 * ID data is an IPv4 address range (IKEv1 only)
84 ID_IPV4_ADDR_RANGE
= 7,
87 * ID data is an IPv6 address range (IKEv1 only)
89 ID_IPV6_ADDR_RANGE
= 8,
92 * ID data is the binary DER encoding of an ASN.1 X.501 Distinguished Name
97 * ID data is the binary DER encoding of an ASN.1 X.509 GeneralName
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.
109 * private type which represents a GeneralName of type URI
111 ID_DER_ASN1_GN_URI
= 201,
116 * enum names for id_type_t.
118 extern enum_name_t
*id_type_names
;
121 * @brief Generic identification, such as used in ID payload.
123 * The following types are possible:
131 * - ID_DER_ASN1_GN_URI
134 * - identification_create_from_string()
135 * - identification_create_from_encoding()
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.
142 struct identification_t
{
145 * @brief Get the encoding of this id, to send over
148 * @warning Result points to internal data, do NOT free!
150 * @param this the identification_t object
151 * @return a chunk containing the encoded bytes
153 chunk_t (*get_encoding
) (identification_t
*this);
156 * @brief Get the type of this identification.
158 * @param this the identification_t object
161 id_type_t (*get_type
) (identification_t
*this);
164 * @brief Check if two identification_t objects are equal.
166 * @param this the identification_t object
167 * @param other other identification_t object
168 * @return TRUE if the IDs are equal
170 bool (*equals
) (identification_t
*this, identification_t
*other
);
173 * @brief Check if an ID matches a wildcard ID.
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
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
188 bool (*matches
) (identification_t
*this, identification_t
*other
, int *wildcards
);
191 * @brief Check if an ID is a wildcard ID.
193 * If the ID represents multiple IDs (with wildcards, or
194 * as the type ID_ANY), TRUE is returned. If it is unique,
197 * @param this identification_t object
198 * @return TRUE if ID contains wildcards
200 bool (*contains_wildcards
) (identification_t
*this);
203 * @brief Clone a identification_t instance.
205 * @param this the identification_t object to clone
206 * @return clone of this
208 identification_t
*(*clone
) (identification_t
*this);
211 * @brief Destroys a identification_t object.
213 * @param this identification_t object
215 void (*destroy
) (identification_t
*this);
219 * @brief Creates an identification_t object from a string.
221 * @param string input string, which will be converted
223 * - created identification_t object, or
224 * - NULL if unsupported string supplied.
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
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
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.
245 identification_t
* identification_create_from_string(char *string
);
248 * @brief Creates an identification_t object from an encoded chunk.
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
254 * In contrast to identification_create_from_string(), this constructor never
255 * returns NULL, even when the conversion to a string representation fails.
259 identification_t
* identification_create_from_encoding(id_type_t type
, chunk_t encoded
);
261 #endif /* IDENTIFICATION_H_ */