From 898862478f9adecfc5580814cf1296464c448b1b Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sun, 3 Apr 2011 19:14:42 +1000 Subject: [PATCH] automatically decode base64 encoded SAML values --- mech_eap/util_saml.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mech_eap/util_saml.cpp b/mech_eap/util_saml.cpp index 26bf544..9658bf0 100644 --- a/mech_eap/util_saml.cpp +++ b/mech_eap/util_saml.cpp @@ -671,8 +671,27 @@ gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr, #endif if (av != NULL) { if (value != NULL) { - value->value = toUTF8(av->getTextContent(), true); - value->length = strlen((char *)value->value); + char *stringValue = toUTF8(av->getTextContent(), true); + size_t stringValueLen = strlen(stringValue); + + if (base64Valid(stringValue)) { + ssize_t binaryLen; + + value->value = GSSEAP_MALLOC(stringValueLen); + if (value->value == NULL) + throw new std::bad_alloc; + + binaryLen = base64Decode(stringValue, value->value); + if (binaryLen < 0) { + GSSEAP_FREE(value->value); + value->value = NULL; + return false; + } + value->length = binaryLen; + } else { + value->value = stringValue; + value->length = stringValueLen; + } } if (display_value != NULL) { display_value->value = toUTF8(av->getTextContent(), true); -- 2.1.4