summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-01-12 15:40:01 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-01-12 15:40:01 +0000
commit413932306d6431be184bb20cf9ab9fbfd6453d19 (patch)
treeaafe482a1ff621b84139d077fbaa7a0c39f845d7
parenta237cd105702f66b9ecf6727059d0bdcec096bae (diff)
Core: rewrite lasso_assertion_encrypt using lasso_xmlsect_load_key and add recipient argument
-rw-r--r--lasso/xml/saml-2.0/samlp2_response.c4
-rw-r--r--lasso/xml/tools.c47
2 files changed, 6 insertions, 45 deletions
diff --git a/lasso/xml/saml-2.0/samlp2_response.c b/lasso/xml/saml-2.0/samlp2_response.c
index 8cf59356..22bd4f9d 100644
--- a/lasso/xml/saml-2.0/samlp2_response.c
+++ b/lasso/xml/saml-2.0/samlp2_response.c
@@ -48,7 +48,7 @@
* </figure>
*/
-extern LassoNode* lasso_assertion_encrypt(LassoSaml2Assertion *assertion);
+extern LassoNode* lasso_assertion_encrypt(LassoSaml2Assertion *assertion, char *recipient);
/*****************************************************************************/
/* private methods */
@@ -78,7 +78,7 @@ get_xmlNode(LassoNode *node, gboolean lasso_dump)
assertions_copy = g_list_copy(response->Assertion);
for (assertions = response->Assertion;
assertions != NULL; assertions = g_list_next(assertions)) {
- encrypted_element = lasso_assertion_encrypt(assertions->data);
+ encrypted_element = lasso_assertion_encrypt(assertions->data, NULL);
if (encrypted_element != NULL) {
/* use EncryptedAssertion */
response->EncryptedAssertion = g_list_append(
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index b20de580..f862c9f6 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -526,57 +526,18 @@ done:
}
LassoNode*
-lasso_assertion_encrypt(LassoSaml2Assertion *assertion)
+lasso_assertion_encrypt(LassoSaml2Assertion *assertion, char *recipient)
{
- LassoNode *encrypted_element = NULL;
- gchar *b64_value;
- xmlSecByte *value;
- int length;
- int rc;
xmlSecKey *encryption_public_key = NULL;
- int i;
- xmlSecKeyDataFormat key_formats[] = {
- xmlSecKeyDataFormatDer,
- xmlSecKeyDataFormatCertDer,
- xmlSecKeyDataFormatPkcs8Der,
- xmlSecKeyDataFormatCertPem,
- xmlSecKeyDataFormatPkcs8Pem,
- xmlSecKeyDataFormatPem,
- xmlSecKeyDataFormatBinary,
- 0
- };
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);
- 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(LASSO_NODE(assertion),
- encryption_public_key, assertion->encryption_sym_key_type));
-
- g_free(b64_value);
- g_free(value);
-
- return encrypted_element;
+ encryption_public_key = lasso_xmlsec_load_private_key(assertion->encryption_public_key_str, NULL);
+ return LASSO_NODE(lasso_node_encrypt(LASSO_NODE(assertion),
+ encryption_public_key, assertion->encryption_sym_key_type, recipient));
}