util_saml: correctly account for gss lengths
[mech_eap.orig] / util_saml.cpp
1 /*
2  * Copyright (c) 2011, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
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.
15  *
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.
19  *
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
30  * SUCH DAMAGE.
31  */
32
33 /*
34  * SAML attribute provider implementation.
35  */
36
37 #include "gssapiP_eap.h"
38
39 #include <sstream>
40
41 #include <xercesc/util/XMLUniDefs.hpp>
42 #include <xmltooling/unicode.h>
43 #include <xmltooling/XMLToolingConfig.h>
44 #include <xmltooling/util/XMLHelper.h>
45 #include <xmltooling/util/ParserPool.h>
46 #include <xmltooling/util/DateTime.h>
47
48 #include <saml/exceptions.h>
49 #include <saml/saml1/core/Assertions.h>
50 #include <saml/saml2/core/Assertions.h>
51 #include <saml/saml2/metadata/Metadata.h>
52 #include <saml/saml2/metadata/MetadataProvider.h>
53
54 using namespace xmltooling;
55 using namespace opensaml::saml2md;
56 using namespace opensaml;
57 using namespace xercesc;
58 using namespace std;
59
60 /*
61  * gss_eap_saml_assertion_provider is for retrieving the underlying
62  * assertion.
63  */
64 gss_eap_saml_assertion_provider::gss_eap_saml_assertion_provider(void)
65 {
66     m_assertion = NULL;
67     m_authenticated = false;
68 }
69
70 gss_eap_saml_assertion_provider::~gss_eap_saml_assertion_provider(void)
71 {
72     delete m_assertion;
73 }
74
75 bool
76 gss_eap_saml_assertion_provider::initFromExistingContext(const gss_eap_attr_ctx *manager,
77                                                          const gss_eap_attr_provider *ctx)
78 {
79     /* Then we may be creating from an existing attribute context */
80     const gss_eap_saml_assertion_provider *saml;
81
82     assert(m_assertion == NULL);
83
84     if (!gss_eap_attr_provider::initFromExistingContext(manager, ctx))
85         return false;
86
87     saml = static_cast<const gss_eap_saml_assertion_provider *>(ctx);
88     setAssertion(saml->getAssertion(), saml->authenticated());
89
90     return true;
91 }
92
93 bool
94 gss_eap_saml_assertion_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
95                                                     const gss_cred_id_t gssCred,
96                                                     const gss_ctx_id_t gssCtx)
97 {
98     const gss_eap_radius_attr_provider *radius;
99     gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
100     int authenticated, complete;
101     OM_uint32 minor;
102
103     assert(m_assertion == NULL);
104
105     if (!gss_eap_attr_provider::initFromGssContext(manager, gssCred, gssCtx))
106         return false;
107
108     /*
109      * XXX TODO we need to support draft-howlett-radius-saml-attr-00
110      */
111     radius = static_cast<const gss_eap_radius_attr_provider *>
112         (m_manager->getProvider(ATTR_TYPE_RADIUS));
113     if (radius != NULL &&
114         radius->getFragmentedAttribute(PW_SAML_AAA_ASSERTION,
115                                        VENDORPEC_UKERNA,
116                                        &authenticated, &complete, &value)) {
117         setAssertion(&value, authenticated);
118         gss_release_buffer(&minor, &value);
119     } else {
120         m_assertion = NULL;
121     }
122
123     return true;
124 }
125
126 void
127 gss_eap_saml_assertion_provider::setAssertion(const saml2::Assertion *assertion,
128                                               bool authenticated)
129 {
130
131     delete m_assertion;
132
133     if (assertion != NULL) {
134 #ifdef __APPLE__
135         m_assertion = (saml2::Assertion *)((void *)assertion->clone());
136 #else
137         m_assertion = dynamic_cast<saml2::Assertion *>(assertion->clone());
138 #endif
139         m_authenticated = authenticated;
140     } else {
141         m_assertion = NULL;
142         m_authenticated = false;
143     }
144 }
145
146 void
147 gss_eap_saml_assertion_provider::setAssertion(const gss_buffer_t buffer,
148                                               bool authenticated)
149 {
150     delete m_assertion;
151
152     m_assertion = parseAssertion(buffer);
153     m_authenticated = (m_assertion != NULL && authenticated);
154 }
155
156 saml2::Assertion *
157 gss_eap_saml_assertion_provider::parseAssertion(const gss_buffer_t buffer)
158 {
159     string str((char *)buffer->value, buffer->length);
160     istringstream istream(str);
161     DOMDocument *doc;
162     const XMLObjectBuilder *b;
163
164     try {
165         doc = XMLToolingConfig::getConfig().getParser().parse(istream);
166         if (doc == NULL)
167             return NULL;
168
169         b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
170
171 #ifdef __APPLE__
172         return (saml2::Assertion *)((void *)b->buildFromDocument(doc));
173 #else
174         return dynamic_cast<saml2::Assertion *>(b->buildFromDocument(doc));
175 #endif
176     } catch (exception &e) {
177         return NULL;
178     }
179 }
180
181 bool
182 gss_eap_saml_assertion_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
183                                                    void *data) const
184 {
185     bool ret;
186
187     /* just add the prefix */
188     if (m_assertion != NULL)
189         ret = addAttribute(this, GSS_C_NO_BUFFER, data);
190     else
191         ret = true;
192
193     return ret;
194 }
195
196 bool
197 gss_eap_saml_assertion_provider::setAttribute(int complete GSSEAP_UNUSED,
198                                               const gss_buffer_t attr,
199                                               const gss_buffer_t value)
200 {
201     if (attr == GSS_C_NO_BUFFER || attr->length == 0) {
202         setAssertion(value);
203         return true;
204     }
205
206     return false;
207 }
208
209 bool
210 gss_eap_saml_assertion_provider::deleteAttribute(const gss_buffer_t value GSSEAP_UNUSED)
211 {
212     delete m_assertion;
213     m_assertion = NULL;
214     m_authenticated = false;
215
216     return true;
217 }
218
219 time_t
220 gss_eap_saml_assertion_provider::getExpiryTime(void) const
221 {
222     saml2::Conditions *conditions;
223     time_t expiryTime = 0;
224
225     if (m_assertion == NULL)
226         return 0;
227
228     conditions = m_assertion->getConditions();
229
230     if (conditions != NULL && conditions->getNotOnOrAfter() != NULL)
231         expiryTime = conditions->getNotOnOrAfter()->getEpoch();
232
233     return expiryTime;
234 }
235
236 OM_uint32
237 gss_eap_saml_assertion_provider::mapException(OM_uint32 *minor,
238                                               std::exception &e) const
239 {
240     if (typeid(e) == typeid(SecurityPolicyException))
241         *minor = GSSEAP_SAML_SEC_POLICY_FAILURE;
242     else if (typeid(e) == typeid(BindingException))
243         *minor = GSSEAP_SAML_BINDING_FAILURE;
244     else if (typeid(e) == typeid(ProfileException))
245         *minor = GSSEAP_SAML_PROFILE_FAILURE;
246     else if (typeid(e) == typeid(FatalProfileException))
247         *minor = GSSEAP_SAML_FATAL_PROFILE_FAILURE;
248     else if (typeid(e) == typeid(RetryableProfileException))
249         *minor = GSSEAP_SAML_RETRY_PROFILE_FAILURE;
250     else if (typeid(e) == typeid(MetadataException))
251         *minor = GSSEAP_SAML_METADATA_FAILURE;
252     else
253         return GSS_S_CONTINUE_NEEDED;
254
255     return GSS_S_FAILURE;
256 }
257
258 bool
259 gss_eap_saml_assertion_provider::getAttribute(const gss_buffer_t attr,
260                                               int *authenticated,
261                                               int *complete,
262                                               gss_buffer_t value,
263                                               gss_buffer_t display_value GSSEAP_UNUSED,
264                                               int *more) const
265 {
266     string str;
267
268     if (attr != GSS_C_NO_BUFFER && attr->length != 0)
269         return false;
270
271     if (m_assertion == NULL)
272         return false;
273
274     if (*more != -1)
275         return false;
276
277     if (authenticated != NULL)
278         *authenticated = m_authenticated;
279     if (complete != NULL)
280         *complete = true;
281
282     XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
283
284     duplicateBuffer(str, value);
285     *more = 0;
286
287     return true;
288 }
289
290 gss_any_t
291 gss_eap_saml_assertion_provider::mapToAny(int authenticated,
292                                           gss_buffer_t type_id GSSEAP_UNUSED) const
293 {
294     if (authenticated && !m_authenticated)
295         return (gss_any_t)NULL;
296
297     return (gss_any_t)m_assertion;
298 }
299
300 void
301 gss_eap_saml_assertion_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
302                                                        gss_any_t input) const
303 {
304     delete ((saml2::Assertion *)input);
305 }
306
307 void
308 gss_eap_saml_assertion_provider::exportToBuffer(gss_buffer_t buffer) const
309 {
310     ostringstream sink;
311     string str;
312
313     buffer->length = 0;
314     buffer->value = NULL;
315
316     if (m_assertion == NULL)
317         return;
318
319     sink << *m_assertion;
320     str = sink.str();
321
322     duplicateBuffer(str, buffer);
323 }
324
325 bool
326 gss_eap_saml_assertion_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
327                                                 const gss_buffer_t buffer)
328 {
329     if (!gss_eap_attr_provider::initFromBuffer(ctx, buffer))
330         return false;
331
332     if (buffer->length == 0)
333         return true;
334
335     assert(m_assertion == NULL);
336
337     setAssertion(buffer);
338     /* TODO XXX how to propagate authenticated flag? */
339
340     return true;
341 }
342
343 bool
344 gss_eap_saml_assertion_provider::init(void)
345 {
346     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML_ASSERTION,
347                                        "urn:ietf:params:gss-eap:saml-aaa-assertion",
348                                        createAttrContext);
349     return true;
350 }
351
352 void
353 gss_eap_saml_assertion_provider::finalize(void)
354 {
355     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_SAML_ASSERTION);
356 }
357
358 gss_eap_attr_provider *
359 gss_eap_saml_assertion_provider::createAttrContext(void)
360 {
361     return new gss_eap_saml_assertion_provider;
362 }
363
364 saml2::Assertion *
365 gss_eap_saml_assertion_provider::initAssertion(void)
366 {
367     delete m_assertion;
368     m_assertion = saml2::AssertionBuilder::buildAssertion();
369     m_authenticated = false;
370
371     return m_assertion;
372 }
373
374 /*
375  * gss_eap_saml_attr_provider is for retrieving the underlying attributes.
376  */
377 bool
378 gss_eap_saml_attr_provider::getAssertion(int *authenticated,
379                                          saml2::Assertion **pAssertion,
380                                          bool createIfAbsent) const
381 {
382     gss_eap_saml_assertion_provider *saml;
383
384     if (authenticated != NULL)
385         *authenticated = false;
386     if (pAssertion != NULL)
387         *pAssertion = NULL;
388
389     saml = static_cast<const gss_eap_saml_assertion_provider *>
390         (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
391     if (saml == NULL)
392         return false;
393
394     if (authenticated != NULL)
395         *authenticated = saml->authenticated();
396     if (pAssertion != NULL)
397         *pAssertion = saml->getAssertion();
398
399     if (saml->getAssertion() == NULL) {
400         if (createIfAbsent) {
401             if (authenticated != NULL)
402                 *authenticated = false;
403             if (pAssertion != NULL)
404                 *pAssertion = saml->initAssertion();
405         } else
406             return false;
407     }
408
409     return true;
410 }
411
412 bool
413 gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
414                                               void *data) const
415 {
416     saml2::Assertion *assertion;
417     int authenticated;
418
419     if (!getAssertion(&authenticated, &assertion))
420         return true;
421
422     /*
423      * Note: the first prefix is added by the attribute provider manager
424      *
425      * From draft-hartman-gss-eap-naming-00:
426      *
427      *   Each attribute carried in the assertion SHOULD also be a GSS name
428      *   attribute.  The name of this attribute has three parts, all separated
429      *   by an ASCII space character.  The first part is
430      *   urn:ietf:params:gss-eap:saml-attr.  The second part is the URI for
431      *   the SAML attribute name format.  The final part is the name of the
432      *   SAML attribute.  If the mechanism performs an additional attribute
433      *   query, the retrieved attributes SHOULD be GSS-API name attributes
434      *   using the same name syntax.
435      */
436     /* For each attribute statement, look for an attribute match */
437     const vector <saml2::AttributeStatement *> &statements =
438         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
439
440     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
441         s != statements.end();
442         ++s) {
443         const vector<saml2::Attribute*> &attrs =
444             const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
445
446         for (vector<saml2::Attribute*>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) {
447             const XMLCh *attributeName, *attributeNameFormat;
448             XMLCh *qualifiedName;
449             XMLCh space[2] = { ' ', 0 };
450             gss_buffer_desc utf8;
451             bool ret;
452
453             attributeName = (*a)->getName();
454             attributeNameFormat = (*a)->getNameFormat();
455             if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0')
456                 attributeNameFormat = saml2::Attribute::UNSPECIFIED;
457
458             qualifiedName = new XMLCh[XMLString::stringLen(attributeNameFormat) + 1 +
459                                       XMLString::stringLen(attributeName) + 1];
460             XMLString::copyString(qualifiedName, attributeNameFormat);
461             XMLString::catString(qualifiedName, space);
462             XMLString::catString(qualifiedName, attributeName);
463
464             utf8.value = (void *)toUTF8(qualifiedName);
465             utf8.length = strlen((char *)utf8.value);
466
467             ret = addAttribute(this, &utf8, data);
468
469             delete qualifiedName;
470
471             if (!ret)
472                 return ret;
473         }
474     }
475
476     return true;
477 }
478
479 static BaseRefVectorOf<XMLCh> *
480 decomposeAttributeName(const gss_buffer_t attr)
481 {
482     string inputAttr((const char *) attr->value, attr->length);
483     XMLCh *qualifiedAttr = XMLString::transcode((const char *)inputAttr.c_str());
484
485     BaseRefVectorOf<XMLCh> *components = XMLString::tokenizeString(qualifiedAttr);
486
487     XMLString::release(&qualifiedAttr);
488
489     if (components->size() != 2) {
490         delete components;
491         components = NULL;
492     }
493
494     return components;
495 }
496
497 bool
498 gss_eap_saml_attr_provider::setAttribute(int complete GSSEAP_UNUSED,
499                                          const gss_buffer_t attr,
500                                          const gss_buffer_t value)
501 {
502     saml2::Assertion *assertion;
503     saml2::Attribute *attribute;
504     saml2::AttributeValue *attributeValue;
505     saml2::AttributeStatement *attributeStatement;
506
507     if (!getAssertion(NULL, &assertion, true))
508         return false;
509
510     if (assertion->getAttributeStatements().size() != 0) {
511         attributeStatement = assertion->getAttributeStatements().front();
512     } else {
513         attributeStatement = saml2::AttributeStatementBuilder::buildAttributeStatement();
514         assertion->getAttributeStatements().push_back(attributeStatement);
515     }
516
517     /* Check the attribute name consists of name format | whsp | name */
518     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
519     if (components == NULL)
520         return false;
521
522     attribute = saml2::AttributeBuilder::buildAttribute();
523     attribute->setNameFormat(components->elementAt(0));
524     attribute->setName(components->elementAt(1));
525
526     string sValue((const char *) value->value, value->length);
527     XMLCh *xmlValue = XMLString::transcode(sValue.c_str());
528
529     attributeValue = saml2::AttributeValueBuilder::buildAttributeValue();
530     attributeValue->setTextContent(xmlValue);
531
532     attribute->getAttributeValues().push_back(attributeValue);
533
534     assert(attributeStatement != NULL);
535     attributeStatement->getAttributes().push_back(attribute);
536
537     delete components;
538     XMLString::release(&xmlValue);;
539
540     return true;
541 }
542
543 bool
544 gss_eap_saml_attr_provider::deleteAttribute(const gss_buffer_t attr)
545 {
546     saml2::Assertion *assertion;
547     bool ret = false;
548
549     if (!getAssertion(NULL, &assertion) ||
550         assertion->getAttributeStatements().size() == 0)
551         return false;
552
553     /* Check the attribute name consists of name format | whsp | name */
554     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
555     if (components == NULL)
556         return false;
557
558     /* For each attribute statement, look for an attribute match */
559     const vector<saml2::AttributeStatement *> &statements =
560         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
561
562     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
563         s != statements.end();
564         ++s) {
565         const vector<saml2::Attribute *> &attrs =
566             const_cast<const saml2::AttributeStatement *>(*s)->getAttributes();
567         ssize_t index = -1, i = 0;
568
569         /* There's got to be an easier way to do this */
570         for (vector<saml2::Attribute *>::const_iterator a = attrs.begin();
571              a != attrs.end();
572              ++a) {
573             if (XMLString::equals((*a)->getNameFormat(), components->elementAt(0)) &&
574                 XMLString::equals((*a)->getName(), components->elementAt(1))) {
575                 index = i;
576                 break;
577             }
578             ++i;
579         }
580         if (index != -1) {
581             (*s)->getAttributes().erase((*s)->getAttributes().begin() + index);
582             ret = true;
583         }
584     }
585
586     delete components;
587
588     return ret;
589 }
590
591 bool
592 gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
593                                          int *authenticated,
594                                          int *complete,
595                                          const saml2::Attribute **pAttribute) const
596 {
597     saml2::Assertion *assertion;
598
599     if (authenticated != NULL)
600         *authenticated = false;
601     if (complete != NULL)
602         *complete = true;
603     *pAttribute = NULL;
604
605     if (!getAssertion(authenticated, &assertion) ||
606         assertion->getAttributeStatements().size() == 0)
607         return false;
608
609     /* Check the attribute name consists of name format | whsp | name */
610     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
611     if (components == NULL)
612         return false;
613
614     /* For each attribute statement, look for an attribute match */
615     const vector <saml2::AttributeStatement *> &statements =
616         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
617     const saml2::Attribute *ret = NULL;
618
619     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
620         s != statements.end();
621         ++s) {
622         const vector<saml2::Attribute *> &attrs =
623             const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
624
625         for (vector<saml2::Attribute *>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) {
626             const XMLCh *attributeName, *attributeNameFormat;
627
628             attributeName = (*a)->getName();
629             attributeNameFormat = (*a)->getNameFormat();
630             if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0')
631                 attributeNameFormat = saml2::Attribute::UNSPECIFIED;
632
633             if (XMLString::equals(attributeNameFormat, components->elementAt(0)) &&
634                 XMLString::equals(attributeName, components->elementAt(1))) {
635                 ret = *a;
636                 break;
637             }
638         }
639
640         if (ret != NULL)
641             break;
642     }
643
644     delete components;
645
646     *pAttribute = ret;
647
648     return (ret != NULL);
649 }
650
651 bool
652 gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
653                                          int *authenticated,
654                                          int *complete,
655                                          gss_buffer_t value,
656                                          gss_buffer_t display_value,
657                                          int *more) const
658 {
659     const saml2::Attribute *a;
660     const saml2::AttributeValue *av;
661     int nvalues, i = *more;
662
663     *more = 0;
664
665     if (!getAttribute(attr, authenticated, complete, &a))
666         return false;
667
668     nvalues = a->getAttributeValues().size();
669
670     if (i == -1)
671         i = 0;
672     else if (i >= nvalues)
673         return false;
674 #ifdef __APPLE__
675     av = (const saml2::AttributeValue *)((void *)(a->getAttributeValues().at(i)));
676 #else
677     av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i));
678 #endif
679     if (av != NULL) {
680         if (value != NULL) {
681             value->value = toUTF8(av->getTextContent(), true);
682             value->length = strlen((char *)value->value);
683         }
684         if (display_value != NULL) {
685             display_value->value = toUTF8(av->getTextContent(), true);
686             display_value->length = strlen((char *)value->value);
687         }
688     }
689
690     if (nvalues > ++i)
691         *more = i;
692
693     return true;
694 }
695
696 gss_any_t
697 gss_eap_saml_attr_provider::mapToAny(int authenticated GSSEAP_UNUSED,
698                                      gss_buffer_t type_id GSSEAP_UNUSED) const
699 {
700     return (gss_any_t)NULL;
701 }
702
703 void
704 gss_eap_saml_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
705                                                   gss_any_t input GSSEAP_UNUSED) const
706 {
707 }
708
709 void
710 gss_eap_saml_attr_provider::exportToBuffer(gss_buffer_t buffer) const
711 {
712     buffer->length = 0;
713     buffer->value = NULL;
714 }
715
716 bool
717 gss_eap_saml_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
718                                            const gss_buffer_t buffer)
719 {
720     return gss_eap_attr_provider::initFromBuffer(ctx, buffer);
721 }
722
723 bool
724 gss_eap_saml_attr_provider::init(void)
725 {
726     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML,
727                                        "urn:ietf:params:gss-eap:saml-attr",
728                                        createAttrContext);
729     return true;
730 }
731
732 void
733 gss_eap_saml_attr_provider::finalize(void)
734 {
735     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_SAML);
736 }
737
738 gss_eap_attr_provider *
739 gss_eap_saml_attr_provider::createAttrContext(void)
740 {
741     return new gss_eap_saml_attr_provider;
742 }
743
744 OM_uint32
745 gssEapSamlAttrProvidersInit(OM_uint32 *minor)
746 {
747     if (!gss_eap_saml_assertion_provider::init() ||
748         !gss_eap_saml_attr_provider::init()) {
749         *minor = GSSEAP_SAML_INIT_FAILURE;
750         return GSS_S_FAILURE;
751     }
752
753     return GSS_S_COMPLETE;
754 }
755
756 OM_uint32
757 gssEapSamlAttrProvidersFinalize(OM_uint32 *minor)
758 {
759     gss_eap_saml_attr_provider::finalize();
760     gss_eap_saml_assertion_provider::finalize();
761
762     *minor = 0;
763     return GSS_S_COMPLETE;
764 }