Line data Source code
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 : */
9 : #include "globals.h"
10 :
11 : #ifndef XMLSEC_NO_X509
12 :
13 : #include <stdlib.h>
14 : #include <stdio.h>
15 : #include <string.h>
16 :
17 : #include <libxml/tree.h>
18 : #include <libxml/parser.h>
19 :
20 : #include <xmlsec/xmlsec.h>
21 : #include <xmlsec/buffer.h>
22 : #include <xmlsec/xmltree.h>
23 : #include <xmlsec/keys.h>
24 : #include <xmlsec/keysmngr.h>
25 : #include <xmlsec/transforms.h>
26 : #include <xmlsec/keyinfo.h>
27 : #include <xmlsec/x509.h>
28 : #include <xmlsec/errors.h>
29 :
30 : /**
31 : * xmlSecX509DataGetNodeContent:
32 : * @node: the pointer to <dsig:X509Data/> node.
33 : * @deleteChildren: the flag that indicates whether to remove node children after reading.
34 : * @keyInfoCtx: the pointer to <dsig:KeyInfo/> node processing context.
35 : *
36 : * Reads the contents of <dsig:X509Data/> node and returns it as
37 : * a bits mask.
38 : *
39 : * Returns: the bit mask representing the <dsig:X509Data/> node content
40 : * or a negative value if an error occurs.
41 : */
42 : int
43 0 : xmlSecX509DataGetNodeContent (xmlNodePtr node, int deleteChildren,
44 : xmlSecKeyInfoCtxPtr keyInfoCtx) {
45 : xmlNodePtr cur, next;
46 : int deleteCurNode;
47 0 : int content = 0;
48 :
49 0 : xmlSecAssert2(node != NULL, 0);
50 0 : xmlSecAssert2(keyInfoCtx != NULL, -1);
51 :
52 : /* determine the current node content */
53 0 : cur = xmlSecGetNextElementNode(node->children);
54 0 : while(cur != NULL) {
55 0 : deleteCurNode = 0;
56 0 : if(xmlSecCheckNodeName(cur, xmlSecNodeX509Certificate, xmlSecDSigNs)) {
57 0 : if(xmlSecIsEmptyNode(cur) == 1) {
58 0 : content |= XMLSEC_X509DATA_CERTIFICATE_NODE;
59 0 : deleteCurNode = 1;
60 : }
61 0 : } else if(xmlSecCheckNodeName(cur, xmlSecNodeX509SubjectName, xmlSecDSigNs)) {
62 0 : if(xmlSecIsEmptyNode(cur) == 1) {
63 0 : content |= XMLSEC_X509DATA_SUBJECTNAME_NODE;
64 0 : deleteCurNode = 1;
65 : }
66 0 : } else if(xmlSecCheckNodeName(cur, xmlSecNodeX509IssuerSerial, xmlSecDSigNs)) {
67 0 : if(xmlSecIsEmptyNode(cur) == 1) {
68 0 : content |= XMLSEC_X509DATA_ISSUERSERIAL_NODE;
69 0 : deleteCurNode = 1;
70 : }
71 0 : } else if(xmlSecCheckNodeName(cur, xmlSecNodeX509SKI, xmlSecDSigNs)) {
72 0 : if(xmlSecIsEmptyNode(cur) == 1) {
73 0 : content |= XMLSEC_X509DATA_SKI_NODE;
74 0 : deleteCurNode = 1;
75 : }
76 0 : } else if(xmlSecCheckNodeName(cur, xmlSecNodeX509CRL, xmlSecDSigNs)) {
77 0 : if(xmlSecIsEmptyNode(cur) == 1) {
78 0 : content |= XMLSEC_X509DATA_CRL_NODE;
79 0 : deleteCurNode = 1;
80 : }
81 : } else {
82 : /* todo: fail on unknown child node? */
83 : }
84 0 : next = xmlSecGetNextElementNode(cur->next);
85 0 : if((deleteCurNode != 0) && (deleteChildren != 0)) {
86 : /* remove "template" nodes */
87 0 : xmlUnlinkNode(cur);
88 0 : xmlFreeNode(cur);
89 : }
90 0 : cur = next;
91 : }
92 :
93 0 : return (content);
94 : }
95 :
96 : #endif /* XMLSEC_NO_X509 */
97 :
|