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_ctx *ctx,
53 const gss_eap_attr_provider *source,
54 const gss_buffer_t attribute,
57 #define ATTR_TYPE_RADIUS 0U /* RADIUS AVPs */
58 #define ATTR_TYPE_SAML_ASSERTION 1U /* SAML assertion */
59 #define ATTR_TYPE_SAML 2U /* SAML attributes */
60 #define ATTR_TYPE_LOCAL 3U /* Local attributes */
61 #define ATTR_TYPE_MIN ATTR_TYPE_RADIUS
62 #define ATTR_TYPE_MAX ATTR_TYPE_LOCAL
64 #define ATTR_FLAG_DISABLE_LOCAL 0x00000001
67 * Attribute provider: this represents a source of attributes derived
68 * from the security context.
70 struct gss_eap_attr_provider
73 gss_eap_attr_provider(void) {}
74 virtual ~gss_eap_attr_provider(void) {}
76 bool initWithManager(const gss_eap_attr_ctx *manager)
82 virtual bool initFromExistingContext(const gss_eap_attr_ctx *manager,
83 const gss_eap_attr_provider *ctx GSSEAP_UNUSED)
85 return initWithManager(manager);
88 virtual bool initFromGssContext(const gss_eap_attr_ctx *manager,
89 const gss_cred_id_t cred GSSEAP_UNUSED,
90 const gss_ctx_id_t ctx GSSEAP_UNUSED)
92 return initWithManager(manager);
95 virtual bool getAttributeTypes(gss_eap_attr_enumeration_cb GSSEAP_UNUSED,
96 void *data GSSEAP_UNUSED) const
101 virtual bool setAttribute(int complete GSSEAP_UNUSED,
102 const gss_buffer_t attr GSSEAP_UNUSED,
103 const gss_buffer_t value GSSEAP_UNUSED)
108 virtual bool deleteAttribute(const gss_buffer_t value GSSEAP_UNUSED)
113 virtual bool getAttribute(const gss_buffer_t attr GSSEAP_UNUSED,
114 int *authenticated GSSEAP_UNUSED,
115 int *complete GSSEAP_UNUSED,
116 gss_buffer_t value GSSEAP_UNUSED,
117 gss_buffer_t display_value GSSEAP_UNUSED,
118 int *more GSSEAP_UNUSED) const
123 virtual gss_any_t mapToAny(int authenticated GSSEAP_UNUSED,
124 gss_buffer_t type_id GSSEAP_UNUSED) const
129 virtual void releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
130 gss_any_t input GSSEAP_UNUSED) const
134 virtual const char *prefix(void) const
139 virtual const char *marshallingKey(void) const
144 virtual bool unmarshallAndInit(const gss_eap_attr_ctx *manager,
145 DDF &object GSSEAP_UNUSED)
147 return initWithManager(manager);
150 virtual DDF marshall(void) const
155 virtual time_t getExpiryTime(void) const { return 0; }
157 virtual OM_uint32 mapException(OM_uint32 *minor GSSEAP_UNUSED,
158 std::exception &e GSSEAP_UNUSED) const
160 return GSS_S_CONTINUE_NEEDED;
163 static bool init(void) { return true; }
164 static void finalize(void) {}
166 static gss_eap_attr_provider *createAttrContext(void) { return NULL; }
169 const gss_eap_attr_ctx *m_manager;
172 /* make non-copyable */
173 gss_eap_attr_provider(const gss_eap_attr_provider&);
174 gss_eap_attr_provider& operator=(const gss_eap_attr_provider&);
177 typedef gss_eap_attr_provider *(*gss_eap_attr_create_provider)(void);
180 * Attribute context: this manages a set of providers for a given
183 struct gss_eap_attr_ctx
186 gss_eap_attr_ctx(void);
187 ~gss_eap_attr_ctx(void);
189 bool initFromExistingContext(const gss_eap_attr_ctx *manager);
190 bool initFromGssContext(const gss_cred_id_t cred,
191 const gss_ctx_id_t ctx);
193 bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
194 bool getAttributeTypes(gss_buffer_set_t *attrs);
196 bool setAttribute(int complete,
197 const gss_buffer_t attr,
198 const gss_buffer_t value);
199 bool deleteAttribute(const gss_buffer_t value);
200 bool getAttribute(const gss_buffer_t attr,
204 gss_buffer_t display_value,
206 gss_any_t mapToAny(int authenticated,
207 gss_buffer_t type_id) const;
208 void releaseAnyNameMapping(gss_buffer_t type_id,
209 gss_any_t input) const;
211 void exportToBuffer(gss_buffer_t buffer) const;
212 bool initFromBuffer(const gss_buffer_t buffer);
215 composeAttributeName(const gss_buffer_t prefix,
216 const gss_buffer_t suffix);
218 decomposeAttributeName(const gss_buffer_t attribute,
220 gss_buffer_t suffix);
222 composeAttributeName(const gss_buffer_t prefix,
223 const gss_buffer_t suffix,
224 gss_buffer_t attribute);
227 composeAttributeName(unsigned int type,
228 const gss_buffer_t suffix);
230 decomposeAttributeName(const gss_buffer_t attribute,
232 gss_buffer_t suffix) const;
234 composeAttributeName(unsigned int type,
235 const gss_buffer_t suffix,
236 gss_buffer_t attribute) const;
238 gss_eap_attr_provider *getProvider(unsigned int type) const;
241 registerProvider(unsigned int type,
242 gss_eap_attr_create_provider factory);
244 unregisterProvider(unsigned int type);
246 time_t getExpiryTime(void) const;
247 OM_uint32 mapException(OM_uint32 *minor, std::exception &e) const;
250 bool providerEnabled(unsigned int type) const;
251 void releaseProvider(unsigned int type);
253 unsigned int attributePrefixToType(const gss_buffer_t prefix) const;
254 gss_buffer_desc attributeTypeToPrefix(unsigned int type) const;
256 bool unmarshallAndInit(DDF &object);
257 DDF marshall(void) const;
259 gss_eap_attr_provider *getPrimaryProvider(void) const;
261 /* make non-copyable */
262 gss_eap_attr_ctx(const gss_eap_attr_ctx&);
263 gss_eap_attr_ctx& operator=(const gss_eap_attr_ctx&);
266 gss_eap_attr_provider *m_providers[ATTR_TYPE_MAX + 1];
269 #endif /* __cplusplus */
271 #include "util_radius.h"
272 #include "util_saml.h"
273 #include "util_shib.h"
278 duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
282 if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
283 throw new std::bad_alloc();
287 duplicateBuffer(std::string &str, gss_buffer_t buffer)
291 tmp.length = str.length();
292 tmp.value = (char *)str.c_str();
294 duplicateBuffer(tmp, buffer);
298 struct gss_eap_attr_ctx;
306 * C wrappers for attribute context functions. These match their
307 * GSS naming extension equivalents. The caller is required to
308 * obtain the name mutex.
312 gssEapCreateAttrContext(OM_uint32 *minor,
313 gss_cred_id_t acceptorCred,
314 gss_ctx_id_t acceptorCtx,
315 struct gss_eap_attr_ctx **pAttrCtx,
316 time_t *pExpiryTime);
319 gssEapInquireName(OM_uint32 *minor,
323 gss_buffer_set_t *attrs);
326 gssEapGetNameAttribute(OM_uint32 *minor,
332 gss_buffer_t display_value,
336 gssEapDeleteNameAttribute(OM_uint32 *minor,
341 gssEapSetNameAttribute(OM_uint32 *minor,
348 gssEapExportAttrContext(OM_uint32 *minor,
350 gss_buffer_t buffer);
353 gssEapImportAttrContext(OM_uint32 *minor,
358 gssEapDuplicateAttrContext(OM_uint32 *minor,
363 gssEapMapNameToAny(OM_uint32 *minor,
366 gss_buffer_t type_id,
370 gssEapReleaseAnyNameMapping(OM_uint32 *minor,
372 gss_buffer_t type_id,
376 gssEapReleaseAttrContext(OM_uint32 *minor,
380 gssEapAttrProvidersFinalize(OM_uint32 *minor);
386 #endif /* _UTIL_ATTR_H_ */