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-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. 11 */ 12 #ifndef __XMLSEC_XMLENC_H__ 13 #define __XMLSEC_XMLENC_H__ 14 15 #ifndef XMLSEC_NO_XMLENC 16 17 #include <stdio.h> 18 19 #include <libxml/tree.h> 20 #include <libxml/parser.h> 21 22 #include <xmlsec/xmlsec.h> 23 #include <xmlsec/buffer.h> 24 #include <xmlsec/keys.h> 25 #include <xmlsec/keysmngr.h> 26 #include <xmlsec/keyinfo.h> 27 #include <xmlsec/transforms.h> 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif /* __cplusplus */ 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 /** 47 * XMLSEC_ENC_RETURN_REPLACED_NODE: 48 * 49 * If this flag is set, then the replaced node will be returned in the replacedNodeList 50 */ 51 #define XMLSEC_ENC_RETURN_REPLACED_NODE 0x00000001 52 53 /** 54 * xmlSecEncCtx: 55 * @userData: the pointer to user data (xmlsec and xmlsec-crypto libraries 56 * never touches this). 57 * @flags: the XML Encryption processing flags. 58 * @flags2: the XML Encryption processing flags. 59 * @mode: the mode. 60 * @keyInfoReadCtx: the reading key context. 61 * @keyInfoWriteCtx: the writing key context (not used for signature verification). 62 * @transformCtx: the transforms processing context. 63 * @defEncMethodId: the default encryption method (used if 64 * <enc:EncryptionMethod/> node is not present). 65 * @encKey: the signature key; application may set #encKey 66 * before calling encryption/decryption functions. 67 * @operation: the operation: encrypt or decrypt. 68 * @result: the pointer to signature (not valid for signature verification). 69 * @resultBase64Encoded: the flag: if set then result in #result is base64 encoded. 70 * @resultReplaced: the flag: if set then resulted <enc:EncryptedData/> 71 * or <enc:EncryptedKey/> node is added to the document. 72 * @encMethod: the pointer to encryption transform. 73 * @replacedNodeList: the first node of the list of replaced nodes depending on the nodeReplacementMode 74 * @id: the ID attribute of <enc:EncryptedData/> 75 * or <enc:EncryptedKey/> node. 76 * @type: the Type attribute of <enc:EncryptedData/> 77 * or <enc:EncryptedKey/> node. 78 * @mimeType: the MimeType attribute of <enc:EncryptedData/> 79 * or <enc:EncryptedKey/> node. 80 * @encoding: the Encoding attributeof <enc:EncryptedData/> 81 * or <enc:EncryptedKey/> node. 82 * @recipient: the Recipient attribute of <enc:EncryptedKey/> node.. 83 * @carriedKeyName: the CarriedKeyName attribute of <enc:EncryptedKey/> node. 84 * @encDataNode: the pointer to <enc:EncryptedData/> 85 * or <enc:EncryptedKey/> node. 86 * @encMethodNode: the pointer to <enc:EncryptionMethod/> node. 87 * @keyInfoNode: the pointer to <enc:KeyInfo/> node. 88 * @cipherValueNode: the pointer to <enc:CipherValue/> node. 89 * @reserved1: reserved for the future. 90 * 91 * XML Encryption context. 92 */ 93 struct _xmlSecEncCtx { 94 /* these data user can set before performing the operation */ 95 void* userData; 96 unsigned int flags; 97 unsigned int flags2; 98 xmlEncCtxMode mode; 99 xmlSecKeyInfoCtx keyInfoReadCtx; 100 xmlSecKeyInfoCtx keyInfoWriteCtx; 101 xmlSecTransformCtx transformCtx; 102 xmlSecTransformId defEncMethodId; 103 104 /* these data are returned */ 105 xmlSecKeyPtr encKey; 106 xmlSecTransformOperation operation; 107 xmlSecBufferPtr result; 108 int resultBase64Encoded; 109 int resultReplaced; 110 xmlSecTransformPtr encMethod; 111 112 /* attributes from EncryptedData or EncryptedKey */ 113 xmlChar* id; 114 xmlChar* type; 115 xmlChar* mimeType; 116 xmlChar* encoding; 117 xmlChar* recipient; 118 xmlChar* carriedKeyName; 119 120 /* these are internal data, nobody should change that except us */ 121 xmlNodePtr encDataNode; 122 xmlNodePtr encMethodNode; 123 xmlNodePtr keyInfoNode; 124 xmlNodePtr cipherValueNode; 125 126 xmlNodePtr replacedNodeList; /* the pointer to the replaced node */ 127 void* reserved1; /* reserved for future */ 128 }; 129 130 XMLSEC_EXPORT xmlSecEncCtxPtr xmlSecEncCtxCreate (xmlSecKeysMngrPtr keysMngr); 131 XMLSEC_EXPORT void xmlSecEncCtxDestroy (xmlSecEncCtxPtr encCtx); 132 XMLSEC_EXPORT int xmlSecEncCtxInitialize (xmlSecEncCtxPtr encCtx, 133 xmlSecKeysMngrPtr keysMngr); 134 XMLSEC_EXPORT void xmlSecEncCtxFinalize (xmlSecEncCtxPtr encCtx); 135 XMLSEC_EXPORT int xmlSecEncCtxCopyUserPref (xmlSecEncCtxPtr dst, 136 xmlSecEncCtxPtr src); 137 XMLSEC_EXPORT void xmlSecEncCtxReset (xmlSecEncCtxPtr encCtx); 138 XMLSEC_EXPORT int xmlSecEncCtxBinaryEncrypt (xmlSecEncCtxPtr encCtx, 139 xmlNodePtr tmpl, 140 const xmlSecByte* data, 141 xmlSecSize dataSize); 142 XMLSEC_EXPORT int xmlSecEncCtxXmlEncrypt (xmlSecEncCtxPtr encCtx, 143 xmlNodePtr tmpl, 144 xmlNodePtr node); 145 XMLSEC_EXPORT int xmlSecEncCtxUriEncrypt (xmlSecEncCtxPtr encCtx, 146 xmlNodePtr tmpl, 147 const xmlChar *uri); 148 XMLSEC_EXPORT int xmlSecEncCtxDecrypt (xmlSecEncCtxPtr encCtx, 149 xmlNodePtr node); 150 XMLSEC_EXPORT xmlSecBufferPtr xmlSecEncCtxDecryptToBuffer (xmlSecEncCtxPtr encCtx, 151 xmlNodePtr node ); 152 XMLSEC_EXPORT void xmlSecEncCtxDebugDump (xmlSecEncCtxPtr encCtx, 153 FILE* output); 154 XMLSEC_EXPORT void xmlSecEncCtxDebugXmlDump (xmlSecEncCtxPtr encCtx, 155 FILE* output); 156 157 #ifdef __cplusplus 158 } 159 #endif /* __cplusplus */ 160 161 #endif /* XMLSEC_NO_XMLENC */ 162 163 #endif /* __XMLSEC_XMLENC_H__ */ 164 165