summaryrefslogtreecommitdiffstats
path: root/lasso
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2009-03-27 15:05:26 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2009-03-27 15:05:26 +0000
commitc252e5d1c3492c0bd3bc3be8a4b54ec165dc3a91 (patch)
tree6810edc0c72d3a56d309eafbdc1611e6d9fec810 /lasso
parent8fc5cb3f499199581262688ad31268639a529dcc (diff)
downloadlasso-c252e5d1c3492c0bd3bc3be8a4b54ec165dc3a91.tar.gz
lasso-c252e5d1c3492c0bd3bc3be8a4b54ec165dc3a91.tar.xz
lasso-c252e5d1c3492c0bd3bc3be8a4b54ec165dc3a91.zip
Core: remove lasso_node_decrypt implementation
* lasso/xml/xml.c: remove code for lasso_node_decrypt.
Diffstat (limited to 'lasso')
-rw-r--r--lasso/xml/xml.c148
1 files changed, 0 insertions, 148 deletions
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index 488cc440..dcf3a5e3 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -645,154 +645,6 @@ exit:
/**
- * lasso_node_decrypt:
- * @xml_node: an EncryptedData #xmlNode to decrypt
- * @encryption_private_key : RSA private key to decrypt the node
- *
- * Decrypt a DES EncryptedKey with the RSA key.
- * Then decrypt @xml_node with the DES key.
- *
- * Return value: a LassoNode which is the decrypted @xml_node.
- * It must be freed by the caller.
- **/
-LassoNode*
-lasso_node_decrypt(LassoSaml2EncryptedElement* encrypted_element,
- xmlSecKey *encryption_private_key)
-{
- xmlDocPtr doc = NULL;
- xmlDocPtr doc2 = NULL;
- xmlSecEncCtxPtr encCtx = NULL;
- xmlSecKeyPtr sym_key = NULL;
- xmlSecBufferPtr key_buffer = NULL;
- LassoNode *decrypted_node = NULL;
- xmlNodePtr encrypted_data_node = NULL;
- xmlNodePtr encrypted_key_node = NULL;
- xmlNodePtr encryption_method_node = NULL;
- char *algorithm;
- xmlSecKeyDataId key_type;
- GList *i = NULL;
-
- if (encryption_private_key == NULL || !xmlSecKeyIsValid(encryption_private_key)) {
- message(G_LOG_LEVEL_WARNING, "Invalid decryption key");
- goto cleanup;
- }
-
- /* Need to duplicate it because xmlSecEncCtxDestroy(encCtx); will destroy it */
- encryption_private_key = xmlSecKeyDuplicate(encryption_private_key);
-
- encrypted_data_node = xmlCopyNode(encrypted_element->EncryptedData, 1);
-
- /* Get the encryption algorithm for EncryptedData in its EncryptionMethod node */
- encryption_method_node = xmlSecTmplEncDataGetEncMethodNode(encrypted_data_node);
- if (encryption_method_node == NULL) {
- message(G_LOG_LEVEL_WARNING, "No EncryptionMethod node in EncryptedData");
- goto cleanup;
- }
- algorithm = (char*)xmlGetProp(encryption_method_node, (xmlChar *)"Algorithm");
- if (algorithm == NULL) {
- message(G_LOG_LEVEL_WARNING, "No EncryptionMethod");
- goto cleanup;
- }
- if (strstr(algorithm , "#aes")) {
- key_type = xmlSecKeyDataAesId;
- } else if (strstr(algorithm , "des")) {
- key_type = xmlSecKeyDataDesId;
- } else {
- message(G_LOG_LEVEL_WARNING, "Unknown EncryptionMethod");
- goto cleanup;
- }
-
- /* Get the EncryptedKey */
- if (encrypted_element->EncryptedKey != NULL) {
- for (i = encrypted_element->EncryptedKey; i; i = g_list_next(i)) {
- if (i->data == NULL)
- continue;
- if (strcmp((char*)((xmlNode*)i->data)->name, "EncryptedKey") == 0) {
- encrypted_key_node = xmlCopyNode((xmlNode*)(i->data), 1);
- break;
- }
- }
- } else {
- /* Look an EncryptedKey inside the EncryptedData */
- encrypted_key_node = encrypted_data_node;
- while (encrypted_key_node &&
- strcmp((char*)encrypted_key_node->name, "EncryptedKey") != 0 ) {
- if (strcmp((char*)encrypted_key_node->name, "EncryptedData") == 0 ||
- strcmp((char*)encrypted_key_node->name, "KeyInfo") == 0) {
- encrypted_key_node = xmlCopyNode(encrypted_key_node->children, 1);
- break;
- }
- encrypted_key_node = encrypted_key_node->next;
- }
- }
-
- if (encrypted_key_node == NULL) {
- message(G_LOG_LEVEL_WARNING, "No EncryptedKey node");
- goto cleanup;
- }
-
- /* Create a document to contain the node to decrypt */
- doc = xmlNewDoc((xmlChar*)"1.0");
- xmlDocSetRootElement(doc, encrypted_data_node);
-
- doc2 = xmlNewDoc((xmlChar*)"1.0");
- xmlDocSetRootElement(doc2, encrypted_key_node);
-
- /* create encryption context to decrypt EncryptedKey */
- encCtx = xmlSecEncCtxCreate(NULL);
- if (encCtx == NULL) {
- message(G_LOG_LEVEL_WARNING, "Failed to create encryption context");
- goto cleanup;
- }
- encCtx->encKey = encryption_private_key;
- encCtx->mode = xmlEncCtxModeEncryptedKey;
-
- /* decrypt the EncryptedKey */
- key_buffer = xmlSecEncCtxDecryptToBuffer(encCtx, encrypted_key_node);
- if (key_buffer != NULL) {
- sym_key = xmlSecKeyReadBuffer(key_type, key_buffer);
- }
- if (sym_key == NULL) {
- message(G_LOG_LEVEL_WARNING, "EncryptedKey decryption failed");
- goto cleanup;
- }
-
- /* create encryption context to decrypt EncryptedData */
- xmlSecEncCtxDestroy(encCtx);
- encCtx = xmlSecEncCtxCreate(NULL);
- if (encCtx == NULL) {
- message(G_LOG_LEVEL_WARNING, "Failed to create encryption context");
- goto cleanup;
- }
- encCtx->encKey = sym_key;
- encCtx->mode = xmlEncCtxModeEncryptedData;
-
- /* decrypt the EncryptedData */
- if ((xmlSecEncCtxDecrypt(encCtx, encrypted_data_node) < 0) || (encCtx->result == NULL)) {
- message(G_LOG_LEVEL_WARNING, "EncryptedData decryption failed");
- goto cleanup;
- }
-
- decrypted_node = lasso_node_new_from_xmlNode(doc->children);
-
-cleanup:
- if (doc == NULL) {
- if (encrypted_data_node) {
- xmlFreeNode(encrypted_data_node);
- }
- if (encrypted_key_node) {
- xmlFreeNode(encrypted_key_node);
- }
- }
- if (encCtx) {
- xmlSecEncCtxDestroy(encCtx);
- }
- lasso_release_doc(doc);
-
- return decrypted_node;
-}
-
-/**
* lasso_node_init_from_query:
* @node: a #LassoNode (or derived class)
* @query: the query string