summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2006-11-30 11:04:57 +0000
committerFrederic Peters <fpeters@entrouvert.com>2006-11-30 11:04:57 +0000
commit2b4627a8852ef694a0d74ccff5246c3b418aca63 (patch)
tree6d3221604711a20e1c4836cd42751a6306aaff63
parent2b6e2f5d083aebbc47e640a4f2d399f66f805e56 (diff)
fixing memory leaks, side effects and more in EncryptedAssertion
-rw-r--r--lasso/xml/saml-2.0/samlp2_response.c27
-rw-r--r--lasso/xml/tools.c35
2 files changed, 31 insertions, 31 deletions
diff --git a/lasso/xml/saml-2.0/samlp2_response.c b/lasso/xml/saml-2.0/samlp2_response.c
index 2e923ac5..051d3e4b 100644
--- a/lasso/xml/saml-2.0/samlp2_response.c
+++ b/lasso/xml/saml-2.0/samlp2_response.c
@@ -41,6 +41,8 @@
* </complexType>
*/
+extern LassoNode* lasso_assertion_encrypt(LassoSaml2Assertion *assertion);
+
/*****************************************************************************/
/* private methods */
/*****************************************************************************/
@@ -86,28 +88,29 @@ static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
{
LassoSamlp2Response *response = LASSO_SAMLP2_RESPONSE(node);
- GList *assertion_item = NULL;
- LassoSaml2Assertion *assertion = NULL;
+ GList *assertions;
LassoNode *encrypted_element = NULL;
+ xmlNode *result;
- if (response->Assertion != NULL && response->Assertion->data != NULL)
- assertion = response->Assertion->data;
-
+ assertions = response->Assertion;
/* Encrypt Assertions for messages but not for dumps */
if (lasso_dump == FALSE && response->Assertion != NULL) {
- for (assertion_item = response->Assertion;
- assertion_item != NULL && assertion_item->data != NULL;
- assertion_item = g_list_next(assertion_item)) {
- encrypted_element = lasso_assertion_encrypt(assertion_item->data, response);
+ for (assertions = response->Assertion;
+ assertions != NULL; assertions = g_list_next(assertions)) {
+ encrypted_element = lasso_assertion_encrypt(assertions->data);
if (encrypted_element != NULL) {
response->EncryptedAssertion = g_list_append(
response->EncryptedAssertion, encrypted_element);
- response->Assertion = g_list_remove(response->Assertion, assertion);
+ /* XXX: side effect is emptyying response->Assertion */
}
}
+ response->Assertion = NULL;
}
-
- return parent_class->get_xmlNode(node, lasso_dump);
+
+ result = parent_class->get_xmlNode(node, lasso_dump);
+ response->Assertion = assertions;
+
+ return result;
}
/*****************************************************************************/
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index 89678ada..5c3c8213 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -405,24 +405,17 @@ done:
return s_new_query;
}
-LassoNode *
+LassoNode*
lasso_assertion_encrypt(LassoSaml2Assertion *assertion)
{
LassoNode *encrypted_element = NULL;
- xmlChar *b64_value;
+ gchar *b64_value;
xmlSecByte *value;
int length;
int rc;
xmlSecKeyInfoCtxPtr ctx;
xmlSecKey *encryption_public_key = NULL;
int i;
-
- if (! assertion->encryption_activated ||
- assertion->encryption_public_key_str == NULL) {
- return NULL;
- }
-
- /* Load the encryption key*/
xmlSecKeyDataFormat key_formats[] = {
xmlSecKeyDataFormatDer,
xmlSecKeyDataFormatCertDer,
@@ -434,30 +427,34 @@ lasso_assertion_encrypt(LassoSaml2Assertion *assertion)
0
};
- b64_value = (xmlChar*)g_strdup(assertion->encryption_public_key_str);
- length = strlen((char*)b64_value);
- value = g_malloc(length);
- xmlSecErrorsDefaultCallbackEnableOutput(FALSE);
- rc = xmlSecBase64Decode(b64_value, value, length);
+ if (assertion->encryption_activated == FALSE ||
+ assertion->encryption_public_key_str == NULL) {
+ return NULL;
+ }
+
+ b64_value = g_strdup(assertion->encryption_public_key_str);
+ length = strlen(b64_value);
+ value = g_malloc(length*4); /* enough place for decoding */
+ rc = xmlSecBase64Decode((xmlChar*)b64_value, value, length);
if (rc < 0) {
/* bad base-64 */
g_free(value);
- value = (xmlSecByte*)g_strdup((char*)b64_value);
- rc = strlen((char*)value);
+ g_free(b64_value);
+ return NULL;
}
+ xmlSecErrorsDefaultCallbackEnableOutput(FALSE);
for (i = 0; key_formats[i] && encryption_public_key == NULL; i++) {
encryption_public_key = xmlSecCryptoAppKeyLoadMemory(value, rc,
key_formats[i], NULL, NULL, NULL);
}
+ xmlSecErrorsDefaultCallbackEnableOutput(TRUE);
/* Finally encrypt the assertion */
encrypted_element = LASSO_NODE(lasso_node_encrypt(assertion, encryption_public_key));
- xmlSecErrorsDefaultCallbackEnableOutput(TRUE);
- xmlFree(b64_value);
+ g_free(b64_value);
g_free(value);
-/* g_free(assertion->encryption_public_key_str); */
return encrypted_element;
}