1 /*
2  * XML Security Library (http://www.aleksey.com/xmlsec).
3  *
4  * The transforms engine
5  *
6  * This is free software; see Copyright file in the source
7  * distribution for preciese wording.
8  *
9  * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
10  */
11 #ifndef __XMLSEC_TRANSFORMS_H__
12 #define __XMLSEC_TRANSFORMS_H__
13 
14 #include <libxml/tree.h>
15 #include <libxml/xpath.h>
16 
17 #include <xmlsec/xmlsec.h>
18 #include <xmlsec/buffer.h>
19 #include <xmlsec/list.h>
20 #include <xmlsec/nodeset.h>
21 #include <xmlsec/keys.h>
22 
23 #ifndef XMLSEC_NO_XSLT
24 #include <libxslt/security.h>
25 #endif /* XMLSEC_NO_XSLT */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30 
31 typedef const struct _xmlSecTransformKlass              xmlSecTransformKlass,
32                                                         *xmlSecTransformId;
33 
34 /**
35  * XMLSEC_TRANSFORM_BINARY_CHUNK:
36  *
37  * The binary data chunks size. XMLSec processes binary data one chunk
38  * at a time. Changing this impacts xmlsec memory usage and performance.
39  */
40 #define XMLSEC_TRANSFORM_BINARY_CHUNK                   1024
41 
42 /**********************************************************************
43  *
44  * High-level functions
45  *
46  *********************************************************************/
47 XMLSEC_EXPORT xmlSecPtrListPtr  xmlSecTransformIdsGet           (void);
48 XMLSEC_EXPORT int               xmlSecTransformIdsInit          (void);
49 XMLSEC_EXPORT void              xmlSecTransformIdsShutdown      (void);
50 XMLSEC_EXPORT int               xmlSecTransformIdsRegisterDefault(void);
51 XMLSEC_EXPORT int               xmlSecTransformIdsRegister      (xmlSecTransformId id);
52 
53 /**
54  * xmlSecTransformStatus:
55  * @xmlSecTransformStatusNone:          the status unknown.
56  * @xmlSecTransformStatusWorking:       the transform is executed.
57  * @xmlSecTransformStatusFinished:      the transform finished
58  * @xmlSecTransformStatusOk:            the transform succeeded.
59  * @xmlSecTransformStatusFail:          the transform failed (an error occur).
60  *
61  * The transform execution status.
62  */
63 typedef enum  {
64     xmlSecTransformStatusNone = 0,
65     xmlSecTransformStatusWorking,
66     xmlSecTransformStatusFinished,
67     xmlSecTransformStatusOk,
68     xmlSecTransformStatusFail
69 } xmlSecTransformStatus;
70 
71 /**
72  * xmlSecTransformMode:
73  * @xmlSecTransformModeNone:            the mode is unknown.
74  * @xmlSecTransformModePush:            pushing data thru transform.
75  * @xmlSecTransformModePop:             popping data from transform.
76  *
77  * The transform operation mode
78  */
79 typedef enum  {
80     xmlSecTransformModeNone = 0,
81     xmlSecTransformModePush,
82     xmlSecTransformModePop
83 } xmlSecTransformMode;
84 
85 /**
86  * xmlSecTransformOperation:
87  * @xmlSecTransformOperationNone:       the operation is unknown.
88  * @xmlSecTransformOperationEncode:     the encode operation (for base64 transform).
89  * @xmlSecTransformOperationDecode:     the decode operation (for base64 transform).
90  * @xmlSecTransformOperationSign:       the sign or digest operation.
91  * @xmlSecTransformOperationVerify:     the verification of signature or digest operation.
92  * @xmlSecTransformOperationEncrypt:    the encryption operation.
93  * @xmlSecTransformOperationDecrypt:    the decryption operation.
94  *
95  * The transform operation.
96  */
97 typedef enum  {
98     xmlSecTransformOperationNone = 0,
99     xmlSecTransformOperationEncode,
100     xmlSecTransformOperationDecode,
101     xmlSecTransformOperationSign,
102     xmlSecTransformOperationVerify,
103     xmlSecTransformOperationEncrypt,
104     xmlSecTransformOperationDecrypt
105 } xmlSecTransformOperation;
106 
107 /**************************************************************************
108  *
109  * xmlSecTransformUriType:
110  *
111  *************************************************************************/
112 /**
113  * xmlSecTransformUriType:
114  *
115  * URI transform type bit mask.
116  */
117 typedef unsigned int                            xmlSecTransformUriType;
118 
119 /**
120  * xmlSecTransformUriTypeNone:
121  *
122  * The URI type is unknown or not set.
123  */
124 #define xmlSecTransformUriTypeNone              0x0000
125 
126 /**
127  * xmlSecTransformUriTypeEmpty:
128  *
129  * The empty URI ("") type.
130  */
131 #define xmlSecTransformUriTypeEmpty             0x0001
132 
133 /**
134  * xmlSecTransformUriTypeSameDocument:
135  *
136  * The same document ("#...") but not empty ("") URI type.
137  */
138 #define xmlSecTransformUriTypeSameDocument      0x0002
139 
140 /**
141  * xmlSecTransformUriTypeLocal:
142  *
143  * The local URI ("file:///....") type.
144  */
145 #define xmlSecTransformUriTypeLocal             0x0004
146 
147 /**
148  * xmlSecTransformUriTypeRemote:
149  *
150  * The remote URI type.
151  */
152 #define xmlSecTransformUriTypeRemote            0x0008
153 
154 /**
155  * xmlSecTransformUriTypeAny:
156  *
157  * Any URI type.
158  */
159 #define xmlSecTransformUriTypeAny               0xFFFF
160 
161 XMLSEC_EXPORT int                       xmlSecTransformUriTypeCheck     (xmlSecTransformUriType type,
162                                                                          const xmlChar* uri);
163 /**************************************************************************
164  *
165  * xmlSecTransformDataType
166  *
167  *************************************************************************/
168 /**
169  * xmlSecTransformDataType:
170  *
171  * Transform data type bit mask.
172  */
173 typedef xmlSecByte                              xmlSecTransformDataType;
174 
175 /**
176  * xmlSecTransformDataTypeUnknown:
177  *
178  * The transform data type is unknown or nor data expected.
179  */
180 #define xmlSecTransformDataTypeUnknown          0x0000
181 
182 /**
183  * xmlSecTransformDataTypeBin:
184  *
185  * The binary transform data.
186  */
187 #define xmlSecTransformDataTypeBin              0x0001
188 
189 /**
190  * xmlSecTransformDataTypeXml:
191  *
192  * The xml transform data.
193  */
194 #define xmlSecTransformDataTypeXml              0x0002
195 
196 /**************************************************************************
197  *
198  * xmlSecTransformUsage
199  *
200  *************************************************************************/
201 /**
202  * xmlSecTransformUsage:
203  *
204  * The transform usage bit mask.
205  */
206 typedef unsigned int                            xmlSecTransformUsage;
207 
208 /**
209  * xmlSecTransformUsageUnknown:
210  *
211  * Transforms usage is unknown or undefined.
212  */
213 #define xmlSecTransformUsageUnknown             0x0000
214 
215 /**
216  * xmlSecTransformUsageDSigTransform:
217  *
218  * Transform could be used in <dsig:Transform>.
219  */
220 #define xmlSecTransformUsageDSigTransform       0x0001
221 
222 /**
223  * xmlSecTransformUsageC14NMethod:
224  *
225  * Transform could be used in <dsig:CanonicalizationMethod>.
226  */
227 #define xmlSecTransformUsageC14NMethod          0x0002
228 
229 /**
230  * xmlSecTransformUsageDigestMethod:
231  *
232  * Transform could be used in <dsig:DigestMethod>.
233  */
234 #define xmlSecTransformUsageDigestMethod        0x0004
235 
236 /**
237  * xmlSecTransformUsageSignatureMethod:
238  *
239  * Transform could be used in <dsig:SignatureMethod>.
240  */
241 #define xmlSecTransformUsageSignatureMethod     0x0008
242 
243 /**
244  * xmlSecTransformUsageEncryptionMethod:
245  *
246  * Transform could be used in <enc:EncryptionMethod>.
247  */
248 #define xmlSecTransformUsageEncryptionMethod    0x0010
249 
250 /**
251  * xmlSecTransformUsageAny:
252  *
253  * Transform could be used for operation.
254  */
255 #define xmlSecTransformUsageAny                 0xFFFF
256 
257 /**************************************************************************
258  *
259  * xmlSecTransformCtx
260  *
261  *************************************************************************/
262 /**
263  * xmlSecTransformCtxPreExecuteCallback:
264  * @transformCtx:       the pointer to transform's context.
265  *
266  * The callback called after creating transforms chain but before
267  * starting data processing. Application can use this callback to
268  * do additional transforms chain verification or modification and
269  * aborting transforms execution (if necessary).
270  *
271  * Returns: 0 on success and a negative value otherwise (in this case,
272  * transforms chain will not be executed and xmlsec processing stops).
273  */
274 typedef int             (*xmlSecTransformCtxPreExecuteCallback)         (xmlSecTransformCtxPtr transformCtx);
275 
276 /**
277  * XMLSEC_TRANSFORMCTX_FLAGS_USE_VISA3D_HACK:
278  *
279  * If this flag is set then URI ID references are resolved directly
280  * without using XPointers. This allows one to sign/verify Visa3D
281  * documents that don't follow XML, XPointer and XML DSig specifications.
282  */
283 #define XMLSEC_TRANSFORMCTX_FLAGS_USE_VISA3D_HACK               0x00000001
284 
285 /**
286  * xmlSecTransformCtx:
287  * @userData:           the pointer to user data (xmlsec and xmlsec-crypto never
288  *                      touch this).
289  * @flags:              the bit mask flags to control transforms execution
290  *                      (reserved for the future).
291  * @flags2:             the bit mask flags to control transforms execution
292  *                      (reserved for the future).
293  * @enabledUris:        the allowed transform data source uri types.
294  * @enabledTransforms:  the list of enabled transforms; if list is empty (default)
295  *                      then all registered transforms are enabled.
296  * @preExecCallback:    the callback called after preparing transform chain
297  *                      and right before actual data processing; application
298  *                      can use this callback to change transforms parameters,
299  *                      insert additional transforms in the chain or do
300  *                      additional validation (and abort transform execution
301  *                      if needed).
302  * @result:             the pointer to transforms result buffer.
303  * @status:             the transforms chain processing status.
304  * @uri:                the data source URI without xpointer expression.
305  * @xptrExpr:           the xpointer expression from data source URI (if any).
306  * @first:              the first transform in the chain.
307  * @last:               the last transform in the chain.
308  * @reserved0:          reserved for the future.
309  * @reserved1:          reserved for the future.
310  *
311  * The transform execution context.
312  */
313 struct _xmlSecTransformCtx {
314     /* user settings */
315     void*                                       userData;
316     unsigned int                                flags;
317     unsigned int                                flags2;
318     xmlSecTransformUriType                      enabledUris;
319     xmlSecPtrList                               enabledTransforms;
320     xmlSecTransformCtxPreExecuteCallback        preExecCallback;
321 
322     /* results */
323     xmlSecBufferPtr                             result;
324     xmlSecTransformStatus                       status;
325     xmlChar*                                    uri;
326     xmlChar*                                    xptrExpr;
327     xmlSecTransformPtr                          first;
328     xmlSecTransformPtr                          last;
329 
330     /* for the future */
331     void*                                       reserved0;
332     void*                                       reserved1;
333 };
334 
335 XMLSEC_EXPORT xmlSecTransformCtxPtr     xmlSecTransformCtxCreate        (void);
336 XMLSEC_EXPORT void                      xmlSecTransformCtxDestroy       (xmlSecTransformCtxPtr ctx);
337 XMLSEC_EXPORT int                       xmlSecTransformCtxInitialize    (xmlSecTransformCtxPtr ctx);
338 XMLSEC_EXPORT void                      xmlSecTransformCtxFinalize      (xmlSecTransformCtxPtr ctx);
339 XMLSEC_EXPORT void                      xmlSecTransformCtxReset         (xmlSecTransformCtxPtr ctx);
340 XMLSEC_EXPORT int                       xmlSecTransformCtxCopyUserPref  (xmlSecTransformCtxPtr dst,
341                                                                          xmlSecTransformCtxPtr src);
342 XMLSEC_EXPORT int                       xmlSecTransformCtxSetUri        (xmlSecTransformCtxPtr ctx,
343                                                                          const xmlChar* uri,
344                                                                          xmlNodePtr hereNode);
345 XMLSEC_EXPORT int                       xmlSecTransformCtxAppend        (xmlSecTransformCtxPtr ctx,
346                                                                          xmlSecTransformPtr transform);
347 XMLSEC_EXPORT int                       xmlSecTransformCtxPrepend       (xmlSecTransformCtxPtr ctx,
348                                                                          xmlSecTransformPtr transform);
349 XMLSEC_EXPORT xmlSecTransformPtr        xmlSecTransformCtxCreateAndAppend(xmlSecTransformCtxPtr ctx,
350                                                                          xmlSecTransformId id);
351 XMLSEC_EXPORT xmlSecTransformPtr        xmlSecTransformCtxCreateAndPrepend(xmlSecTransformCtxPtr ctx,
352                                                                          xmlSecTransformId id);
353 XMLSEC_EXPORT xmlSecTransformPtr        xmlSecTransformCtxNodeRead      (xmlSecTransformCtxPtr ctx,
354                                                                          xmlNodePtr node,
355                                                                          xmlSecTransformUsage usage);
356 XMLSEC_EXPORT int                       xmlSecTransformCtxNodesListRead (xmlSecTransformCtxPtr ctx,
357                                                                          xmlNodePtr node,
358                                                                          xmlSecTransformUsage usage);
359 XMLSEC_EXPORT int                       xmlSecTransformCtxPrepare       (xmlSecTransformCtxPtr ctx,
360                                                                          xmlSecTransformDataType inputDataType);
361 XMLSEC_EXPORT int                       xmlSecTransformCtxBinaryExecute (xmlSecTransformCtxPtr ctx,
362                                                                          const xmlSecByte* data,
363                                                                          xmlSecSize dataSize);
364 XMLSEC_EXPORT int                       xmlSecTransformCtxUriExecute    (xmlSecTransformCtxPtr ctx,
365                                                                          const xmlChar* uri);
366 XMLSEC_EXPORT int                       xmlSecTransformCtxXmlExecute    (xmlSecTransformCtxPtr ctx,
367                                                                          xmlSecNodeSetPtr nodes);
368 XMLSEC_EXPORT int                       xmlSecTransformCtxExecute       (xmlSecTransformCtxPtr ctx,
369                                                                          xmlDocPtr doc);
370 XMLSEC_EXPORT void                      xmlSecTransformCtxDebugDump     (xmlSecTransformCtxPtr ctx,
371                                                                         FILE* output);
372 XMLSEC_EXPORT void                      xmlSecTransformCtxDebugXmlDump  (xmlSecTransformCtxPtr ctx,
373                                                                          FILE* output);
374 
375 /**************************************************************************
376  *
377  * xmlSecTransform
378  *
379  *************************************************************************/
380 /**
381  * xmlSecTransform:
382  * @id:                 the transform id (pointer to #xmlSecTransformId).
383  * @operation:          the transform's operation.
384  * @status:             the current status.
385  * @hereNode:           the pointer to transform's <dsig:Transform /> node.
386  * @next:               the pointer to next transform in the chain.
387  * @prev:               the pointer to previous transform in the chain.
388  * @inBuf:              the input binary data buffer.
389  * @outBuf:             the output binary data buffer.
390  * @inNodes:            the input XML nodes.
391  * @outNodes:           the output XML nodes.
392  * @reserved0:          reserved for the future.
393  * @reserved1:          reserved for the future.
394  *
395  * The transform structure.
396  */
397 struct _xmlSecTransform {
398     xmlSecTransformId                   id;
399     xmlSecTransformOperation            operation;
400     xmlSecTransformStatus               status;
401     xmlNodePtr                          hereNode;
402 
403     /* transforms chain */
404     xmlSecTransformPtr                  next;
405     xmlSecTransformPtr                  prev;
406 
407     /* binary data */
408     xmlSecBuffer                        inBuf;
409     xmlSecBuffer                        outBuf;
410 
411     /* xml data */
412     xmlSecNodeSetPtr                    inNodes;
413     xmlSecNodeSetPtr                    outNodes;
414 
415     /* reserved for the future */
416     void*                               reserved0;
417     void*                               reserved1;
418 };
419 
420 XMLSEC_EXPORT xmlSecTransformPtr        xmlSecTransformCreate   (xmlSecTransformId id);
421 XMLSEC_EXPORT void                      xmlSecTransformDestroy  (xmlSecTransformPtr transform);
422 XMLSEC_EXPORT xmlSecTransformPtr        xmlSecTransformNodeRead (xmlNodePtr node,
423                                                                  xmlSecTransformUsage usage,
424                                                                  xmlSecTransformCtxPtr transformCtx);
425 XMLSEC_EXPORT int                       xmlSecTransformPump     (xmlSecTransformPtr left,
426                                                                  xmlSecTransformPtr right,
427                                                                  xmlSecTransformCtxPtr transformCtx);
428 XMLSEC_EXPORT int                       xmlSecTransformSetKey   (xmlSecTransformPtr transform,
429                                                                  xmlSecKeyPtr key);
430 XMLSEC_EXPORT int                       xmlSecTransformSetKeyReq(xmlSecTransformPtr transform,
431                                                                  xmlSecKeyReqPtr keyReq);
432 XMLSEC_EXPORT int                       xmlSecTransformVerify   (xmlSecTransformPtr transform,
433                                                                  const xmlSecByte* data,
434                                                                  xmlSecSize dataSize,
435                                                                  xmlSecTransformCtxPtr transformCtx);
436 XMLSEC_EXPORT int                       xmlSecTransformVerifyNodeContent(xmlSecTransformPtr transform,
437                                                                  xmlNodePtr node,
438                                                                  xmlSecTransformCtxPtr transformCtx);
439 XMLSEC_EXPORT xmlSecTransformDataType   xmlSecTransformGetDataType(xmlSecTransformPtr transform,
440                                                                  xmlSecTransformMode mode,
441                                                                  xmlSecTransformCtxPtr transformCtx);
442 XMLSEC_EXPORT int                       xmlSecTransformPushBin  (xmlSecTransformPtr transform,
443                                                                  const xmlSecByte* data,
444                                                                  xmlSecSize dataSize,
445                                                                  int final,
446                                                                  xmlSecTransformCtxPtr transformCtx);
447 XMLSEC_EXPORT int                       xmlSecTransformPopBin   (xmlSecTransformPtr transform,
448                                                                  xmlSecByte* data,
449                                                                  xmlSecSize maxDataSize,
450                                                                  xmlSecSize* dataSize,
451                                                                  xmlSecTransformCtxPtr transformCtx);
452 XMLSEC_EXPORT int                       xmlSecTransformPushXml  (xmlSecTransformPtr transform,
453                                                                  xmlSecNodeSetPtr nodes,
454                                                                  xmlSecTransformCtxPtr transformCtx);
455 XMLSEC_EXPORT int                       xmlSecTransformPopXml   (xmlSecTransformPtr transform,
456                                                                  xmlSecNodeSetPtr* nodes,
457                                                                  xmlSecTransformCtxPtr transformCtx);
458 XMLSEC_EXPORT int                       xmlSecTransformExecute  (xmlSecTransformPtr transform,
459                                                                  int last,
460                                                                  xmlSecTransformCtxPtr transformCtx);
461 XMLSEC_EXPORT void                      xmlSecTransformDebugDump(xmlSecTransformPtr transform,
462                                                                  FILE* output);
463 XMLSEC_EXPORT void                      xmlSecTransformDebugXmlDump(xmlSecTransformPtr transform,
464                                                                  FILE* output);
465 /**
466  * xmlSecTransformGetName:
467  * @transform:          the pointer to transform.
468  *
469  * Macro. Returns transform name.
470  */
471 #define xmlSecTransformGetName(transform) \
472         ((xmlSecTransformIsValid((transform))) ? \
473           xmlSecTransformKlassGetName((transform)->id) : NULL)
474 
475 /**
476  * xmlSecTransformIsValid:
477  * @transform:          the pointer to transform.
478  *
479  * Macro. Returns 1 if the @transform is valid or 0 otherwise.
480  */
481 #define xmlSecTransformIsValid(transform) \
482         ((( transform ) != NULL) && \
483          (( transform )->id != NULL) && \
484          (( transform )->id->klassSize >= sizeof(xmlSecTransformKlass)) && \
485          (( transform )->id->objSize >= sizeof(xmlSecTransform)) && \
486          (( transform )->id->name != NULL))
487 
488 /**
489  * xmlSecTransformCheckId:
490  * @transform:          the pointer to transform.
491  * @i:                  the transform id.
492  *
493  * Macro. Returns 1 if the @transform is valid and has specified id @i
494  * or 0 otherwise.
495  */
496 #define xmlSecTransformCheckId(transform, i) \
497         (xmlSecTransformIsValid(( transform )) && \
498         ((((const xmlSecTransformId) (( transform )->id))) == ( i )))
499 
500 /**
501  * xmlSecTransformCheckSize:
502  * @transform:          the pointer to transform.
503  * @size:               the transform object size.
504  *
505  * Macro. Returns 1 if the @transform is valid and has at least @size
506  * bytes or 0 otherwise.
507  */
508 #define xmlSecTransformCheckSize(transform, size) \
509         (xmlSecTransformIsValid(( transform )) && \
510         ((( transform )->id->objSize) >= ( size )))
511 
512 
513 /************************************************************************
514  *
515  * Operations on transforms chain
516  *
517  ************************************************************************/
518 XMLSEC_EXPORT int                       xmlSecTransformConnect  (xmlSecTransformPtr left,
519                                                                  xmlSecTransformPtr right,
520                                                                  xmlSecTransformCtxPtr transformCtx);
521 XMLSEC_EXPORT void                      xmlSecTransformRemove   (xmlSecTransformPtr transform);
522 
523 /************************************************************************
524  *
525  * Default callbacks, most of the transforms can use them
526  *
527  ************************************************************************/
528 XMLSEC_EXPORT xmlSecTransformDataType   xmlSecTransformDefaultGetDataType(xmlSecTransformPtr transform,
529                                                                  xmlSecTransformMode mode,
530                                                                  xmlSecTransformCtxPtr transformCtx);
531 XMLSEC_EXPORT int                       xmlSecTransformDefaultPushBin(xmlSecTransformPtr transform,
532                                                                  const xmlSecByte* data,
533                                                                  xmlSecSize dataSize,
534                                                                  int final,
535                                                                  xmlSecTransformCtxPtr transformCtx);
536 XMLSEC_EXPORT int                       xmlSecTransformDefaultPopBin(xmlSecTransformPtr transform,
537                                                                  xmlSecByte* data,
538                                                                  xmlSecSize maxDataSize,
539                                                                  xmlSecSize* dataSize,
540                                                                  xmlSecTransformCtxPtr transformCtx);
541 XMLSEC_EXPORT int                       xmlSecTransformDefaultPushXml(xmlSecTransformPtr transform,
542                                                                  xmlSecNodeSetPtr nodes,
543                                                                  xmlSecTransformCtxPtr transformCtx);
544 XMLSEC_EXPORT int                       xmlSecTransformDefaultPopXml(xmlSecTransformPtr transform,
545                                                                  xmlSecNodeSetPtr* nodes,
546                                                                  xmlSecTransformCtxPtr transformCtx);
547 
548 /************************************************************************
549  *
550  * IO buffers for transforms
551  *
552  ************************************************************************/
553 XMLSEC_EXPORT xmlOutputBufferPtr        xmlSecTransformCreateOutputBuffer(xmlSecTransformPtr transform,
554                                                                  xmlSecTransformCtxPtr transformCtx);
555 XMLSEC_EXPORT xmlParserInputBufferPtr   xmlSecTransformCreateInputBuffer(xmlSecTransformPtr transform,
556                                                                  xmlSecTransformCtxPtr transformCtx);
557 
558 /************************************************************************
559  *
560  * Transform Klass
561  *
562  ************************************************************************/
563 /**
564  * xmlSecTransformInitializeMethod:
565  * @transform:                  the pointer to transform object.
566  *
567  * The transform specific initialization method.
568  *
569  * Returns: 0 on success or a negative value otherwise.
570  */
571 typedef int             (*xmlSecTransformInitializeMethod)      (xmlSecTransformPtr transform);
572 
573 /**
574  * xmlSecTransformFinalizeMethod:
575  * @transform:                  the pointer to transform object.
576  *
577  * The transform specific destroy method.
578  */
579 typedef void            (*xmlSecTransformFinalizeMethod)        (xmlSecTransformPtr transform);
580 
581 /**
582  * xmlSecTransformGetDataTypeMethod:
583  * @transform:                  the pointer to transform object.
584  * @mode:                       the mode.
585  * @transformCtx:               the pointer to transform context object.
586  *
587  * The transform specific method to query information about transform
588  * data type in specified mode @mode.
589  *
590  * Returns: transform data type.
591  */
592 typedef xmlSecTransformDataType (*xmlSecTransformGetDataTypeMethod)(xmlSecTransformPtr transform,
593                                                                  xmlSecTransformMode mode,
594                                                                  xmlSecTransformCtxPtr transformCtx);
595 
596 /**
597  * xmlSecTransformNodeReadMethod:
598  * @transform:                  the pointer to transform object.
599  * @node:                       the pointer to <dsig:Transform/> node.
600  * @transformCtx:               the pointer to transform context object.
601  *
602  * The transform specific method to read the transform data from
603  * the @node.
604  *
605  * Returns: 0 on success or a negative value otherwise.
606  */
607 typedef int             (*xmlSecTransformNodeReadMethod)        (xmlSecTransformPtr transform,
608                                                                  xmlNodePtr node,
609                                                                  xmlSecTransformCtxPtr transformCtx);
610 
611 /**
612  * xmlSecTransformNodeWriteMethod:
613  * @transform:                  the pointer to transform object.
614  * @node:                       the pointer to <dsig:Transform/> node.
615  * @transformCtx:               the pointer to transform context object.
616  *
617  * The transform specific method to write transform information to an XML node @node.
618  *
619  * Returns: 0 on success or a negative value otherwise.
620  */
621 typedef int             (*xmlSecTransformNodeWriteMethod)       (xmlSecTransformPtr transform,
622                                                                  xmlNodePtr node,
623                                                                  xmlSecTransformCtxPtr transformCtx);
624 
625 /**
626  * xmlSecTransformSetKeyRequirementsMethod:
627  * @transform:                  the pointer to transform object.
628  * @keyReq:                     the pointer to key requirements structure.
629  *
630  * Transform specific method to set transform's key requirements.
631  *
632  * Returns: 0 on success or a negative value otherwise.
633  */
634 typedef int             (*xmlSecTransformSetKeyRequirementsMethod)(xmlSecTransformPtr transform,
635                                                                  xmlSecKeyReqPtr keyReq);
636 
637 /**
638  * xmlSecTransformSetKeyMethod:
639  * @transform:                  the pointer to transform object.
640  * @key:                        the pointer to key.
641  *
642  * The transform specific method to set the key for use.
643  *
644  * Returns: 0 on success or a negative value otherwise.
645  */
646 typedef int             (*xmlSecTransformSetKeyMethod)          (xmlSecTransformPtr transform,
647                                                                  xmlSecKeyPtr key);
648 
649 /**
650  * xmlSecTransformVerifyMethod:
651  * @transform:                  the pointer to transform object.
652  * @data:                       the input buffer.
653  * @dataSize:                   the size of input buffer @data.
654  * @transformCtx:               the pointer to transform context object.
655  *
656  * The transform specific method to verify transform processing results
657  * (used by digest and signature transforms). This method sets @status
658  * member of the #xmlSecTransform structure to either #xmlSecTransformStatusOk
659  * if verification succeeded or #xmlSecTransformStatusFail otherwise.
660  *
661  * Returns: 0 on success or a negative value otherwise.
662  */
663 typedef int             (*xmlSecTransformVerifyMethod)          (xmlSecTransformPtr transform,
664                                                                  const xmlSecByte* data,
665                                                                  xmlSecSize dataSize,
666                                                                  xmlSecTransformCtxPtr transformCtx);
667 /**
668  * xmlSecTransformPushBinMethod:
669  * @transform:                  the pointer to transform object.
670  * @data:                       the input binary data,
671  * @dataSize:                   the input data size.
672  * @final:                      the flag: if set to 1 then it's the last
673  *                              data chunk.
674  * @transformCtx:               the pointer to transform context object.
675  *
676  * The transform specific method to process data from @data and push
677  * result to the next transform in the chain.
678  *
679  * Returns: 0 on success or a negative value otherwise.
680  */
681 typedef int             (*xmlSecTransformPushBinMethod)         (xmlSecTransformPtr transform,
682                                                                  const xmlSecByte* data,
683                                                                  xmlSecSize dataSize,
684                                                                  int final,
685                                                                  xmlSecTransformCtxPtr transformCtx);
686 /**
687  * xmlSecTransformPopBinMethod:
688  * @transform:                  the pointer to transform object.
689  * @data:                       the buffer to store result data.
690  * @maxDataSize:                the size of the buffer @data.
691  * @dataSize:                   the pointer to returned data size.
692  * @transformCtx:               the pointer to transform context object.
693  *
694  * The transform specific method to pop data from previous transform
695  * in the chain and return result in the @data buffer. The size of returned
696  * data is placed in the @dataSize.
697  *
698  * Returns: 0 on success or a negative value otherwise.
699  */
700 typedef int             (*xmlSecTransformPopBinMethod)          (xmlSecTransformPtr transform,
701                                                                  xmlSecByte* data,
702                                                                  xmlSecSize maxDataSize,
703                                                                  xmlSecSize* dataSize,
704                                                                  xmlSecTransformCtxPtr transformCtx);
705 /**
706  * xmlSecTransformPushXmlMethod:
707  * @transform:                  the pointer to transform object.
708  * @nodes:                      the input nodes.
709  * @transformCtx:               the pointer to transform context object.
710  *
711  * The transform specific method to process @nodes and push result to the next
712  * transform in the chain.
713  *
714  * Returns: 0 on success or a negative value otherwise.
715  */
716 typedef int             (*xmlSecTransformPushXmlMethod)         (xmlSecTransformPtr transform,
717                                                                  xmlSecNodeSetPtr nodes,
718                                                                  xmlSecTransformCtxPtr transformCtx);
719 /**
720  * xmlSecTransformPopXmlMethod:
721  * @transform:                  the pointer to transform object.
722  * @nodes:                      the pointer to store popinter to result nodes.
723  * @transformCtx:               the pointer to transform context object.
724  *
725  * The transform specific method to pop data from previous transform in the chain,
726  * process the data and return result in @nodes.
727  *
728  * Returns: 0 on success or a negative value otherwise.
729  */
730 typedef int             (*xmlSecTransformPopXmlMethod)          (xmlSecTransformPtr transform,
731                                                                  xmlSecNodeSetPtr* nodes,
732                                                                  xmlSecTransformCtxPtr transformCtx);
733 /**
734  * xmlSecTransformExecuteMethod:
735  * @transform:                  the pointer to transform object.
736  * @last:                       the flag: if set to 1 then it's the last data chunk.
737  * @transformCtx:               the pointer to transform context object.
738  *
739  * Transform specific method to process a chunk of data.
740  *
741  * Returns: 0 on success or a negative value otherwise.
742  */
743 typedef int             (*xmlSecTransformExecuteMethod)         (xmlSecTransformPtr transform,
744                                                                  int last,
745                                                                  xmlSecTransformCtxPtr transformCtx);
746 
747 /**
748  * xmlSecTransformKlass:
749  * @klassSize:                  the transform klass structure size.
750  * @objSize:                    the transform object size.
751  * @name:                       the transform's name.
752  * @href:                       the transform's identification string (href).
753  * @usage:                      the allowed transforms usages.
754  * @initialize:                 the initialization method.
755  * @finalize:                   the finalization (destroy) function.
756  * @readNode:                   the XML node read method.
757  * @writeNode:                  the XML node write method.
758  * @setKeyReq:                  the set key requirements method.
759  * @setKey:                     the set key method.
760  * @verify:                     the verify method (for digest and signature transforms).
761  * @getDataType:                the input/output data type query method.
762  * @pushBin:                    the binary data "push thru chain" processing method.
763  * @popBin:                     the binary data "pop from chain" procesing method.
764  * @pushXml:                    the XML data "push thru chain" processing method.
765  * @popXml:                     the XML data "pop from chain" procesing method.
766  * @execute:                    the low level data processing method used  by default
767  *                              implementations of @pushBin, @popBin, @pushXml and @popXml.
768  * @reserved0:                  reserved for the future.
769  * @reserved1:                  reserved for the future.
770  *
771  * The transform klass description structure.
772  */
773 struct _xmlSecTransformKlass {
774     /* data */
775     xmlSecSize                          klassSize;
776     xmlSecSize                          objSize;
777     const xmlChar*                      name;
778     const xmlChar*                      href;
779     xmlSecTransformUsage                usage;
780 
781     /* methods */
782     xmlSecTransformInitializeMethod     initialize;
783     xmlSecTransformFinalizeMethod       finalize;
784 
785     xmlSecTransformNodeReadMethod       readNode;
786     xmlSecTransformNodeWriteMethod      writeNode;
787 
788     xmlSecTransformSetKeyRequirementsMethod     setKeyReq;
789     xmlSecTransformSetKeyMethod         setKey;
790     xmlSecTransformVerifyMethod         verify;
791     xmlSecTransformGetDataTypeMethod    getDataType;
792 
793     xmlSecTransformPushBinMethod        pushBin;
794     xmlSecTransformPopBinMethod         popBin;
795     xmlSecTransformPushXmlMethod        pushXml;
796     xmlSecTransformPopXmlMethod         popXml;
797 
798     /* low level method */
799     xmlSecTransformExecuteMethod        execute;
800 
801     /* reserved for future */
802     void*                               reserved0;
803     void*                               reserved1;
804 };
805 
806 /**
807  * xmlSecTransformKlassGetName:
808  * @klass:              the transform's klass.
809  *
810  * Macro. Returns transform klass name.
811  */
812 #define xmlSecTransformKlassGetName(klass) \
813         (((klass)) ? ((klass)->name) : NULL)
814 
815 /***********************************************************************
816  *
817  * Transform Ids list
818  *
819  **********************************************************************/
820 /**
821  * xmlSecTransformIdListId:
822  *
823  * Transform klasses list klass.
824  */
825 #define xmlSecTransformIdListId xmlSecTransformIdListGetKlass()
826 XMLSEC_EXPORT xmlSecPtrListId   xmlSecTransformIdListGetKlass   (void);
827 XMLSEC_EXPORT int               xmlSecTransformIdListFind       (xmlSecPtrListPtr list,
828                                                                  xmlSecTransformId transformId);
829 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformIdListFindByHref (xmlSecPtrListPtr list,
830                                                                  const xmlChar* href,
831                                                                  xmlSecTransformUsage usage);
832 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformIdListFindByName (xmlSecPtrListPtr list,
833                                                                  const xmlChar* name,
834                                                                  xmlSecTransformUsage usage);
835 XMLSEC_EXPORT void              xmlSecTransformIdListDebugDump  (xmlSecPtrListPtr list,
836                                                                  FILE* output);
837 XMLSEC_EXPORT void              xmlSecTransformIdListDebugXmlDump(xmlSecPtrListPtr list,
838                                                                  FILE* output);
839 
840 
841 /********************************************************************
842  *
843  * XML Sec Library Transform Ids
844  *
845  *******************************************************************/
846 /**
847  * xmlSecTransformIdUnknown:
848  *
849  * The "unknown" transform id (NULL).
850  */
851 #define xmlSecTransformIdUnknown                        ((xmlSecTransformId)NULL)
852 
853 /**
854  * xmlSecTransformBase64Id:
855  *
856  * The base64 encode transform klass.
857  */
858 #define xmlSecTransformBase64Id \
859         xmlSecTransformBase64GetKlass()
860 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformBase64GetKlass           (void);
861 XMLSEC_EXPORT void              xmlSecTransformBase64SetLineSize        (xmlSecTransformPtr transform,
862                                                                          xmlSecSize lineSize);
863 /**
864  * xmlSecTransformInclC14NId:
865  *
866  * The regular (inclusive) C14N without comments transform klass.
867  */
868 #define xmlSecTransformInclC14NId \
869         xmlSecTransformInclC14NGetKlass()
870 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformInclC14NGetKlass         (void);
871 
872 /**
873  * xmlSecTransformInclC14NWithCommentsId:
874  *
875  * The regular (inclusive) C14N with comments transform klass.
876  */
877 #define xmlSecTransformInclC14NWithCommentsId \
878         xmlSecTransformInclC14NWithCommentsGetKlass()
879 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformInclC14NWithCommentsGetKlass(void);
880 
881 /**
882  * xmlSecTransformInclC14N11Id:
883  *
884  * The regular (inclusive) C14N 1.1 without comments transform klass.
885  */
886 #define xmlSecTransformInclC14N11Id \
887         xmlSecTransformInclC14N11GetKlass()
888 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformInclC14N11GetKlass       (void);
889 
890 /**
891  * xmlSecTransformInclC14N11WithCommentsId:
892  *
893  * The regular (inclusive) C14N 1.1 with comments transform klass.
894  */
895 #define xmlSecTransformInclC14N11WithCommentsId \
896         xmlSecTransformInclC14N11WithCommentsGetKlass()
897 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformInclC14N11WithCommentsGetKlass(void);
898 
899 /**
900  * xmlSecTransformExclC14NId
901  *
902  * The exclusive C14N without comments transform klass.
903  */
904 #define xmlSecTransformExclC14NId \
905         xmlSecTransformExclC14NGetKlass()
906 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformExclC14NGetKlass         (void);
907 
908 /**
909  * xmlSecTransformExclC14NWithCommentsId:
910  *
911  * The exclusive C14N with comments transform klass.
912  */
913 #define xmlSecTransformExclC14NWithCommentsId \
914         xmlSecTransformExclC14NWithCommentsGetKlass()
915 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformExclC14NWithCommentsGetKlass(void);
916 
917 /**
918  * xmlSecTransformEnvelopedId:
919  *
920  * The "enveloped" transform klass.
921  */
922 #define xmlSecTransformEnvelopedId \
923         xmlSecTransformEnvelopedGetKlass()
924 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformEnvelopedGetKlass        (void);
925 
926 /**
927  * xmlSecTransformXPathId:
928  *
929  * The XPath transform klass.
930  */
931 #define xmlSecTransformXPathId \
932         xmlSecTransformXPathGetKlass()
933 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformXPathGetKlass            (void);
934 
935 /**
936  * xmlSecTransformXPath2Id:
937  *
938  * The XPath2 transform klass.
939  */
940 #define xmlSecTransformXPath2Id \
941         xmlSecTransformXPath2GetKlass()
942 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformXPath2GetKlass           (void);
943 
944 /**
945  * xmlSecTransformXPointerId:
946  *
947  * The XPointer transform klass.
948  */
949 #define xmlSecTransformXPointerId \
950         xmlSecTransformXPointerGetKlass()
951 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformXPointerGetKlass         (void);
952 XMLSEC_EXPORT int               xmlSecTransformXPointerSetExpr          (xmlSecTransformPtr transform,
953                                                                          const xmlChar* expr,
954                                                                          xmlSecNodeSetType nodeSetType,
955                                                                          xmlNodePtr hereNode);
956 /**
957  * xmlSecTransformRelationshipId:
958  *
959  * The Relationship transform klass.
960  */
961 #define xmlSecTransformRelationshipId \
962         xmlSecTransformRelationshipGetKlass()
963 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformRelationshipGetKlass     (void);
964 
965 #ifndef XMLSEC_NO_XSLT
966 
967 /**
968  * xmlSecTransformXsltId:
969  *
970  * The XSLT transform klass.
971  */
972 #define xmlSecTransformXsltId \
973         xmlSecTransformXsltGetKlass()
974 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformXsltGetKlass             (void);
975 XMLSEC_EXPORT void              xmlSecTransformXsltSetDefaultSecurityPrefs(xsltSecurityPrefsPtr sec);
976 #endif /* XMLSEC_NO_XSLT */
977 
978 /**
979  * xmlSecTransformRemoveXmlTagsC14NId:
980  *
981  * The "remove all xml tags" transform klass (used before base64 transforms).
982  */
983 #define xmlSecTransformRemoveXmlTagsC14NId \
984         xmlSecTransformRemoveXmlTagsC14NGetKlass()
985 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformRemoveXmlTagsC14NGetKlass(void);
986 
987 /**
988  * xmlSecTransformVisa3DHackId:
989  *
990  * Selects node subtree by given node id string. The only reason why we need this
991  * is Visa3D protocol. It doesn't follow XML/XPointer/XMLDSig specs and allows
992  * invalid XPointer expressions in the URI attribute. Since we couldn't evaluate
993  * such expressions thru XPath/XPointer engine, we need to have this hack here.
994  */
995 #define xmlSecTransformVisa3DHackId \
996         xmlSecTransformVisa3DHackGetKlass()
997 XMLSEC_EXPORT xmlSecTransformId xmlSecTransformVisa3DHackGetKlass       (void);
998 XMLSEC_EXPORT int               xmlSecTransformVisa3DHackSetID          (xmlSecTransformPtr transform,
999                                                                          const xmlChar* id);
1000 
1001 #ifdef __cplusplus
1002 }
1003 #endif /* __cplusplus */
1004 
1005 #endif /* __XMLSEC_TRANSFORMS_H__ */
1006 
1007