|         |      1 /**  | 
|         |      2  * XML Security Library (http://www.aleksey.com/xmlsec). | 
|         |      3  * | 
|         |      4  * This is free software; see Copyright file in the source | 
|         |      5  * distribution for preciese wording. | 
|         |      6  *  | 
|         |      7  * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> | 
|         |      8  * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.  | 
|         |      9  */ | 
|         |     10 #include "xmlsec_config.h" | 
|         |     11 #ifndef XMLSEC_NO_X509 | 
|         |     12 #include "xmlsec_globals.h" | 
|         |     13   | 
|         |     14 #include <stdlib.h> | 
|         |     15 #include <stdio.h> | 
|         |     16 #include <string.h> | 
|         |     17  | 
|         |     18 #include <libxml2_tree.h> | 
|         |     19 #include <libxml2_parser.h> | 
|         |     20  | 
|         |     21 #include "xmlsec_xmlsec.h" | 
|         |     22 #include "xmlsec_buffer.h" | 
|         |     23 #include "xmlsec_xmltree.h" | 
|         |     24 #include "xmlsec_keys.h" | 
|         |     25 #include "xmlsec_keysmngr.h" | 
|         |     26 #include "xmlsec_transforms.h" | 
|         |     27 #include "xmlsec_keyinfo.h" | 
|         |     28 #include "xmlsec_x509.h" | 
|         |     29 #include "xmlsec_errors.h" | 
|         |     30  | 
|         |     31 /** | 
|         |     32  * xmlSecX509DataGetNodeContent: | 
|         |     33  * @node:		the pointer to <dsig:X509Data/> node. | 
|         |     34  * @deleteChildren:	the flag that indicates whether to remove node children after reading. | 
|         |     35  * @keyInfoCtx:		the pointer to <dsig:KeyInfo/> node processing context. | 
|         |     36  * | 
|         |     37  * Reads the contents of <dsig:X509Data/> node and returns it as | 
|         |     38  * a bits mask. | 
|         |     39  * | 
|         |     40  * Returns the bit mask representing the <dsig:X509Data/> node content | 
|         |     41  * or a negative value if an error occurs. | 
|         |     42  */ | 
|         |     43 EXPORT_C | 
|         |     44 int | 
|         |     45 xmlSecX509DataGetNodeContent (xmlNodePtr node, int deleteChildren, | 
|         |     46 			    xmlSecKeyInfoCtxPtr keyInfoCtx) { | 
|         |     47     xmlNodePtr cur, next; | 
|         |     48     int deleteCurNode; | 
|         |     49     int content = 0; | 
|         |     50  | 
|         |     51     xmlSecAssert2(node != NULL, 0); | 
|         |     52     xmlSecAssert2(keyInfoCtx != NULL, -1); | 
|         |     53  | 
|         |     54     /* determine the current node content */ | 
|         |     55     cur = xmlSecGetNextElementNode(node->children);  | 
|         |     56     while(cur != NULL) { | 
|         |     57 	deleteCurNode = 0; | 
|         |     58 	if(xmlSecCheckNodeName(cur, xmlSecNodeX509Certificate, xmlSecDSigNs)) { | 
|         |     59 	    if(xmlSecIsEmptyNode(cur) == 1) { | 
|         |     60 		content |= XMLSEC_X509DATA_CERTIFICATE_NODE; | 
|         |     61 		deleteCurNode = 1; | 
|         |     62 	    } | 
|         |     63 	} else if(xmlSecCheckNodeName(cur, xmlSecNodeX509SubjectName, xmlSecDSigNs)) { | 
|         |     64 	    if(xmlSecIsEmptyNode(cur) == 1) { | 
|         |     65     	        content |= XMLSEC_X509DATA_SUBJECTNAME_NODE; | 
|         |     66 		deleteCurNode = 1; | 
|         |     67 	    } | 
|         |     68 	} else if(xmlSecCheckNodeName(cur, xmlSecNodeX509IssuerSerial, xmlSecDSigNs)) { | 
|         |     69 	    if(xmlSecIsEmptyNode(cur) == 1) { | 
|         |     70 		content |= XMLSEC_X509DATA_ISSUERSERIAL_NODE; | 
|         |     71 		deleteCurNode = 1; | 
|         |     72 	    } | 
|         |     73 	} else if(xmlSecCheckNodeName(cur, xmlSecNodeX509SKI, xmlSecDSigNs)) { | 
|         |     74 	    if(xmlSecIsEmptyNode(cur) == 1) { | 
|         |     75 		content |= XMLSEC_X509DATA_SKI_NODE; | 
|         |     76 		deleteCurNode = 1; | 
|         |     77 	    } | 
|         |     78 	} else if(xmlSecCheckNodeName(cur, xmlSecNodeX509CRL, xmlSecDSigNs)) { | 
|         |     79 	    if(xmlSecIsEmptyNode(cur) == 1) { | 
|         |     80 		content |= XMLSEC_X509DATA_CRL_NODE; | 
|         |     81 		deleteCurNode = 1; | 
|         |     82 	    } | 
|         |     83 	} else { | 
|         |     84 	} | 
|         |     85 	next = xmlSecGetNextElementNode(cur->next); | 
|         |     86 	if((deleteCurNode != 0) && (deleteChildren != 0)) { | 
|         |     87 	    /* remove "template" nodes */ | 
|         |     88 	    xmlUnlinkNode(cur); | 
|         |     89 	    xmlFreeNode(cur); | 
|         |     90 	} | 
|         |     91 	cur = next; | 
|         |     92     } | 
|         |     93  | 
|         |     94     return (content); | 
|         |     95 } | 
|         |     96  | 
|         |     97 #endif /* XMLSEC_NO_X509 */ | 
|         |     98  |