|
1 /** |
|
2 * XML Security Library (http://www.aleksey.com/xmlsec). |
|
3 * |
|
4 * "XML Encryption" implementation |
|
5 * http://www.w3.org/TR/xmlenc-core |
|
6 * |
|
7 * This is free software; see Copyright file in the source |
|
8 * distribution for preciese wording. |
|
9 * |
|
10 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> |
|
11 * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
12 */ |
|
13 #ifndef __XMLSEC_XMLENC_H__ |
|
14 #define __XMLSEC_XMLENC_H__ |
|
15 #include "xmlsec_config.h" |
|
16 #ifndef XMLSEC_NO_XMLENC |
|
17 |
|
18 #ifdef __cplusplus |
|
19 extern "C" { |
|
20 #endif /* __cplusplus */ |
|
21 #include <stdio.h> |
|
22 |
|
23 #include <libxml2_tree.h> |
|
24 #include <libxml2_parser.h> |
|
25 |
|
26 #include "xmlsec_xmlsec.h" |
|
27 #include "xmlsec_buffer.h" |
|
28 #include "xmlsec_keys.h" |
|
29 #include "xmlsec_keysmngr.h" |
|
30 #include "xmlsec_keyinfo.h" |
|
31 #include "xmlsec_transforms.h" |
|
32 |
|
33 /** |
|
34 * xmlEncCtxMode: |
|
35 * @xmlEncCtxModeEncryptedData: the <enc:EncryptedData/> element procesing. |
|
36 * @xmlEncCtxModeEncryptedKey: the <enc:EncryptedKey/> element processing. |
|
37 * |
|
38 * The #xmlSecEncCtx mode. |
|
39 */ |
|
40 typedef enum { |
|
41 xmlEncCtxModeEncryptedData = 0, |
|
42 xmlEncCtxModeEncryptedKey |
|
43 } xmlEncCtxMode; |
|
44 |
|
45 /** |
|
46 * xmlSecEncCtx: |
|
47 * @userData: the pointer to user data (xmlsec and xmlsec-crypto libraries |
|
48 * never touches this). |
|
49 * @flags: the XML Encryption processing flags. |
|
50 * @flags2: the XML Encryption processing flags. |
|
51 * @mode: the mode. |
|
52 * @keyInfoReadCtx: the reading key context. |
|
53 * @keyInfoWriteCtx: the writing key context (not used for signature verification). |
|
54 * @transformCtx: the transforms processing context. |
|
55 * @defEncMethodId: the default encryption method (used if |
|
56 * <enc:EncryptionMethod/> node is not present). |
|
57 * @encKey: the signature key; application may set #encKey |
|
58 * before calling encryption/decryption functions. |
|
59 * @operation: the operation: encrypt or decrypt. |
|
60 * @result: the pointer to signature (not valid for signature verificaction). |
|
61 * @resultBase64Encoded: the flag: if set then result in #result is base64 encoded. |
|
62 * @resultReplaced: the flag: if set then resulted <enc:EncryptedData/> |
|
63 * or <enc:EncryptedKey/> node is added to the document. |
|
64 * @encMethod: the pointer to encryption transform. |
|
65 * @id: the ID attribute of <enc:EncryptedData/> |
|
66 * or <enc:EncryptedKey/> node. |
|
67 * @type: the Type attribute of <enc:EncryptedData/> |
|
68 * or <enc:EncryptedKey/> node. |
|
69 * @mimeType: the MimeType attribute of <enc:EncryptedData/> |
|
70 * or <enc:EncryptedKey/> node. |
|
71 * @encoding: the Encoding attributeof <enc:EncryptedData/> |
|
72 * or <enc:EncryptedKey/> node. |
|
73 * @recipient: the Recipient attribute of <enc:EncryptedKey/> node.. |
|
74 * @carriedKeyName: the CarriedKeyName attribute of <enc:EncryptedKey/> node. |
|
75 * @encDataNode: the pointer to <enc:EncryptedData/> |
|
76 * or <enc:EncryptedKey/> node. |
|
77 * @encMethodNode: the pointer to <enc:EncryptionMethod/> node. |
|
78 * @keyInfoNode: the pointer to <enc:KeyInfo/> node. |
|
79 * @cipherValueNode: the pointer to <enc:CipherValue/> node. |
|
80 * @reserved0: reserved for the future. |
|
81 * @reserved1: reserved for the future. |
|
82 * |
|
83 * XML Encrypiton context. |
|
84 */ |
|
85 struct _xmlSecEncCtx { |
|
86 /* these data user can set before performing the operation */ |
|
87 void* userData; |
|
88 unsigned int flags; |
|
89 unsigned int flags2; |
|
90 xmlEncCtxMode mode; |
|
91 xmlSecKeyInfoCtx keyInfoReadCtx; |
|
92 xmlSecKeyInfoCtx keyInfoWriteCtx; |
|
93 xmlSecTransformCtx transformCtx; |
|
94 xmlSecTransformId defEncMethodId; |
|
95 |
|
96 /* these data are returned */ |
|
97 xmlSecKeyPtr encKey; |
|
98 xmlSecTransformOperation operation; |
|
99 xmlSecBufferPtr result; |
|
100 int resultBase64Encoded; |
|
101 int resultReplaced; |
|
102 xmlSecTransformPtr encMethod; |
|
103 |
|
104 /* attributes from EncryptedData or EncryptedKey */ |
|
105 xmlChar* id; |
|
106 xmlChar* type; |
|
107 xmlChar* mimeType; |
|
108 xmlChar* encoding; |
|
109 xmlChar* recipient; |
|
110 xmlChar* carriedKeyName; |
|
111 |
|
112 /* these are internal data, nobody should change that except us */ |
|
113 xmlNodePtr encDataNode; |
|
114 xmlNodePtr encMethodNode; |
|
115 xmlNodePtr keyInfoNode; |
|
116 xmlNodePtr cipherValueNode; |
|
117 |
|
118 /* reserved for future */ |
|
119 void* reserved0; |
|
120 void* reserved1; |
|
121 }; |
|
122 |
|
123 XMLSEC_EXPORT xmlSecEncCtxPtr xmlSecEncCtxCreate (xmlSecKeysMngrPtr keysMngr); |
|
124 XMLSEC_EXPORT void xmlSecEncCtxDestroy (xmlSecEncCtxPtr encCtx); |
|
125 XMLSEC_EXPORT int xmlSecEncCtxInitialize (xmlSecEncCtxPtr encCtx, |
|
126 xmlSecKeysMngrPtr keysMngr); |
|
127 XMLSEC_EXPORT void xmlSecEncCtxFinalize (xmlSecEncCtxPtr encCtx); |
|
128 XMLSEC_EXPORT int xmlSecEncCtxCopyUserPref (xmlSecEncCtxPtr dst, |
|
129 xmlSecEncCtxPtr src); |
|
130 XMLSEC_EXPORT void xmlSecEncCtxReset (xmlSecEncCtxPtr encCtx); |
|
131 XMLSEC_EXPORT int xmlSecEncCtxBinaryEncrypt (xmlSecEncCtxPtr encCtx, |
|
132 xmlNodePtr tmpl, |
|
133 const xmlSecByte* data, |
|
134 xmlSecSize dataSize); |
|
135 XMLSEC_EXPORT int xmlSecEncCtxXmlEncrypt (xmlSecEncCtxPtr encCtx, |
|
136 xmlNodePtr tmpl, |
|
137 xmlNodePtr node); |
|
138 XMLSEC_EXPORT int xmlSecEncCtxUriEncrypt (xmlSecEncCtxPtr encCtx, |
|
139 xmlNodePtr tmpl, |
|
140 const xmlChar *uri); |
|
141 XMLSEC_EXPORT int xmlSecEncCtxDecrypt (xmlSecEncCtxPtr encCtx, |
|
142 xmlNodePtr node); |
|
143 XMLSEC_EXPORT xmlSecBufferPtr xmlSecEncCtxDecryptToBuffer (xmlSecEncCtxPtr encCtx, |
|
144 xmlNodePtr node ); |
|
145 XMLSEC_EXPORT void xmlSecEncCtxDebugDump (xmlSecEncCtxPtr encCtx, |
|
146 FILE* output); |
|
147 XMLSEC_EXPORT void xmlSecEncCtxDebugXmlDump (xmlSecEncCtxPtr encCtx, |
|
148 FILE* output); |
|
149 |
|
150 #ifdef __cplusplus |
|
151 } |
|
152 #endif /* __cplusplus */ |
|
153 |
|
154 #endif /* XMLSEC_NO_XMLENC */ |
|
155 |
|
156 #endif /* __XMLSEC_XMLENC_H__ */ |
|
157 |