30796bd56ce46473025ae4840ea5556810b8d5fe
[strongswan.git] / Source / lib / utils / identification.h
1 /**
2 * @file identification.h
3 *
4 * @brief Interface of identification_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23
24 #ifndef IDENTIFICATION_H_
25 #define IDENTIFICATION_H_
26
27
28 #include "types.h"
29
30 typedef enum id_type_t id_type_t;
31
32 /**
33 * @brief ID Types in a ID payload.
34 *
35 * @see
36 * - identification_t
37 * - id_payload_t
38 *
39 * @ingroup utils
40 */
41 enum id_type_t {
42
43 /**
44 * ID data is a single four (4) octet IPv4 address.
45 */
46 ID_IPV4_ADDR = 1,
47
48 /**
49 * ID data is a fully-qualified domain name string.
50 * An example of a ID_FQDN is, "example.com".
51 * The string MUST not contain any terminators (e.g., NULL, CR, etc.).
52 */
53 ID_FQDN = 2,
54
55 /**
56 * ID data is a fully-qualified RFC822 email address string, An example of
57 * a ID_RFC822_ADDR is, "jsmith@example.com". The string MUST
58 * not contain any terminators.
59 */
60 ID_RFC822_ADDR = 3,
61
62 /**
63 * ID data is a single sixteen (16) octet IPv6 address.
64 */
65 ID_IPV6_ADDR = 5,
66
67 /**
68 * ID data is the binary DER encoding of an ASN.1 X.500 Distinguished Name
69 * [X.501].
70 */
71 ID_DER_ASN1_DN = 9,
72
73 /**
74 * ID data is the binary DER encoding of an ASN.1 X.500 GeneralName
75 * [X.509].
76 */
77 ID_DER_ASN1_GN = 10,
78
79 /**
80 * ID data is an opaque octet stream which may be used to pass vendor-
81 * specific information necessary to do certain proprietary
82 * types of identification.
83 */
84 ID_KEY_ID = 11
85 };
86
87 /**
88 * Old pluto id format
89 *
90 * @deprecated Do not use any more, only here for pluto.
91 */
92 // struct id {
93 // /** ID_* value, pluto pendant to id_type_t */
94 // int kind;
95 // /** ID_IPV4_ADDR, ID_IPV6_ADDR */
96 // ip_address ip_addr;
97 // /** ID_FQDN, ID_USER_FQDN (with @) */
98 // /** ID_KEY_ID, ID_DER_ASN_DN */
99 // chunk_t name;
100 // };
101
102 /**
103 * String mappings for id_type_t.
104 */
105 extern mapping_t id_type_m[];
106
107 typedef struct identification_t identification_t;
108
109 /**
110 * @brief Generic identification, such as used in ID payload.
111 *
112 * The following types are possible:
113 * - ID_IPV4_ADDR
114 * - ID_FQDN*
115 * - ID_RFC822_ADDR*
116 * - ID_IPV6_ADDR*
117 * - ID_DER_ASN1_DN*
118 * - ID_DER_ASN1_GN*
119 * - ID_KEY_ID*
120 * (* = string conversion not supported)
121 *
122 * @b Constructors:
123 * - identification_create_from_string()
124 * - identification_create_from_encoding()
125 *
126 * @todo Support for other ID types then ID_IPV4_ADDR.
127 *
128 * @ingroup utils
129 */
130 struct identification_t {
131
132 /**
133 * @brief Get the encoding of this id, to send over
134 * the network.
135 *
136 * @warning Result points to internal data, do NOT free!
137 *
138 * @param this the identification_t object
139 * @return a chunk containing the encoded bytes
140 */
141 chunk_t (*get_encoding) (identification_t *this);
142
143 /**
144 * @brief Get the type of this identification.
145 *
146 * @param this the identification_t object
147 * @return id_type_t
148 */
149 id_type_t (*get_type) (identification_t *this);
150
151 /**
152 * @brief Get a string representation of this id.
153 *
154 * @warning Result points to internal data, do NOT free!
155 *
156 * @param this the identification_t object
157 * @return string
158 */
159 char *(*get_string) (identification_t *this);
160
161 /**
162 * @brief Get the id in the format used in pluto.
163 *
164 * We do this in pluto style here, which means no memory
165 * is allocated.
166 *
167 * @param this the identification_t object
168 * @return string
169 */
170 // void (*get_pluto_id) (identification_t *this, struct id *pluto_id);
171
172 /**
173 * @brief Check if two identification_t objects are equal.
174 *
175 * @param this the identification_t object
176 * @param other other identification_t object
177 * @return TRUE if the IDs are equal
178 */
179 bool (*equals) (identification_t *this,identification_t *other);
180
181 /**
182 * @brief Check if an ID belongs to a wildcard ID.
183 *
184 * An identification_t may contain wildcards, such as
185 * *@strongswan.org. This call checks if a given ID
186 * (e.g. tester@strongswan.org) belongs to a such wildcard
187 * ID. Returns TRUE if IDs are identical.
188 *
189 * @param this the ID containing a wildcard
190 * @param other the ID without wildcard
191 * @return TRUE if other belongs to this
192 */
193 bool (*belongs_to) (identification_t *this, identification_t *other);
194
195 /**
196 * @brief Clone a identification_t instance.
197 *
198 * @param this the identification_t object to clone
199 * @return clone of this
200 */
201 identification_t *(*clone) (identification_t *this);
202
203 /**
204 * @brief Destroys a identification_t object.
205 *
206 * @param this identification_t object
207 */
208 void (*destroy) (identification_t *this);
209 };
210
211 /**
212 * @brief Creates an identification_t object from a string.
213 *
214 * @param type type of this id, such as ID_IPV4_ADDR
215 * @param string input string, which will be converted
216 * @return
217 * - created identification_t object, or
218 * - NULL if type not supported.
219 *
220 * @ingroup utils
221 */
222 identification_t * identification_create_from_string(id_type_t type, char *string);
223
224 /**
225 * @brief Creates an identification_t object from an encoded chunk.
226 *
227 * @param type type of this id, such as ID_IPV4_ADDR
228 * @param encoded encoded bytes, such as from identification_t.get_encoding
229 * @return identification_t object
230 *
231 * @ingroup utils
232 */
233 identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
234
235 /**
236 * @brief Creates an identification_t object from the old pluto id format.
237 *
238 * Pluto uses struct id for identification stuff. Since we need to convert from
239 * this format to our identification_t, we need this special constructor.
240 *
241 * @param id old pluto format id
242 * @return identification_t object
243 *
244 * @ingroup utils
245 */
246 // identification_t * identification_create_from_pluto_id(struct id *pluto_id);
247
248
249 #endif /* IDENTIFICATION_H_ */