2 * Copyright (c) 2011, 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 * Attribute provider interface.
38 #define _UTIL_ATTR_H_ 1
44 #include <shibsp/remoting/ddf.h>
46 using namespace shibsp;
48 struct gss_eap_attr_provider;
49 struct gss_eap_attr_ctx;
52 (*gss_eap_attr_enumeration_cb)(const gss_eap_attr_provider *source,
53 const gss_buffer_t attribute,
56 #define ATTR_TYPE_RADIUS 0U /* RADIUS AVPs */
57 #define ATTR_TYPE_SAML_ASSERTION 1U /* SAML assertion */
58 #define ATTR_TYPE_SAML 2U /* SAML attributes */
59 #define ATTR_TYPE_LOCAL 3U /* Local attributes */
60 #define ATTR_TYPE_MIN ATTR_TYPE_RADIUS
61 #define ATTR_TYPE_MAX ATTR_TYPE_LOCAL
63 #define ATTR_FLAG_DISABLE_LOCAL 0x00000001
66 * Attribute provider: this represents a source of attributes derived
67 * from the security context.
69 struct gss_eap_attr_provider
72 gss_eap_attr_provider(void) {}
73 virtual ~gss_eap_attr_provider(void) {}
75 bool initWithManager(const gss_eap_attr_ctx *manager)
81 virtual bool initFromExistingContext(const gss_eap_attr_ctx *manager,
82 const gss_eap_attr_provider *ctx GSSEAP_UNUSED)
84 return initWithManager(manager);
87 virtual bool initFromGssContext(const gss_eap_attr_ctx *manager,
88 const gss_cred_id_t cred GSSEAP_UNUSED,
89 const gss_ctx_id_t ctx GSSEAP_UNUSED)
91 return initWithManager(manager);
94 virtual bool getAttributeTypes(gss_eap_attr_enumeration_cb GSSEAP_UNUSED,
95 void *data GSSEAP_UNUSED) const
100 virtual bool setAttribute(int complete GSSEAP_UNUSED,
101 const gss_buffer_t attr GSSEAP_UNUSED,
102 const gss_buffer_t value GSSEAP_UNUSED)
107 virtual bool deleteAttribute(const gss_buffer_t value GSSEAP_UNUSED)
112 virtual bool getAttribute(const gss_buffer_t attr GSSEAP_UNUSED,
113 int *authenticated GSSEAP_UNUSED,
114 int *complete GSSEAP_UNUSED,
115 gss_buffer_t value GSSEAP_UNUSED,
116 gss_buffer_t display_value GSSEAP_UNUSED,
117 int *more GSSEAP_UNUSED) const
122 virtual gss_any_t mapToAny(int authenticated GSSEAP_UNUSED,
123 gss_buffer_t type_id GSSEAP_UNUSED) const
127 virtual void releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
128 gss_any_t input GSSEAP_UNUSED) const
132 virtual bool unmarshallAndInit(const gss_eap_attr_ctx *manager,
133 DDF &object GSSEAP_UNUSED)
135 return initWithManager(manager);
138 virtual DDF marshall(void) const
143 virtual time_t getExpiryTime(void) const { return 0; }
145 virtual OM_uint32 mapException(OM_uint32 *minor GSSEAP_UNUSED,
146 std::exception &e GSSEAP_UNUSED) const
148 return GSS_S_CONTINUE_NEEDED;
151 static bool init(void) { return true; }
152 static void finalize(void) {}
154 static gss_eap_attr_provider *createAttrContext(void) { return NULL; }
157 const gss_eap_attr_ctx *m_manager;
160 /* make non-copyable */
161 gss_eap_attr_provider(const gss_eap_attr_provider&);
162 gss_eap_attr_provider& operator=(const gss_eap_attr_provider&);
165 typedef gss_eap_attr_provider *(*gss_eap_attr_create_provider)(void);
168 * Attribute context: this manages a set of providers for a given
171 struct gss_eap_attr_ctx
174 gss_eap_attr_ctx(void);
175 ~gss_eap_attr_ctx(void);
177 bool initFromExistingContext(const gss_eap_attr_ctx *manager);
178 bool initFromGssContext(const gss_cred_id_t cred,
179 const gss_ctx_id_t ctx);
181 bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
182 bool getAttributeTypes(gss_buffer_set_t *attrs);
184 bool setAttribute(int complete,
185 const gss_buffer_t attr,
186 const gss_buffer_t value);
187 bool deleteAttribute(const gss_buffer_t value);
188 bool getAttribute(const gss_buffer_t attr,
192 gss_buffer_t display_value,
194 gss_any_t mapToAny(int authenticated,
195 gss_buffer_t type_id) const;
196 void releaseAnyNameMapping(gss_buffer_t type_id,
197 gss_any_t input) const;
199 void exportToBuffer(gss_buffer_t buffer) const;
200 bool initFromBuffer(const gss_buffer_t buffer);
203 attributePrefixToType(const gss_buffer_t prefix);
205 static const gss_buffer_t
206 attributeTypeToPrefix(unsigned int type);
209 decomposeAttributeName(const gss_buffer_t attribute,
211 gss_buffer_t suffix);
213 composeAttributeName(const gss_buffer_t prefix,
214 const gss_buffer_t suffix,
215 gss_buffer_t attribute);
217 decomposeAttributeName(const gss_buffer_t attribute,
219 gss_buffer_t suffix);
221 composeAttributeName(unsigned int type,
222 const gss_buffer_t suffix,
223 gss_buffer_t attribute);
226 composeAttributeName(const gss_buffer_t prefix,
227 const gss_buffer_t suffix);
229 composeAttributeName(unsigned int type,
230 const gss_buffer_t suffix);
232 gss_eap_attr_provider *getProvider(unsigned int type) const;
233 gss_eap_attr_provider *getProvider(const gss_buffer_t prefix) const;
236 registerProvider(unsigned int type,
238 gss_eap_attr_create_provider factory);
240 unregisterProvider(unsigned int type);
242 time_t getExpiryTime(void) const;
243 OM_uint32 mapException(OM_uint32 *minor, std::exception &e) const;
246 bool providerEnabled(unsigned int type) const;
247 void releaseProvider(unsigned int type);
249 bool unmarshallAndInit(DDF &object);
250 DDF marshall(void) const;
252 gss_eap_attr_provider *getPrimaryProvider(void) const;
254 /* make non-copyable */
255 gss_eap_attr_ctx(const gss_eap_attr_ctx&);
256 gss_eap_attr_ctx& operator=(const gss_eap_attr_ctx&);
259 gss_eap_attr_provider *m_providers[ATTR_TYPE_MAX + 1];
262 #endif /* __cplusplus */
264 #include "util_radius.h"
265 #include "util_saml.h"
266 #include "util_shib.h"
271 duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
275 if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
276 throw new std::bad_alloc();
280 duplicateBuffer(std::string &str, gss_buffer_t buffer)
284 tmp.length = str.length();
285 tmp.value = (char *)str.c_str();
287 duplicateBuffer(tmp, buffer);
291 struct gss_eap_attr_ctx;
299 * C wrappers for attribute context functions. These match their
300 * GSS naming extension equivalents. The caller is required to
301 * obtain the name mutex.
305 gssEapCreateAttrContext(OM_uint32 *minor,
306 gss_cred_id_t acceptorCred,
307 gss_ctx_id_t acceptorCtx,
308 struct gss_eap_attr_ctx **pAttrCtx,
309 time_t *pExpiryTime);
312 gssEapInquireName(OM_uint32 *minor,
316 gss_buffer_set_t *attrs);
319 gssEapGetNameAttribute(OM_uint32 *minor,
325 gss_buffer_t display_value,
329 gssEapDeleteNameAttribute(OM_uint32 *minor,
334 gssEapSetNameAttribute(OM_uint32 *minor,
341 gssEapExportAttrContext(OM_uint32 *minor,
343 gss_buffer_t buffer);
346 gssEapImportAttrContext(OM_uint32 *minor,
351 gssEapDuplicateAttrContext(OM_uint32 *minor,
356 gssEapMapNameToAny(OM_uint32 *minor,
359 gss_buffer_t type_id,
363 gssEapReleaseAnyNameMapping(OM_uint32 *minor,
365 gss_buffer_t type_id,
369 gssEapReleaseAttrContext(OM_uint32 *minor,
373 gssEapAttrProvidersFinalize(OM_uint32 *minor);
379 #endif /* _UTIL_ATTR_H_ */