2 * Copyright (c) 2010, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * 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.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #define _UTIL_ATTR_H_ 1
39 struct gss_eap_attr_provider;
40 struct gss_eap_attr_ctx;
43 (*gss_eap_attr_enumeration_cb)(const gss_eap_attr_provider *source,
44 const gss_buffer_t attribute,
47 #define ATTR_TYPE_RADIUS 0U /* RADIUS AVPs */
48 #define ATTR_TYPE_SAML_ASSERTION 1U /* SAML assertion */
49 #define ATTR_TYPE_SAML 2U /* SAML attributes */
50 #define ATTR_TYPE_LOCAL 3U /* Local attributes */
51 #define ATTR_TYPE_MIN ATTR_TYPE_RADIUS
52 #define ATTR_TYPE_MAX ATTR_TYPE_LOCAL
54 #define ATTR_FLAG_DISABLE_LOCAL 0x00000001
57 * Attribute provider: this represents a source of attributes derived
58 * from the security context.
60 struct gss_eap_attr_provider
63 gss_eap_attr_provider(void) {}
64 virtual ~gss_eap_attr_provider(void) {}
66 bool initWithManager(const gss_eap_attr_ctx *manager)
72 virtual bool initFromExistingContext(const gss_eap_attr_ctx *manager,
73 const gss_eap_attr_provider *ctx)
75 return initWithManager(manager);
78 virtual bool initFromGssContext(const gss_eap_attr_ctx *manager,
79 const gss_cred_id_t cred,
80 const gss_ctx_id_t ctx)
82 return initWithManager(manager);
85 virtual bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const
90 virtual bool setAttribute(int complete,
91 const gss_buffer_t attr,
92 const gss_buffer_t value) { return false; }
93 virtual bool deleteAttribute(const gss_buffer_t value) { return false; }
94 virtual bool getAttribute(const gss_buffer_t attr,
98 gss_buffer_t display_value,
99 int *more) const { return false; }
101 virtual gss_any_t mapToAny(int authenticated,
102 gss_buffer_t type_id) const { return NULL; }
103 virtual void releaseAnyNameMapping(gss_buffer_t type_id,
104 gss_any_t input) const {}
106 virtual void exportToBuffer(gss_buffer_t buffer) const {}
107 virtual bool initFromBuffer(const gss_eap_attr_ctx *manager,
108 const gss_buffer_t buffer)
110 return initWithManager(manager);
113 virtual time_t getExpiryTime(void) const { return 0; }
115 static bool init(void) { return true; }
116 static void finalize(void) {}
118 static gss_eap_attr_provider *createAttrContext(void) { return NULL; }
121 const gss_eap_attr_ctx *m_manager;
124 /* make non-copyable */
125 gss_eap_attr_provider(const gss_eap_attr_provider&);
126 gss_eap_attr_provider& operator=(const gss_eap_attr_provider&);
129 typedef gss_eap_attr_provider *(*gss_eap_attr_create_provider)(void);
132 * Attribute context: this manages a set of providers for a given
135 struct gss_eap_attr_ctx
138 gss_eap_attr_ctx(void);
139 ~gss_eap_attr_ctx(void);
141 bool initFromExistingContext(const gss_eap_attr_ctx *manager);
142 bool initFromGssContext(const gss_cred_id_t cred,
143 const gss_ctx_id_t ctx);
145 bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
146 bool getAttributeTypes(gss_buffer_set_t *attrs);
148 bool setAttribute(int complete,
149 const gss_buffer_t attr,
150 const gss_buffer_t value);
151 bool deleteAttribute(const gss_buffer_t value);
152 bool getAttribute(const gss_buffer_t attr,
156 gss_buffer_t display_value,
158 gss_any_t mapToAny(int authenticated,
159 gss_buffer_t type_id) const;
160 void releaseAnyNameMapping(gss_buffer_t type_id,
161 gss_any_t input) const;
163 void exportToBuffer(gss_buffer_t buffer) const;
164 bool initFromBuffer(const gss_buffer_t buffer);
167 attributePrefixToType(const gss_buffer_t prefix);
169 static const gss_buffer_t
170 attributeTypeToPrefix(unsigned int type);
173 decomposeAttributeName(const gss_buffer_t attribute,
175 gss_buffer_t suffix);
177 composeAttributeName(const gss_buffer_t prefix,
178 const gss_buffer_t suffix,
179 gss_buffer_t attribute);
181 decomposeAttributeName(const gss_buffer_t attribute,
183 gss_buffer_t suffix);
185 composeAttributeName(unsigned int type,
186 const gss_buffer_t suffix,
187 gss_buffer_t attribute);
190 composeAttributeName(const gss_buffer_t prefix,
191 const gss_buffer_t suffix);
193 composeAttributeName(unsigned int type,
194 const gss_buffer_t suffix);
196 gss_eap_attr_provider *getProvider(unsigned int type) const;
197 gss_eap_attr_provider *getProvider(const gss_buffer_t prefix) const;
200 registerProvider(unsigned int type,
202 gss_eap_attr_create_provider factory);
204 unregisterProvider(unsigned int type);
206 time_t getExpiryTime(void) const;
209 bool providerEnabled(unsigned int type) const;
210 void releaseProvider(unsigned int type);
212 gss_eap_attr_provider *getPrimaryProvider(void) const;
214 /* make non-copyable */
215 gss_eap_attr_ctx(const gss_eap_attr_ctx&);
216 gss_eap_attr_ctx& operator=(const gss_eap_attr_ctx&);
219 gss_eap_attr_provider *m_providers[ATTR_TYPE_MAX + 1];
222 #endif /* __cplusplus */
224 #include "util_radius.h"
225 #include "util_saml.h"
226 #include "util_shib.h"
234 duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
238 if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
239 throw new std::bad_alloc();
243 duplicateBuffer(std::string &str, gss_buffer_t buffer)
247 tmp.length = str.length();
248 tmp.value = (char *)str.c_str();
250 duplicateBuffer(tmp, buffer);
254 struct gss_eap_attr_ctx;
262 * C wrappers for attribute context functions. These match their
263 * GSS naming extension equivalents. The caller is required to
264 * obtain the name mutex.
267 struct gss_eap_attr_ctx *
268 gssEapCreateAttrContext(gss_cred_id_t acceptorCred,
269 gss_ctx_id_t acceptorCtx);
272 gssEapInquireName(OM_uint32 *minor,
276 gss_buffer_set_t *attrs);
279 gssEapGetNameAttribute(OM_uint32 *minor,
285 gss_buffer_t display_value,
289 gssEapDeleteNameAttribute(OM_uint32 *minor,
294 gssEapSetNameAttribute(OM_uint32 *minor,
301 gssEapExportAttrContext(OM_uint32 *minor,
303 gss_buffer_t buffer);
306 gssEapImportAttrContext(OM_uint32 *minor,
311 gssEapDuplicateAttrContext(OM_uint32 *minor,
316 gssEapMapNameToAny(OM_uint32 *minor,
319 gss_buffer_t type_id,
323 gssEapReleaseAnyNameMapping(OM_uint32 *minor,
325 gss_buffer_t type_id,
329 gssEapReleaseAttrContext(OM_uint32 *minor,
333 gssEapAttrProvidersFinalize(OM_uint32 *minor);
339 #endif /* _UTIL_ATTR_H_ */