Line | Count | Source |
1 | | /** |
2 | | * XML Security Library (http://www.aleksey.com/xmlsec). |
3 | | * |
4 | | * This is free software; see the Copyright file in the source distribution for precise wording. |
5 | | * |
6 | | * Copyright (C) 2002-2026 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. |
7 | | */ |
8 | | /** |
9 | | * @addtogroup xmlsec_core_transforms |
10 | | * @brief C14N canonicalization transform implementation. |
11 | | */ |
12 | | #include "globals.h" |
13 | | |
14 | | #include <libxml/tree.h> |
15 | | #include <libxml/c14n.h> |
16 | | |
17 | | #include <xmlsec/xmlsec.h> |
18 | | #include <xmlsec/list.h> |
19 | | #include <xmlsec/transforms.h> |
20 | | #include <xmlsec/xmltree.h> |
21 | | #include <xmlsec/errors.h> |
22 | | |
23 | | #include "cast_helpers.h" |
24 | | |
25 | | /****************************************************************************** |
26 | | * |
27 | | * C14N transforms |
28 | | * |
29 | | * xmlSecTransform + xmlSecStringList (inclusive namespaces list for ExclC14N). |
30 | | * |
31 | | *****************************************************************************/ |
32 | 240k | XMLSEC_TRANSFORM_DECLARE(C14N, xmlSecPtrList) |
33 | 240k | #define xmlSecC14NSize XMLSEC_TRANSFORM_SIZE(C14N) |
34 | 240k | |
35 | 240k | #define xmlSecTransformC14NCheckId(transform) \ |
36 | 240k | (xmlSecTransformInclC14NCheckId((transform)) || \ |
37 | 240k | xmlSecTransformInclC14N11CheckId((transform)) || \ |
38 | 240k | xmlSecTransformExclC14NCheckId((transform)) || \ |
39 | 240k | xmlSecTransformCheckId((transform), xmlSecTransformRemoveXmlTagsC14NId)) |
40 | 240k | |
41 | 240k | #define xmlSecTransformInclC14NCheckId(transform) \ |
42 | 240k | (xmlSecTransformCheckId((transform), xmlSecTransformInclC14NId) || \ |
43 | 240k | xmlSecTransformCheckId((transform), xmlSecTransformInclC14NWithCommentsId)) |
44 | 240k | |
45 | 240k | #define xmlSecTransformInclC14N11CheckId(transform) \ |
46 | 240k | (xmlSecTransformCheckId((transform), xmlSecTransformInclC14N11Id) || \ |
47 | 240k | xmlSecTransformCheckId((transform), xmlSecTransformInclC14N11WithCommentsId)) |
48 | 240k | |
49 | 240k | #define xmlSecTransformExclC14NCheckId(transform) \ |
50 | 240k | (xmlSecTransformCheckId((transform), xmlSecTransformExclC14NId) || \ |
51 | 240k | xmlSecTransformCheckId((transform), xmlSecTransformExclC14NWithCommentsId)) |
52 | 240k | |
53 | 240k | |
54 | 240k | static int xmlSecTransformC14NInitialize (xmlSecTransformPtr transform); |
55 | 240k | static void xmlSecTransformC14NFinalize (xmlSecTransformPtr transform); |
56 | 240k | static int xmlSecTransformC14NNodeRead (xmlSecTransformPtr transform, |
57 | 240k | xmlNodePtr node, |
58 | 240k | xmlSecTransformCtxPtr transformCtx); |
59 | 240k | static int xmlSecTransformC14NPushXml (xmlSecTransformPtr transform, |
60 | 240k | xmlSecNodeSetPtr nodes, |
61 | 240k | xmlSecTransformCtxPtr transformCtx); |
62 | 240k | static int xmlSecTransformC14NPopBin (xmlSecTransformPtr transform, |
63 | 240k | xmlSecByte* data, |
64 | 240k | xmlSecSize maxDataSize, |
65 | 240k | xmlSecSize* dataSize, |
66 | 240k | xmlSecTransformCtxPtr transformCtx); |
67 | 240k | static int xmlSecTransformC14NExecute (xmlSecTransformId id, |
68 | 240k | xmlSecNodeSetPtr nodes, |
69 | 240k | xmlSecPtrListPtr nsList, |
70 | 240k | xmlOutputBufferPtr buf); |
71 | 240k | |
72 | 240k | #define XMLSEC_IS_XML_SPACE(ch) \ |
73 | 240k | (((ch) == ' ') || ((ch) == '\t') || ((ch) == '\n') || ((ch) == '\r')) |
74 | | |
75 | | static int |
76 | 29.2k | xmlSecTransformC14NInitialize(xmlSecTransformPtr transform) { |
77 | 29.2k | xmlSecPtrListPtr nsList; |
78 | 29.2k | int ret; |
79 | | |
80 | 29.2k | xmlSecAssert2(xmlSecTransformC14NCheckId(transform), -1); |
81 | | |
82 | 29.2k | nsList = xmlSecC14NGetCtx(transform); |
83 | 29.2k | xmlSecAssert2(nsList != NULL, -1); |
84 | | |
85 | 29.2k | ret = xmlSecPtrListInitialize(nsList, xmlSecStringListId); |
86 | 29.2k | if(ret < 0) { |
87 | 0 | xmlSecInternalError("xmlSecPtrListInitialize", |
88 | 0 | xmlSecTransformGetName(transform)); |
89 | 0 | return(-1); |
90 | 0 | } |
91 | 29.2k | return(0); |
92 | 29.2k | } |
93 | | |
94 | | static void |
95 | 29.2k | xmlSecTransformC14NFinalize(xmlSecTransformPtr transform) { |
96 | 29.2k | xmlSecPtrListPtr nsList; |
97 | | |
98 | 29.2k | xmlSecAssert(xmlSecTransformC14NCheckId(transform)); |
99 | | |
100 | 29.2k | nsList = xmlSecC14NGetCtx(transform); |
101 | 29.2k | xmlSecAssert(xmlSecPtrListCheckId(nsList, xmlSecStringListId)); |
102 | | |
103 | 29.2k | xmlSecPtrListFinalize(nsList); |
104 | 29.2k | } |
105 | | |
106 | | static int |
107 | 5 | xmlSecTransformC14NNodeRead(xmlSecTransformPtr transform, xmlNodePtr node, xmlSecTransformCtxPtr transformCtx) { |
108 | 5 | xmlSecPtrListPtr nsList; |
109 | 5 | xmlNodePtr cur; |
110 | 5 | xmlChar *list; |
111 | 5 | xmlChar *p, *n, *tmp; |
112 | 5 | int ret; |
113 | | |
114 | | /* we have something to read only for exclusive c14n transforms */ |
115 | 5 | xmlSecAssert2(xmlSecTransformExclC14NCheckId(transform), -1); |
116 | 5 | xmlSecAssert2(node != NULL, -1); |
117 | 5 | xmlSecAssert2(transformCtx != NULL, -1); |
118 | | |
119 | 5 | nsList = xmlSecC14NGetCtx(transform); |
120 | 5 | xmlSecAssert2(xmlSecPtrListCheckId(nsList, xmlSecStringListId), -1); |
121 | 5 | xmlSecAssert2(xmlSecPtrListGetSize(nsList) == 0, -1); |
122 | | |
123 | | /* there is only one optional node */ |
124 | 5 | cur = xmlSecGetNextElementNode(node->children); |
125 | 5 | if(cur != NULL) { |
126 | 1 | if(!xmlSecCheckNodeName(cur, xmlSecNodeInclusiveNamespaces, xmlSecNsExcC14N)) { |
127 | 1 | xmlSecInvalidNodeError(cur, xmlSecNodeInclusiveNamespaces, |
128 | 1 | xmlSecTransformGetName(transform)); |
129 | 1 | return(-1); |
130 | 1 | } |
131 | | |
132 | | /* per the W3C Exclusive Canonicalization specification the |
133 | | * PrefixList attribute is optional (its value "may be null"); a |
134 | | * missing attribute is treated the same as an empty string, i.e. |
135 | | * no extra namespaces are included */ |
136 | 0 | list = xmlGetProp(cur, xmlSecAttrPrefixList); |
137 | | |
138 | | /* the list of namespaces is XML whitespace separated. |
139 | | * The tokens are not validated as NCNames and duplicates are not |
140 | | * rejected: the list is only used by libxml2 for equality |
141 | | * comparison against the in-scope prefixes during canonicalization, |
142 | | * so an invalid or duplicated token is simply ignored */ |
143 | 0 | for(p = list; ((p != NULL) && ((*p) != '\0')); p = n) { |
144 | 0 | while((*p != '\0') && XMLSEC_IS_XML_SPACE(*p)) { |
145 | 0 | ++p; |
146 | 0 | } |
147 | 0 | if(*p == '\0') { |
148 | 0 | break; |
149 | 0 | } |
150 | | |
151 | 0 | n = p; |
152 | 0 | while((*n != '\0') && !XMLSEC_IS_XML_SPACE(*n)) { |
153 | 0 | ++n; |
154 | 0 | } |
155 | 0 | if(*n != '\0') { |
156 | 0 | *(n++) = '\0'; |
157 | 0 | } |
158 | |
|
159 | 0 | tmp = xmlStrdup(p); |
160 | 0 | if(tmp == NULL) { |
161 | 0 | xmlSecStrdupError(p, xmlSecTransformGetName(transform)); |
162 | 0 | xmlFree(list); |
163 | 0 | return(-1); |
164 | 0 | } |
165 | | |
166 | 0 | ret = xmlSecPtrListAdd(nsList, tmp); |
167 | 0 | if(ret < 0) { |
168 | 0 | xmlSecInternalError("xmlSecPtrListAdd", |
169 | 0 | xmlSecTransformGetName(transform)); |
170 | 0 | xmlFree(tmp); |
171 | 0 | xmlFree(list); |
172 | 0 | return(-1); |
173 | 0 | } |
174 | 0 | } |
175 | 0 | xmlFree(list); |
176 | | |
177 | | /* add NULL at the end */ |
178 | 0 | ret = xmlSecPtrListAdd(nsList, NULL); |
179 | 0 | if(ret < 0) { |
180 | 0 | xmlSecInternalError("xmlSecPtrListAdd", |
181 | 0 | xmlSecTransformGetName(transform)); |
182 | 0 | return(-1); |
183 | 0 | } |
184 | | |
185 | 0 | cur = xmlSecGetNextElementNode(cur->next); |
186 | 0 | } |
187 | | |
188 | | /* check that we have nothing else */ |
189 | 4 | if(cur != NULL) { |
190 | 0 | xmlSecUnexpectedNodeError(cur, NULL); |
191 | 0 | return(-1); |
192 | 0 | } |
193 | | |
194 | 4 | return(0); |
195 | 4 | } |
196 | | |
197 | | /* |
198 | | * Note: in case of failure, the transform status is set to |
199 | | * #xmlSecTransformStatusFail and any partial output in the output buffer |
200 | | * is discarded, so a subsequent push operation will fail explicitly |
201 | | * instead of returning success without producing any output. The rest |
202 | | * of the transform state is undefined until the #xmlSecTransformDestroy |
203 | | * function is called. |
204 | | */ |
205 | | static int |
206 | 21.8k | xmlSecTransformC14NPushXml(xmlSecTransformPtr transform, xmlSecNodeSetPtr nodes, xmlSecTransformCtxPtr transformCtx) { |
207 | 21.8k | xmlOutputBufferPtr buf; |
208 | 21.8k | int ret; |
209 | | |
210 | 21.8k | xmlSecAssert2(xmlSecTransformC14NCheckId(transform), -1); |
211 | 21.8k | xmlSecAssert2(nodes != NULL, -1); |
212 | 21.8k | xmlSecAssert2(nodes->doc != NULL, -1); |
213 | 21.8k | xmlSecAssert2(transformCtx != NULL, -1); |
214 | | |
215 | | /* check/update current transform status */ |
216 | 21.8k | switch(transform->status) { |
217 | 21.8k | case xmlSecTransformStatusNone: |
218 | 21.8k | transform->status = xmlSecTransformStatusWorking; |
219 | 21.8k | break; |
220 | 0 | case xmlSecTransformStatusWorking: |
221 | 0 | case xmlSecTransformStatusFinished: |
222 | 0 | return(0); |
223 | 0 | default: |
224 | 0 | xmlSecInvalidTransformStatusError(transform); |
225 | 0 | return(-1); |
226 | 21.8k | } |
227 | 21.8k | xmlSecAssert2(transform->status == xmlSecTransformStatusWorking, -1); |
228 | | |
229 | | /* prepare output buffer: next transform or ourselves */ |
230 | 21.8k | if(transform->next != NULL) { |
231 | 21.8k | buf = xmlSecTransformCreateOutputBuffer(transform->next, transformCtx); |
232 | 21.8k | if(buf == NULL) { |
233 | 0 | xmlSecInternalError("xmlSecTransformCreateOutputBuffer", xmlSecTransformGetName(transform)); |
234 | 0 | transform->status = xmlSecTransformStatusFail; |
235 | 0 | return(-1); |
236 | 0 | } |
237 | 21.8k | } else { |
238 | 0 | buf = xmlSecBufferCreateOutputBuffer(&(transform->outBuf)); |
239 | 0 | if(buf == NULL) { |
240 | 0 | xmlSecInternalError("xmlSecBufferCreateOutputBuffer", xmlSecTransformGetName(transform)); |
241 | 0 | transform->status = xmlSecTransformStatusFail; |
242 | 0 | return(-1); |
243 | 0 | } |
244 | 0 | } |
245 | | |
246 | 21.8k | ret = xmlSecTransformC14NExecute(transform->id, nodes, xmlSecC14NGetCtx(transform), buf); |
247 | 21.8k | if(ret < 0) { |
248 | 1.07k | xmlSecInternalError("xmlSecTransformC14NExecute", xmlSecTransformGetName(transform)); |
249 | | /* the buffer must be closed to release it (the IO buffer is only |
250 | | * freed by its close callback). The close pushes the partial data |
251 | | * into the next transform, which is harmless here: the whole |
252 | | * operation is aborted and the produced data is discarded */ |
253 | 1.07k | (void)xmlOutputBufferClose(buf); |
254 | | /* clear the partial output in the local buffer so it cannot be |
255 | | * picked up by a later operation (the data may have already been |
256 | | * pushed into the next transform by the close callback, but the |
257 | | * whole operation is aborted, so it is of no use) and mark the |
258 | | * transform as failed */ |
259 | 1.07k | xmlSecBufferEmpty(&(transform->outBuf)); |
260 | 1.07k | transform->status = xmlSecTransformStatusFail; |
261 | 1.07k | return(-1); |
262 | 1.07k | } |
263 | | |
264 | 20.7k | ret = xmlOutputBufferClose(buf); |
265 | 20.7k | if(ret < 0) { |
266 | 4.74k | xmlSecXmlError("xmlOutputBufferClose", xmlSecTransformGetName(transform)); |
267 | 4.74k | transform->status = xmlSecTransformStatusFail; |
268 | 4.74k | return(-1); |
269 | 4.74k | } |
270 | 15.9k | transform->status = xmlSecTransformStatusFinished; |
271 | 15.9k | return(0); |
272 | 20.7k | } |
273 | | |
274 | | static int |
275 | | xmlSecTransformC14NPopBin(xmlSecTransformPtr transform, xmlSecByte* data, |
276 | | xmlSecSize maxDataSize, xmlSecSize* dataSize, |
277 | 0 | xmlSecTransformCtxPtr transformCtx) { |
278 | | /* |
279 | | * Intentionally unimplemented. The xmlsec1 sign/verify and encrypt/decrypt flows drive |
280 | | * the transform chain in push mode only: a C14N transform is always fed via PushXml and |
281 | | * writes its canonicalized result straight into the following transform, so this |
282 | | * pull-style PopBin entry point is never reached (the only pump call site pulls from the |
283 | | * InputURI source). The popBin method pointer is kept set solely so that data-type |
284 | | * negotiation (xmlSecTransformConnect) still reports a "Bin" output and connects this |
285 | | * transform to a binary consumer; if it is ever invoked we fail loudly rather than |
286 | | * produce output. |
287 | | */ |
288 | 0 | (void)transform; |
289 | 0 | (void)data; |
290 | 0 | (void)maxDataSize; |
291 | 0 | (void)dataSize; |
292 | 0 | (void)transformCtx; |
293 | 0 | xmlSecNotImplementedError("xmlSecTransformC14NPopBin"); |
294 | 0 | return(-1); |
295 | 0 | } |
296 | | |
297 | | static int |
298 | | xmlSecTransformC14NExecute(xmlSecTransformId id, xmlSecNodeSetPtr nodes, xmlSecPtrListPtr nsList, |
299 | 21.8k | xmlOutputBufferPtr buf) { |
300 | 21.8k | const char* failedFunc; |
301 | 21.8k | int ret; |
302 | | |
303 | 21.8k | xmlSecAssert2(id != xmlSecTransformIdUnknown, -1); |
304 | 21.8k | xmlSecAssert2(nodes != NULL, -1); |
305 | 21.8k | xmlSecAssert2(nodes->doc != NULL, -1); |
306 | 21.8k | xmlSecAssert2(nsList != NULL, -1); |
307 | 21.8k | xmlSecAssert2(xmlSecPtrListCheckId(nsList, xmlSecStringListId), -1); |
308 | 21.8k | xmlSecAssert2(buf != NULL, -1); |
309 | | |
310 | 21.8k | failedFunc = "xmlC14NExecute"; |
311 | | |
312 | | /* execute c14n transform */ |
313 | 21.8k | if(id == xmlSecTransformInclC14NId) { |
314 | 21.4k | ret = xmlC14NExecute(nodes->doc, |
315 | 21.4k | (xmlC14NIsVisibleCallback)xmlSecNodeSetContains, |
316 | 21.4k | nodes, XML_C14N_1_0, NULL, 0, buf); |
317 | 21.4k | } else if(id == xmlSecTransformInclC14NWithCommentsId) { |
318 | 18 | ret = xmlC14NExecute(nodes->doc, |
319 | 18 | (xmlC14NIsVisibleCallback)xmlSecNodeSetContains, |
320 | 18 | nodes, XML_C14N_1_0, NULL, 1, buf); |
321 | 350 | } else if(id == xmlSecTransformInclC14N11Id) { |
322 | 0 | ret = xmlC14NExecute(nodes->doc, |
323 | 0 | (xmlC14NIsVisibleCallback)xmlSecNodeSetContains, |
324 | 0 | nodes, XML_C14N_1_1, NULL, 0, buf); |
325 | 350 | } else if(id == xmlSecTransformInclC14N11WithCommentsId) { |
326 | 52 | ret = xmlC14NExecute(nodes->doc, |
327 | 52 | (xmlC14NIsVisibleCallback)xmlSecNodeSetContains, |
328 | 52 | nodes, XML_C14N_1_1, NULL, 1, buf); |
329 | 298 | } else if((id == xmlSecTransformExclC14NId) || (id == xmlSecTransformExclC14NWithCommentsId)) { |
330 | 0 | xmlChar** nsListData; |
331 | 0 | xmlSecSize nsListSize; |
332 | 0 | int withComments; |
333 | | |
334 | | /* LibXML2 expects the list of inclusive namespace prefixes terminated with a NULL. |
335 | | * We already add the NULL at the end in xmlSecTransformC14NNodeRead() but |
336 | | * let's double-check just in case */ |
337 | 0 | nsListSize = xmlSecPtrListGetSize(nsList); |
338 | 0 | if((nsListSize == 0) || (xmlSecPtrListGetItem(nsList, nsListSize - 1) != NULL)) { |
339 | 0 | ret = xmlSecPtrListAdd(nsList, NULL); |
340 | 0 | if(ret < 0) { |
341 | 0 | xmlSecInternalError("xmlSecPtrListAdd", xmlSecTransformKlassGetName(id)); |
342 | 0 | return(-1); |
343 | 0 | } |
344 | 0 | } |
345 | | |
346 | | /* HACK: we know that xmlSecPtrList keeps all pointers |
347 | | * in a contiguous array */ |
348 | 0 | nsListData = (xmlChar**)nsList->data; |
349 | 0 | withComments = (id == xmlSecTransformExclC14NWithCommentsId); |
350 | 0 | ret = xmlC14NExecute(nodes->doc, |
351 | 0 | (xmlC14NIsVisibleCallback)xmlSecNodeSetContains, |
352 | 0 | nodes, XML_C14N_EXCLUSIVE_1_0, nsListData, withComments, buf); |
353 | 298 | } else if(id == xmlSecTransformRemoveXmlTagsC14NId) { |
354 | 298 | failedFunc = "xmlSecNodeSetDumpTextNodes"; |
355 | 298 | ret = xmlSecNodeSetDumpTextNodes(nodes, buf); |
356 | 298 | } else { |
357 | | /* this should not be reachable */ |
358 | 0 | xmlSecOtherError(XMLSEC_ERRORS_R_INVALID_TRANSFORM, |
359 | 0 | xmlSecTransformKlassGetName(id), NULL); |
360 | 0 | return(-1); |
361 | 0 | } |
362 | | |
363 | 21.8k | if(ret < 0) { |
364 | 1.07k | xmlSecXmlError(failedFunc, xmlSecTransformKlassGetName(id)); |
365 | 1.07k | return(-1); |
366 | 1.07k | } |
367 | | |
368 | 20.7k | return(0); |
369 | 21.8k | } |
370 | | |
371 | | /****************************************************************************** |
372 | | * |
373 | | * C14N |
374 | | * |
375 | | *****************************************************************************/ |
376 | | static xmlSecTransformKlass xmlSecTransformInclC14NKlass = { |
377 | | /* klass/object sizes */ |
378 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
379 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
380 | | |
381 | | xmlSecNameC14N, /* const xmlChar* name; */ |
382 | | xmlSecHrefC14N, /* const xmlChar* href; */ |
383 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
384 | | /* xmlSecTransformUsage usage; */ |
385 | | |
386 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
387 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
388 | | NULL, /* xmlSecTransformNodeReadMethod readNode; */ |
389 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
390 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
391 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
392 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
393 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
394 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
395 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
396 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
397 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
398 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
399 | | |
400 | | NULL, /* void* reserved0; */ |
401 | | NULL, /* void* reserved1; */ |
402 | | }; |
403 | | |
404 | | /** |
405 | | * @brief Gets the inclusive C14N transform klass. |
406 | | * @details Inclusive (regular) canonicalization that omits comments transform klass |
407 | | * (http://www.w3.org/TR/xmldsig-core/#sec-c14nAlg and |
408 | | * http://www.w3.org/TR/2001/REC-xml-c14n-20010315). |
409 | | * @return c14n transform id. |
410 | | */ |
411 | | xmlSecTransformId |
412 | 127k | xmlSecTransformInclC14NGetKlass(void) { |
413 | 127k | return(&xmlSecTransformInclC14NKlass); |
414 | 127k | } |
415 | | |
416 | | /****************************************************************************** |
417 | | * |
418 | | * C14N With Comments |
419 | | * |
420 | | *****************************************************************************/ |
421 | | static xmlSecTransformKlass xmlSecTransformInclC14NWithCommentsKlass = { |
422 | | /* klass/object sizes */ |
423 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
424 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
425 | | |
426 | | xmlSecNameC14NWithComments, /* const xmlChar* name; */ |
427 | | xmlSecHrefC14NWithComments, /* const xmlChar* href; */ |
428 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
429 | | /* xmlSecTransformUsage usage; */ |
430 | | |
431 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
432 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
433 | | NULL, /* xmlSecTransformNodeReadMethod readNode; */ |
434 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
435 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
436 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
437 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
438 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
439 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
440 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
441 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
442 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
443 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
444 | | |
445 | | NULL, /* void* reserved0; */ |
446 | | NULL, /* void* reserved1; */ |
447 | | }; |
448 | | |
449 | | /** |
450 | | * @brief Gets the inclusive C14N with comments transform klass. |
451 | | * @details Inclusive (regular) canonicalization that includes comments transform klass |
452 | | * (http://www.w3.org/TR/xmldsig-core/#sec-c14nAlg and |
453 | | * http://www.w3.org/TR/2001/REC-xml-c14n-20010315). |
454 | | * @return c14n with comments transform id. |
455 | | */ |
456 | | xmlSecTransformId |
457 | 1.64k | xmlSecTransformInclC14NWithCommentsGetKlass(void) { |
458 | 1.64k | return(&xmlSecTransformInclC14NWithCommentsKlass); |
459 | 1.64k | } |
460 | | |
461 | | /****************************************************************************** |
462 | | * |
463 | | * C14N v1.1 |
464 | | * |
465 | | *****************************************************************************/ |
466 | | static xmlSecTransformKlass xmlSecTransformInclC14N11Klass = { |
467 | | /* klass/object sizes */ |
468 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
469 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
470 | | |
471 | | xmlSecNameC14N11, /* const xmlChar* name; */ |
472 | | xmlSecHrefC14N11, /* const xmlChar* href; */ |
473 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
474 | | /* xmlSecTransformUsage usage; */ |
475 | | |
476 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
477 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
478 | | NULL, /* xmlSecTransformNodeReadMethod readNode; */ |
479 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
480 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
481 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
482 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
483 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
484 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
485 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
486 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
487 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
488 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
489 | | |
490 | | NULL, /* void* reserved0; */ |
491 | | NULL, /* void* reserved1; */ |
492 | | }; |
493 | | |
494 | | /** |
495 | | * @brief Gets the C14N v1.1 transform klass. |
496 | | * @details C14N version 1.1 (http://www.w3.org/TR/xml-c14n11) |
497 | | * @return c14n v1.1 transform id. |
498 | | */ |
499 | | xmlSecTransformId |
500 | 1.56k | xmlSecTransformInclC14N11GetKlass(void) { |
501 | 1.56k | return(&xmlSecTransformInclC14N11Klass); |
502 | 1.56k | } |
503 | | |
504 | | /****************************************************************************** |
505 | | * |
506 | | * C14N v1.1 With Comments |
507 | | * |
508 | | *****************************************************************************/ |
509 | | static xmlSecTransformKlass xmlSecTransformInclC14N11WithCommentsKlass = { |
510 | | /* klass/object sizes */ |
511 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
512 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
513 | | |
514 | | xmlSecNameC14N11WithComments, /* const xmlChar* name; */ |
515 | | xmlSecHrefC14N11WithComments, /* const xmlChar* href; */ |
516 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
517 | | /* xmlSecTransformUsage usage; */ |
518 | | |
519 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
520 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
521 | | NULL, /* xmlSecTransformNodeReadMethod readNode; */ |
522 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
523 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
524 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
525 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
526 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
527 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
528 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
529 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
530 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
531 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
532 | | |
533 | | NULL, /* void* reserved0; */ |
534 | | NULL, /* void* reserved1; */ |
535 | | }; |
536 | | |
537 | | /** |
538 | | * @brief Gets the C14N v1.1 with comments transform klass. |
539 | | * @details C14N version 1.1 (http://www.w3.org/TR/xml-c14n11) with comments |
540 | | * @return c14n v1.1 with comments transform id. |
541 | | */ |
542 | | xmlSecTransformId |
543 | 1.56k | xmlSecTransformInclC14N11WithCommentsGetKlass(void) { |
544 | 1.56k | return(&xmlSecTransformInclC14N11WithCommentsKlass); |
545 | 1.56k | } |
546 | | |
547 | | |
548 | | /****************************************************************************** |
549 | | * |
550 | | * Excl C14N |
551 | | * |
552 | | *****************************************************************************/ |
553 | | static xmlSecTransformKlass xmlSecTransformExclC14NKlass = { |
554 | | /* klass/object sizes */ |
555 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
556 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
557 | | |
558 | | xmlSecNameExcC14N, /* const xmlChar* name; */ |
559 | | xmlSecHrefExcC14N, /* const xmlChar* href; */ |
560 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
561 | | /* xmlSecTransformUsage usage; */ |
562 | | |
563 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
564 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
565 | | xmlSecTransformC14NNodeRead, /* xmlSecTransformNodeReadMethod readNode; */ |
566 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
567 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
568 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
569 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
570 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
571 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
572 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
573 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
574 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
575 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
576 | | |
577 | | NULL, /* void* reserved0; */ |
578 | | NULL, /* void* reserved1; */ |
579 | | }; |
580 | | |
581 | | /** |
582 | | * @brief Gets the exclusive C14N transform klass. |
583 | | * @details Exclusive canonicalization that omits comments transform klass |
584 | | * (http://www.w3.org/TR/xml-exc-c14n/). |
585 | | * @return exclusive c14n transform id. |
586 | | */ |
587 | | xmlSecTransformId |
588 | 1.35k | xmlSecTransformExclC14NGetKlass(void) { |
589 | 1.35k | return(&xmlSecTransformExclC14NKlass); |
590 | 1.35k | } |
591 | | |
592 | | /****************************************************************************** |
593 | | * |
594 | | * Excl C14N With Comments |
595 | | * |
596 | | *****************************************************************************/ |
597 | | static xmlSecTransformKlass xmlSecTransformExclC14NWithCommentsKlass = { |
598 | | /* klass/object sizes */ |
599 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
600 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
601 | | |
602 | | xmlSecNameExcC14NWithComments, /* const xmlChar* name; */ |
603 | | xmlSecHrefExcC14NWithComments, /* const xmlChar* href; */ |
604 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
605 | | /* xmlSecTransformUsage usage; */ |
606 | | |
607 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
608 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
609 | | xmlSecTransformC14NNodeRead, /* xmlSecTransformNodeReadMethod readNode; */ |
610 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
611 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
612 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
613 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
614 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
615 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
616 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
617 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
618 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
619 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
620 | | |
621 | | NULL, /* void* reserved0; */ |
622 | | NULL, /* void* reserved1; */ |
623 | | }; |
624 | | |
625 | | /** |
626 | | * @brief Gets the exclusive C14N with comments transform klass. |
627 | | * @details Exclusive canonicalization that includes comments transform klass |
628 | | * (http://www.w3.org/TR/xml-exc-c14n/). |
629 | | * @return exclusive c14n with comments transform id. |
630 | | */ |
631 | | xmlSecTransformId |
632 | 1.35k | xmlSecTransformExclC14NWithCommentsGetKlass(void) { |
633 | 1.35k | return(&xmlSecTransformExclC14NWithCommentsKlass); |
634 | 1.35k | } |
635 | | |
636 | | /****************************************************************************** |
637 | | * |
638 | | * Remove XML tags C14N |
639 | | * |
640 | | *****************************************************************************/ |
641 | | static xmlSecTransformKlass xmlSecTransformRemoveXmlTagsC14NKlass = { |
642 | | /* klass/object sizes */ |
643 | | sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */ |
644 | | xmlSecC14NSize, /* xmlSecSize objSize */ |
645 | | |
646 | | BAD_CAST "remove-xml-tags-transform", /* const xmlChar* name; */ |
647 | | NULL, /* const xmlChar* href; */ |
648 | | xmlSecTransformUsageC14NMethod | xmlSecTransformUsageDSigTransform, |
649 | | /* xmlSecTransformUsage usage; */ |
650 | | |
651 | | xmlSecTransformC14NInitialize, /* xmlSecTransformInitializeMethod initialize; */ |
652 | | xmlSecTransformC14NFinalize, /* xmlSecTransformFinalizeMethod finalize; */ |
653 | | NULL, /* xmlSecTransformNodeReadMethod readNode; */ |
654 | | NULL, /* xmlSecTransformNodeWriteMethod writeNode; */ |
655 | | NULL, /* xmlSecTransformSetKeyRequirementsMethod setKeyReq; */ |
656 | | NULL, /* xmlSecTransformSetKeyMethod setKey; */ |
657 | | NULL, /* xmlSecTransformVerifyMethod verify; */ |
658 | | xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */ |
659 | | NULL, /* xmlSecTransformPushBinMethod pushBin; */ |
660 | | xmlSecTransformC14NPopBin, /* xmlSecTransformPopBinMethod popBin; */ |
661 | | xmlSecTransformC14NPushXml, /* xmlSecTransformPushXmlMethod pushXml; */ |
662 | | NULL, /* xmlSecTransformPopXmlMethod popXml; */ |
663 | | NULL, /* xmlSecTransformExecuteMethod execute; */ |
664 | | |
665 | | NULL, /* void* reserved0; */ |
666 | | NULL, /* void* reserved1; */ |
667 | | }; |
668 | | |
669 | | /** |
670 | | * @brief Gets the 'remove xml tags' transform klass. |
671 | | * @details The "remove xml tags" transform is an xmlsec-specific helper that |
672 | | * performs the node-set to octet stream conversion described in the Base64 |
673 | | * section of the XML Digital Signature specification |
674 | | * (http://www.w3.org/TR/xmldsig-core/#sec-Base-64): the Base64 transform |
675 | | * requires an octet stream for input, and if an XPath node-set (or |
676 | | * sufficiently functional alternative) is given as input, it is converted to |
677 | | * an octet stream by performing operations logically equivalent to 1) |
678 | | * applying an XPath transform with expression self::text(), then 2) taking |
679 | | * the string-value of the node-set. Thus, if an XML element is identified by |
680 | | * a barename XPointer in the Reference URI, and its content consists solely |
681 | | * of base64 encoded character data, then this transform automatically strips |
682 | | * away the start and end tags of the identified element and any of its |
683 | | * descendant elements as well as any descendant comments and processing |
684 | | * instructions. The output of this transform is an octet stream. |
685 | | * @return "remove xml tags" transform id. |
686 | | */ |
687 | | xmlSecTransformId |
688 | 1.70k | xmlSecTransformRemoveXmlTagsC14NGetKlass(void) { |
689 | 1.70k | return(&xmlSecTransformRemoveXmlTagsC14NKlass); |
690 | 1.70k | } |