Eneboo - Documentación para desarrolladores
src/libdigidoc/DigiDocEnc.h
Ir a la documentación de este archivo.
00001 #ifndef __DIGIDOC_ENC_H__
00002 #define __DIGIDOC_ENC_H__
00003 //==================================================
00004 // FILE:        DigiDocEnc.h
00005 // PROJECT:     Digi Doc Encryption
00006 // DESCRIPTION: DigiDocEnc structures
00007 // AUTHOR:  Veiko Sinivee, S|E|B IT Partner Estonia
00008 //==================================================
00009 // Copyright (C) AS Sertifitseerimiskeskus
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // GNU Lesser General Public Licence is available at
00019 // http://www.gnu.org/copyleft/lesser.html
00020 //==========< HISTORY >=============================
00021 //      15.09.2004      Veiko Sinivee
00022 //                      Creation
00023 //==================================================
00024 
00025 #include <openssl/x509.h>
00026 #include <libdigidoc/DigiDocMem.h>
00027 #include <libdigidoc/DigiDocConfig.h>
00028 #include <libdigidoc/DigiDocDefs.h>
00029 
00030 #ifdef  __cplusplus
00031 extern "C" {
00032 #endif
00033 
00034 
00035 typedef struct DEncEncryptionProperty_st {
00036   char* szId;          // Id atribute value if present
00037   char* szTarget;      // Target atribute value if present
00038   char* szName;        // "name" atribute value if present - used in our implementation
00039   char* szContent;     // element content if used
00040   // TODO - other atributes ?
00041 } DEncEncryptionProperty;
00042 
00043 typedef struct DEncEncryptionProperties_st {
00044   char* szId;          // Id atribute value if present
00045   DEncEncryptionProperty** arrEncryptionProperties; // array of EncryptionProperty pointers
00046   int                      nEncryptionProperties;   // number of EncryptionProperty objects
00047 } DEncEncryptionProperties;
00048 
00049 
00050 typedef struct DEncEncrytedKey_st {
00051   char* szId;          // Id atribute value if present
00052   char* szRecipient;   // Recipient atribute value if present
00053   char* szEncryptionMethod; // EncryptionMethod element value
00054   char* szKeyName;     // KeyName element value if used
00055   char* szCarriedKeyName; // CarriedKeyName element value if used
00056   X509* pCert;         // receivers certificate - required in our implementation!
00057   DigiDocMemBuf mbufTransportKey; // encrypted transport key
00058 } DEncEncryptedKey;
00059 
00060 typedef struct DEncEncrytedData_st {
00061   char* szId;          // Id atribute value if present
00062   char* szType;        // Type atribute value if present
00063   char* szMimeType;    // MimeType atribute value if present
00064   char* szEncryptionMethod; // EncryptionMethod element value
00065   char* szXmlNs;       // XML namespace
00066   DEncEncryptedKey ** arrEncryptedKeys;
00067   int                  nEncryptedKeys;
00068   DigiDocMemBuf mbufEncryptedData;
00069   DEncEncryptionProperties encProperties;
00070 
00071   // private transient fields
00072   DigiDocMemBuf mbufTransportKey; // unencrypted transport key
00073   char initVector[16];
00074   // flags
00075   int nDataStatus;
00076   int nKeyStatus;
00077 } DEncEncryptedData;
00078 
00079 typedef struct DEncRecvInfo_st {
00080   char* szId;          // Id of recipient
00081   char* szRecipient;   // Recipient atribute value if present
00082   char* szKeyName;     // KeyName element value if used
00083   char* szCarriedKeyName; // CarriedKeyName element value if used
00084   X509* pCert;         // receivers certificate - required in our implementation!
00085 } DEncRecvInfo;
00086 
00087 typedef struct DEncRecvInfoList_st {
00088   int nItems;
00089   DEncRecvInfo** pItems;
00090 } DEncRecvInfoList;
00091 
00092 
00093 
00094 #define DENC_DATA_STATUS_UNINITIALIZED                      0
00095 #define DENC_DATA_STATUS_UNENCRYPTED_AND_NOT_COMPRESSED     1
00096 #define DENC_DATA_STATUS_UNENCRYPTED_AND_COMPRESSED         2
00097 #define DENC_DATA_STATUS_ENCRYPTED_AND_NOT_COMPRESSED       3
00098 #define DENC_DATA_STATUS_ENCRYPTED_AND_COMPRESSED           4
00099 
00100 #define DENC_KEY_STATUS_UNINITIALIZED    0
00101 #define DENC_KEY_STATUS_INITIALIZED      1
00102 #define DENC_KEY_STATUS_DISCARDED        2
00103 
00104 #define ENCPROP_FILENAME                 "Filename"
00105 #define ENCPROP_ORIG_SIZE                "OriginalSize"
00106 #define ENCPROP_ORIG_MIME                "OriginalMimeType"
00107 #define ENCPROP_ORIG_CONTENT             "orig_file"
00108 #define ENCPROP_LIB_VERSION              "LibraryVersion"
00109 #define ENCPROP_DOC_FORMAT               "DocumentFormat"
00110 
00111 #define DENC_FORMAT_ENCDOC_XML           "ENCDOC-XML"
00112 #define DENC_VERSION_1_0                 "1.0"
00113 
00114 #define DENC_COMPRESS_ALLWAYS            0
00115 #define DENC_COMPRESS_NEVER              1
00116 #define DENC_COMPRESS_BEST_EFFORT        2
00117 
00118 #define DENC_ENCRYPTED_KEY_LEN           128
00119 #define DENC_DECRYPTED_KEY_LEN           16
00120 
00121 #define ENCRYPT         1
00122 #define DECRYPT         0
00123 
00124 #define DENC_ENCDATA_TYPE_DDOC   "http://www.sk.ee/DigiDoc/v1.3.0/digidoc.xsd"
00125 
00126 #define DENC_ENCDATA_MIME_XML    "text/xml"
00127 #define DENC_ENCDATA_MIME_ZLIB   "http://www.isi.edu/in-noes/iana/assignments/media-types/application/zip"
00128 
00129 #define DENC_ENC_METHOD_AES128   "http://www.w3.org/2001/04/xmlenc#aes128-cbc"
00130 #define DENC_ENC_METHOD_RSA1_5   "http://www.w3.org/2001/04/xmlenc#rsa-1_5"
00131 #define DENC_ENC_METHOD_RSA1_5_BUGGY   "http://www.w3.org/2001/04/xmlenc#rsa-1-5"
00132 #define DENC_XMLNS_XMLENC        "http://www.w3.org/2001/04/xmlenc#"
00133 #define DENC_XMLNS_XMLENC_ELEMENT "http://www.w3.org/2001/04/xmlenc#Element"
00134 #define DENC_XMLNS_XMLENC_CONTENT "http://www.w3.org/2001/04/xmlenc#Content"
00135 #define DENC_XMLNS_XMLENC_ENCPROP "http://www.w3.org/2001/04/xmlenc#EncryptionProperties"
00136 #define DENC_XMLNS_XMLDSIG        "http://www.w3.org/2000/09/xmldsig#"
00137 
00138 
00139 //======================< DEncEncryptedData >==============================
00140 
00141   //--------------------------------------------------
00142   // "Constructor" of DEncEncryptedData object
00143   // pEncData - address of buffer for newly allocated object [REQUIRED]
00144   // szXmlNs - XML namespace uri [REQUIRED]
00145   // szEncMethod - encyrption method algorithm uri [REQUIRED]
00146   // szId - elements Id attribute [OPTIONAL]
00147   // szType - elements type atribute [OPTIONAL]
00148   // szMimeType - elements mime-type attribute [OPTIONAL]
00149   // returns error code or ERR_OK
00150   //--------------------------------------------------
00151   EXP_OPTION int dencEncryptedData_new(DEncEncryptedData** ppEncData, 
00152                                        const char* szXmlNs, const char* szEncMethod,
00153                                        const char* szId, const char* szType, 
00154                                        const char* szMimeType);
00155   
00156   //--------------------------------------------------
00157   // "Destructor" of DEncEncryptedData object
00158   // pEncData - address of object to be deleted [REQUIRED]
00159   // returns error code or ERR_OK
00160   //--------------------------------------------------
00161   EXP_OPTION int dencEncryptedData_free(DEncEncryptedData* pEncData);
00162 
00163 //======================< DEncEncryptedData - accessors >===================
00164 
00165   //--------------------------------------------------
00166   // Accessor for Id atribute of DEncEncryptedData object.
00167   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00168   // returns value of atribute or NULL.
00169   //--------------------------------------------------
00170   EXP_OPTION const char* dencEncryptedData_GetId(DEncEncryptedData* pEncData);
00171 
00172   //--------------------------------------------------
00173   // Accessor for Type atribute of DEncEncryptedData object.
00174   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00175   // returns value of atribute or NULL.
00176   //--------------------------------------------------
00177   EXP_OPTION const char* dencEncryptedData_GetType(DEncEncryptedData* pEncData);
00178 
00179   //--------------------------------------------------
00180   // Accessor for MimeType atribute of DEncEncryptedData object.
00181   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00182   // returns value of atribute or NULL.
00183   //--------------------------------------------------
00184   EXP_OPTION const char* dencEncryptedData_GetMimeType(DEncEncryptedData* pEncData);
00185 
00186   //--------------------------------------------------
00187   // Accessor for xmlns atribute of DEncEncryptedData object.
00188   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00189   // returns value of atribute or NULL.
00190   //--------------------------------------------------
00191   EXP_OPTION const char* dencEncryptedData_GetXmlNs(DEncEncryptedData* pEncData);
00192 
00193   //--------------------------------------------------
00194   // Accessor for EncryptionMethod subelement of DEncEncryptedData object.
00195   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00196   // returns value of atribute or NULL.
00197   //--------------------------------------------------
00198   EXP_OPTION const char* dencEncryptedData_GetEncryptionMethod(DEncEncryptedData* pEncData);
00199 
00200   //--------------------------------------------------
00201   // Accessor for Id atribute of EncryptionProperties subelement of DEncEncryptedData object.
00202   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00203   // returns value of atribute or NULL.
00204   //--------------------------------------------------
00205   EXP_OPTION const char* dencEncryptedData_GetEncryptionPropertiesId(DEncEncryptedData* pEncData);
00206 
00207   //--------------------------------------------------
00208   // Accessor for count of EncryptionProperties subelement of DEncEncryptedData object.
00209   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00210   // returns count or -1 for error. Then use error API to check errors
00211   //--------------------------------------------------
00212   EXP_OPTION int dencEncryptedData_GetEncryptionPropertiesCount(DEncEncryptedData* pEncData);
00213 
00214   //--------------------------------------------------
00215   // Accessor for EncryptionProperties subelement of DEncEncryptedData object.
00216   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00217   // nIdx - index of EncryptionProperty object [REQUIRED]
00218   // returns EncryptionProperty pointer or NULL for error
00219   //--------------------------------------------------
00220   EXP_OPTION DEncEncryptionProperty* dencEncryptedData_GetEncryptionProperty(DEncEncryptedData* pEncData, int nIdx);
00221 
00222   //--------------------------------------------------
00223   // Retrieves the last EncryptionProperty subelement of DEncEncryptedData object.
00224   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00225   // returns EncryptionProperty pointer or NULL for error
00226   //--------------------------------------------------
00227   EXP_OPTION DEncEncryptionProperty* dencEncryptedData_GetLastEncryptionProperty(DEncEncryptedData* pEncData);
00228 
00229   //--------------------------------------------------
00230   // Finds EncryptionProperty by Name atribute
00231   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00232   // name - name of searched property
00233   // returns EncryptionProperty pointer or NULL for error
00234   //--------------------------------------------------
00235   EXP_OPTION DEncEncryptionProperty* dencEncryptedData_FindEncryptionPropertyByName(DEncEncryptedData* pEncData, const char* name);
00236 
00237   //--------------------------------------------------
00238   // Accessor for count of EncryptedKey subelement of DEncEncryptedData object.
00239   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00240   // returns count or -1 for error. Then use error API to check errors
00241   //--------------------------------------------------
00242   EXP_OPTION int dencEncryptedData_GetEncryptedKeyCount(DEncEncryptedData* pEncData);
00243 
00244   //--------------------------------------------------
00245   // Accessor for EncryptedKey subelement of DEncEncryptedData object.
00246   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00247   // nIdx - index of EncryptedKey object [REQUIRED]
00248   // returns EncryptedKey pointer or NULL for error
00249   //--------------------------------------------------
00250   EXP_OPTION DEncEncryptedKey* dencEncryptedData_GetEncryptedKey(DEncEncryptedData* pEncData, int nIdx);
00251 
00252   //--------------------------------------------------
00253   // Searches an EncryptedKey by recipients name
00254   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00255   // recipient - recipient name used to search the key [REQUIRED]
00256   // returns EncryptedKey pointer or NULL for error
00257   //--------------------------------------------------
00258   EXP_OPTION DEncEncryptedKey* dencEncryptedData_FindEncryptedKeyByRecipient(DEncEncryptedData* pEncData, const char* recipient);
00259 
00260   //--------------------------------------------------
00261   // Searches an EncryptedKey by certs CN field
00262   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00263   // cn - cert CN used to search the key [REQUIRED]
00264   // returns EncryptedKey pointer or NULL for error
00265   //--------------------------------------------------
00266   EXP_OPTION DEncEncryptedKey* dencEncryptedData_FindEncryptedKeyByCN(DEncEncryptedData* pEncData, const char* cn);
00267 
00268   //--------------------------------------------------
00269   // Accessor for EncryptedKey subelement of DEncEncryptedData object.
00270   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00271   // returns EncryptedKey pointer or NULL for error
00272   //--------------------------------------------------
00273   EXP_OPTION DEncEncryptedKey* dencEncryptedData_GetLastEncryptedKey(DEncEncryptedData* pEncData);
00274 
00275   //--------------------------------------------------
00276   // Accessor for encrypted data.
00277   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00278   // ppBuf - address for encrypted data pointer [REQUIRED]
00279   // returns error code or ERR_OK
00280   //--------------------------------------------------
00281   EXP_OPTION int dencEncryptedData_GetEncryptedData(DEncEncryptedData* pEncData, DigiDocMemBuf** ppBuf);
00282 
00283   //--------------------------------------------------
00284   // Accessor for encrypted data status flag.
00285   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00286   // returns status or -1 for error. Then use error API to check errors
00287   //--------------------------------------------------
00288   EXP_OPTION int dencEncryptedData_GetEncryptedDataStatus(DEncEncryptedData* pEncData);
00289 
00290 
00291 //======================< DEncEncryptedData - mutators >===================
00292 
00293   //--------------------------------------------------
00294   // Mutatoror for Id atribute of DEncEncryptedData object.
00295   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00296   // value - new value for atribute [REQUIRED]
00297   // returns error code or ERR_OK
00298   //--------------------------------------------------
00299   EXP_OPTION int dencEncryptedData_SetId(DEncEncryptedData* pEncData, const char* value);
00300 
00301   //--------------------------------------------------
00302   // Mutatoror for Type atribute of DEncEncryptedData object.
00303   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00304   // value - new value for atribute [REQUIRED]
00305   // returns error code or ERR_OK
00306   //--------------------------------------------------
00307   EXP_OPTION int dencEncryptedData_SetType(DEncEncryptedData* pEncData, const char* value);
00308 
00309   //--------------------------------------------------
00310   // Mutatoror for MimeType atribute of DEncEncryptedData object.
00311   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00312   // value - new value for atribute [REQUIRED]
00313   // returns error code or ERR_OK
00314   //--------------------------------------------------
00315   EXP_OPTION int dencEncryptedData_SetMimeType(DEncEncryptedData* pEncData, const char* value);
00316 
00317   //--------------------------------------------------
00318   // Mutatoror for xmlns atribute of DEncEncryptedData object.
00319   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00320   // value - new value for atribute [REQUIRED]
00321   // returns error code or ERR_OK
00322   //--------------------------------------------------
00323   EXP_OPTION int dencEncryptedData_SetXmlNs(DEncEncryptedData* pEncData, const char* value);
00324 
00325   //--------------------------------------------------
00326   // Mutatoror for EncryptionMethod subelement of DEncEncryptedData object.
00327   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00328   // value - new value for atribute [REQUIRED]
00329   // returns error code or ERR_OK
00330   //--------------------------------------------------
00331   EXP_OPTION int dencEncryptedData_SetEncryptionMethod(DEncEncryptedData* pEncData, const char* value);
00332 
00333   //--------------------------------------------------
00334   // Adds unencrypted data to encrypted data element
00335   // waiting to be encrypted in next steps
00336   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00337   // data - new unencrypted data [REQUIRED]
00338   // len - length of data. Use -1 for null terminated strings [REQUIRED]
00339   // returns error code or ERR_OK
00340   //--------------------------------------------------
00341   EXP_OPTION int dencEncryptedData_AppendData(DEncEncryptedData* pEncData, const char* data, int len);
00342 
00343   //--------------------------------------------------
00344   // Mutatoror for Id atribute of EncryptionProperties subelement of DEncEncryptedData object.
00345   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00346   // value - new value for atribute [REQUIRED]
00347   // returns error code or ERR_OK
00348   //--------------------------------------------------
00349   EXP_OPTION int dencEncryptedData_SetEncryptionPropertiesId(DEncEncryptedData* pEncData, const char* value);
00350 
00351   //--------------------------------------------------
00352   // Deletes EncryptionProperties subelement of DEncEncryptedData object.
00353   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00354   // nIdx - index of EncryptionProperty object to be removed [REQUIRED]
00355   // returns error code or ERR_OK
00356   //--------------------------------------------------
00357   EXP_OPTION int dencEncryptedData_DeleteEncryptionProperty(DEncEncryptedData* pEncData, int nIdx);
00358 
00359   //--------------------------------------------------
00360   // Deletes EncryptedKey subelement of DEncEncryptedData object.
00361   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00362   // nIdx - index of EncryptedKey object to be removed [REQUIRED]
00363   // returns error code or ERR_OK
00364   //--------------------------------------------------
00365   EXP_OPTION int dencEncryptedData_DeleteEncryptedKey(DEncEncryptedData* pEncData, int nIdx);
00366 
00367 
00368 //======================< DEncEncryptionProperty >===================
00369 
00370   //--------------------------------------------------
00371   // "Constructor" for EncryptionProperty
00372   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00373   // pEncProperty - address of buffer for new property object [REQUIRED]
00374   // szId - Id atribute of EncryptionProperty [OPTIONAL]
00375   // szTarget - Target atribute of EncryptionProperty [OPTIONAL]
00376   // szName - name atribute of EncryptionProperty [OPTIONAL]
00377   // szContent - content of EncryptionProperty [OPTIONAL]
00378   // returns error code or ERR_OK
00379   //--------------------------------------------------
00380   EXP_OPTION int dencEncryptionProperty_new(DEncEncryptedData* pEncData, 
00381                                  DEncEncryptionProperty** pEncProperty,
00382                                  const char* szId, const char* szTarget,
00383                                  const char* szName, const char* szContent);
00384 
00385   //--------------------------------------------------
00386   // "Destructor" for EncryptionProperty
00387   // pEncProperty - address of buffer for new property object [REQUIRED]
00388   // returns error code or ERR_OK
00389   //--------------------------------------------------
00390   EXP_OPTION int dencEncryptionProperty_free(DEncEncryptionProperty* pEncProperty);
00391 
00392 //======================< DEncEncryptionProperty - accessors >===================
00393 
00394   //--------------------------------------------------
00395   // Accessor for Id atribute of EncryptionProperty object.
00396   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00397   // returns value of atribute or NULL.
00398   //--------------------------------------------------
00399   EXP_OPTION const char* dencEncryptionProperty_GetId(DEncEncryptionProperty* pEncProp);
00400 
00401   //--------------------------------------------------
00402   // Accessor for Target atribute of EncryptionProperty object.
00403   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00404   // returns value of atribute or NULL.
00405   //--------------------------------------------------
00406   EXP_OPTION const char* dencEncryptionProperty_GetTarget(DEncEncryptionProperty* pEncProp);
00407 
00408   //--------------------------------------------------
00409   // Accessor for Name atribute of EncryptionProperty object.
00410   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00411   // returns value of atribute or NULL.
00412   //--------------------------------------------------
00413   EXP_OPTION const char* dencEncryptionProperty_GetName(DEncEncryptionProperty* pEncProp);
00414 
00415   //--------------------------------------------------
00416   // Accessor for content of EncryptionProperty object.
00417   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00418   // returns value of atribute or NULL.
00419   //--------------------------------------------------
00420   EXP_OPTION const char* dencEncryptionProperty_GetContent(DEncEncryptionProperty* pEncProp);
00421 
00422 //======================< DEncEncryptionProperty - mutators >===================
00423 
00424   //--------------------------------------------------
00425   // Mutatoror for Id atribute of DEncEncryptionProperty object.
00426   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00427   // value - new value for atribute [REQUIRED]
00428   // returns error code or ERR_OK
00429   //--------------------------------------------------
00430   EXP_OPTION int dencEncryptionProperty_SetId(DEncEncryptionProperty* pEncProp, const char* value);
00431 
00432   //--------------------------------------------------
00433   // Mutatoror for Target atribute of DEncEncryptionProperty object.
00434   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00435   // value - new value for atribute [REQUIRED]
00436   // returns error code or ERR_OK
00437   //--------------------------------------------------
00438   EXP_OPTION int dencEncryptionProperty_SetTarget(DEncEncryptionProperty* pEncProp, const char* value);
00439 
00440   //--------------------------------------------------
00441   // Mutatoror for Name atribute of DEncEncryptionProperty object.
00442   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00443   // value - new value for atribute [REQUIRED]
00444   // returns error code or ERR_OK
00445   //--------------------------------------------------
00446   EXP_OPTION int dencEncryptionProperty_SetName(DEncEncryptionProperty* pEncProp, const char* value);
00447 
00448   //--------------------------------------------------
00449   // Mutatoror for content of DEncEncryptionProperty object.
00450   // pEncProp - pointer to DEncEncryptionProperty object [REQUIRED]
00451   // value - new value for atribute [REQUIRED]
00452   // returns error code or ERR_OK
00453   //--------------------------------------------------
00454   EXP_OPTION int dencEncryptionProperty_SetContent(DEncEncryptionProperty* pEncProp, const char* value);
00455 
00456 
00457 //======================< DEncEncryptedKey >===================
00458 
00459   //--------------------------------------------------
00460   // "Constructor" for EncryptedKey
00461   // Encrypts the transport key for a receiver
00462   // and stores encrypted key in memory
00463   // Call this function repeatedly for all receivers,
00464   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00465   // pEncKey - address of buffer for new encrypted key object [REQUIRED]
00466   // pCert - recevers certificate [REQUIRED]
00467   // szEncMethod - encryption method [REQUIRED]
00468   // szId - Id atribute of EncryptedKey [OPTIONAL]
00469   // szRecipient - Recipient atribute of EncryptedKey [OPTIONAL]
00470   // szKeyName - KeyName subelement of EncryptedKey [OPTIONAL]
00471   // szCarriedKeyName - CarriedKeyName subelement of EncryptedKey [OPTIONAL]
00472   // returns error code or ERR_OK
00473   //--------------------------------------------------
00474   EXP_OPTION int dencEncryptedKey_new(DEncEncryptedData* pEncData, 
00475                                       DEncEncryptedKey** pEncKey, X509* pCert,
00476                                       const char* szEncMethod, const char* szId,
00477                                       const char* szRecipient, const char* szKeyName,
00478                                       const char* szCarriedKeyName);
00479 
00480   //--------------------------------------------------
00481   // "Destructor" for EncryptedKey
00482   // pEncKey - address of buffer for new encrypted key object [REQUIRED]
00483   // returns error code or ERR_OK
00484   //--------------------------------------------------
00485   EXP_OPTION int dencEncryptedKey_free(DEncEncryptedKey* pEncKey);
00486 
00487 //======================< DEncEncryptedKey - acessors >===================
00488 
00489   //--------------------------------------------------
00490   // Accessor for Id atribute of DEncEncryptedKey object.
00491   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00492   // returns value of atribute or NULL.
00493   //--------------------------------------------------
00494   EXP_OPTION const char* dencEncryptedKey_GetId(DEncEncryptedKey* pEncKey);
00495 
00496   //--------------------------------------------------
00497   // Accessor for Recipient atribute of DEncEncryptedKey object.
00498   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00499   // returns value of atribute or NULL.
00500   //--------------------------------------------------
00501   EXP_OPTION const char* dencEncryptedKey_GetRecipient(DEncEncryptedKey* pEncKey);
00502 
00503   //--------------------------------------------------
00504   // Accessor for EncryptionMethod subelement of DEncEncryptedKey object.
00505   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00506   // returns value of atribute or NULL.
00507   //--------------------------------------------------
00508   EXP_OPTION const char* dencEncryptedKey_GetEncryptionMethod(DEncEncryptedKey* pEncKey);
00509 
00510   //--------------------------------------------------
00511   // Accessor for KeyName subelement of DEncEncryptedKey object.
00512   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00513   // returns value of atribute or NULL.
00514   //--------------------------------------------------
00515   EXP_OPTION const char* dencEncryptedKey_GetKeyName(DEncEncryptedKey* pEncKey);
00516 
00517   //--------------------------------------------------
00518   // Accessor for CarriedKeyName subelement of DEncEncryptedKey object.
00519   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00520   // returns value of atribute or NULL.
00521   //--------------------------------------------------
00522   EXP_OPTION const char* dencEncryptedKey_GetCarriedKeyName(DEncEncryptedKey* pEncKey);
00523 
00524   //--------------------------------------------------
00525   // Accessor for certificate of DEncEncryptedKey object.
00526   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00527   // returns value of atribute or NULL.
00528   //--------------------------------------------------
00529   EXP_OPTION X509* dencEncryptedKey_GetCertificate(DEncEncryptedKey* pEncKey);
00530 
00531 //======================< DEncEncryptedKey - mutators >===================
00532 
00533   //--------------------------------------------------
00534   // Mutatoror for Id atribute of DEncEncryptedKey object.
00535   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00536   // value - new value for atribute [REQUIRED]
00537   // returns error code or ERR_OK
00538   //--------------------------------------------------
00539   EXP_OPTION int dencEncryptedKey_SetId(DEncEncryptedKey* pEncKey, const char* value);
00540 
00541   //--------------------------------------------------
00542   // Mutatoror for Recipient atribute of DEncEncryptedKey object.
00543   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00544   // value - new value for atribute [REQUIRED]
00545   // returns error code or ERR_OK
00546   //--------------------------------------------------
00547   EXP_OPTION int dencEncryptedKey_SetRecipient(DEncEncryptedKey* pEncKey, const char* value);
00548 
00549   //--------------------------------------------------
00550   // Mutatoror for EncryptionMethod subelement of DEncEncryptedKey object.
00551   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00552   // value - new value for atribute [REQUIRED]
00553   // returns error code or ERR_OK
00554   //--------------------------------------------------
00555   EXP_OPTION int dencEncryptedKey_SetEncryptionMethod(DEncEncryptedKey* pEncKey, const char* value);
00556 
00557   //--------------------------------------------------
00558   // Mutatoror for KeyName subelement of DEncEncryptedKey object.
00559   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00560   // value - new value for atribute [REQUIRED]
00561   // returns error code or ERR_OK
00562   //--------------------------------------------------
00563   EXP_OPTION int dencEncryptedKey_SetKeyName(DEncEncryptedKey* pEncKey, const char* value);
00564 
00565   //--------------------------------------------------
00566   // Mutatoror for CarriedKeyName subelement of DEncEncryptedKey object.
00567   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00568   // value - new value for atribute [REQUIRED]
00569   // returns error code or ERR_OK
00570   //--------------------------------------------------
00571   EXP_OPTION int dencEncryptedKey_SetCarriedKeyName(DEncEncryptedKey* pEncKey, const char* value);
00572 
00573   //--------------------------------------------------
00574   // Mutatoror for certificate of DEncEncryptedKey object.
00575   // pEncKey - pointer to DEncEncryptedKey object [REQUIRED]
00576   // value - new value for atribute [REQUIRED]
00577   // returns error code or ERR_OK
00578   //--------------------------------------------------
00579   EXP_OPTION int dencEncryptedKey_SetCertificate(DEncEncryptedKey* pEncKey, X509* value);
00580 
00581 //==========< general crypto fucntions >============
00582 
00583   //--------------------------------------------------
00584   // Locates the correct EncryptedKey object by reading
00585   // users certificate from smartcard and searching the
00586   // right EncryptedKey object
00587   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00588   // ppEncKey - address of a buffer for EncryptedKey pointer [REQUIRED]
00589   // returns error code or ERR_OK
00590   //--------------------------------------------------
00591   EXP_OPTION int dencEncryptedData_findEncryptedKeyByPKCS11(DEncEncryptedData* pEncData, DEncEncryptedKey** ppEncKey);
00592 
00593   //--------------------------------------------------
00594   // Encrypts data with the generated key
00595   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00596   // nCompressOption - flag: DENC_COMPRESS_ALLWAYS, 
00597   //    DENC_COMPRESS_NEVER or DENC_COMPRESS_BEST_EFFORT
00598   // returns error code or ERR_OK
00599   //--------------------------------------------------
00600   EXP_OPTION int dencEncryptedData_encryptData(DEncEncryptedData* pEncData, int nCompressOption);
00601 
00602   //--------------------------------------------------
00603   // Decrypts data transport key with ID card and
00604   // then decrypts the data with the transport key.
00605   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00606   // tKey - decrypted transport key [REQUIRED]
00607   // keyLen - length of trasnport key [REQUIRED]
00608   // returns error code or ERR_OK
00609   //--------------------------------------------------
00610   EXP_OPTION int dencEncryptedData_decrypt_withKey(DEncEncryptedData* pEncData, 
00611                                                    const char* tKey, int keyLen);
00612 
00613   //--------------------------------------------------
00614   // Decrypts data with the generated key
00615   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00616   // returns error code or ERR_OK
00617   //--------------------------------------------------
00618   EXP_OPTION int dencEncryptedData_decryptData(DEncEncryptedData* pEncData);
00619 
00620   //--------------------------------------------------
00621   // Decrypts data transport key with ID card and
00622   // then decrypts the data with the transport key.
00623   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00624   // pEncKey - transport key to decrypt [REQUIRED]
00625   // pin - pin code for smart card [REQUIRED]
00626   // returns error code or ERR_OK
00627   //--------------------------------------------------
00628   EXP_OPTION int dencEncryptedData_decrypt(DEncEncryptedData* pEncData, 
00629                                            DEncEncryptedKey* pEncKey, 
00630                                            const char* pin);
00631 
00632   //--------------------------------------------------
00633   // Compresses data with ZLIB. Cannot compress encrypted data!!!
00634   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00635   // nCompressOption - flag: DENC_COMPRESS_ALLWAYS, 
00636   //    DENC_COMPRESS_NEVER or DENC_COMPRESS_BEST_EFFORT
00637   // returns error code or ERR_OK
00638   //--------------------------------------------------
00639   EXP_OPTION int dencEncryptedData_compressData(DEncEncryptedData* pEncData, int nCompressOption);
00640 
00641   //--------------------------------------------------
00642   // Decompresses data with ZLIB. 
00643   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00644   // nCompressOption - flag: DENC_COMPRESS_ALLWAYS, 
00645   //    DENC_COMPRESS_NEVER or DENC_COMPRESS_BEST_EFFORT
00646   // returns error code or ERR_OK
00647   //--------------------------------------------------
00648   EXP_OPTION int dencEncryptedData_decompressData(DEncEncryptedData* pEncData);
00649 
00650 
00651 //====================< RecipientInfo functions >==========================
00652 
00653   //--------------------------------------------------
00654   // "Constructor" of DEncRecvInfo object
00655   // ppRecvInfo - address of buffer for newly allocated object [REQUIRED]
00656   // szId - recipients id [REQUIRED]
00657   // szRecipient - recipient atribute [OPTIONAL]
00658   // szKeyName - KeyName element [OPTIONAL]
00659   // szCarriedKeyName - CarriedKeyName element [OPTIONAL]
00660   // pCert - certificate [REQUIRED]
00661   // returns error code or ERR_OK
00662   //--------------------------------------------------
00663   EXP_OPTION int dencRecvInfo_new(DEncRecvInfo** ppRecvInfo, 
00664                                   const char* szId, const char* szRecipient, 
00665                                   const char* szKeyName, const char* szCarriedKeyName,
00666                                   const X509* pCert);
00667 
00668   //--------------------------------------------------
00669   // "Destructor" of DEncRecvInfo object
00670   // pRecvInfo - address of buffer for newly allocated object [REQUIRED]
00671   // returns error code or ERR_OK
00672   //--------------------------------------------------
00673   EXP_OPTION int dencRecvInfo_free(DEncRecvInfo* pRecvInfo);
00674 
00675   //--------------------------------------------------
00676   // Stores DEncRecvInfo object to configuration store
00677   // pRecvInfo - address of buffer for newly allocated object [REQUIRED]
00678   // returns error code or ERR_OK
00679   //--------------------------------------------------
00680   EXP_OPTION int dencRecvInfo_store(DEncRecvInfo* pRecvInfo);
00681 
00682   //--------------------------------------------------
00683   // Stores DEncRecvInfo object to configuration store
00684   // pConfStore - store to search in [OPTIONAL]. Use NULL for default
00685   // pRecvInfo - address of buffer for newly allocated object [REQUIRED]
00686   // szId - id of the object [REQUIRED]
00687   // returns error code or ERR_OK
00688   //--------------------------------------------------
00689   EXP_OPTION int dencRecvInfo_findById(ConfigurationStore *pConfStore, 
00690                                        DEncRecvInfo** ppRecvInfo, const char* szId);
00691 
00692   //--------------------------------------------------
00693   // Deletes DEncRecvInfo object from configuration store
00694   // pRecvInfo - address of RecvInfo [REQUIRED]
00695   // returns error code or ERR_OK
00696   //--------------------------------------------------
00697   EXP_OPTION int dencRecvInfo_delete(DEncRecvInfo* pRecvInfo);
00698 
00699   //--------------------------------------------------
00700   // Returns all DEncRecvInfo objects
00701   // pRecvInfoList - address of the list receiving the items [REQUIRED]
00702   // returns error code or ERR_OK
00703   //--------------------------------------------------
00704   EXP_OPTION int dencRecvInfo_findAll(DEncRecvInfoList* pRecvInfoList);
00705 
00706 
00707 //====================< RecipientInfoList functions >==========================
00708 
00709   //--------------------------------------------------
00710   // Adds a DEncRecvInfo object to the list
00711   // pRecvInfoList - address of the list receiving the item [REQUIRED]
00712   // pRecvInfo - new object to be added
00713   // returns error code or ERR_OK
00714   //--------------------------------------------------
00715   EXP_OPTION int dencRecvInfoList_add(DEncRecvInfoList* pRecvInfoList, DEncRecvInfo *pRecvInfo);
00716 
00717   //--------------------------------------------------
00718   // Frees the contents of a DEncRecvInfoList object
00719   // pRecvInfoList - address of the list [REQUIRED]
00720   // returns error code or ERR_OK
00721   //--------------------------------------------------
00722   EXP_OPTION int dencRecvInfoList_free(DEncRecvInfoList* pRecvInfoList);
00723 
00724   //--------------------------------------------------
00725   // Removes the given DEncRecvInfo object from the list
00726   // pRecvInfoList - address of the list [REQUIRED]
00727   // szId - id of the obect to be removed [REQUIRED]
00728   // returns error code or ERR_OK
00729   //--------------------------------------------------
00730   EXP_OPTION int dencRecvInfoList_delete(DEncRecvInfoList* pRecvInfoList, const char* szId);
00731 
00732 //====================< big file functions >==========================
00733 
00734   //--------------------------------------------------
00735   // Encrypts a file and writes it to output file
00736   // The caller must have initialized the transport keys
00737   // but not the data.
00738   // pEncData - pointer to DEncEncryptedData object [REQUIRED]
00739   // szInputFileName - input data name [REQUIRED]
00740   // szOutputFileName - output file name [REQUIRED]
00741   // szMimeType - input data mime type [OPTIONAL]
00742   // returns error code or ERR_OK
00743   //--------------------------------------------------
00744   EXP_OPTION int dencEncryptFile(DEncEncryptedData* pEncData, 
00745                                  const char* szInputFileName, const char* szOutputFileName,
00746                                  const char* szMimeType);
00747 
00748 //====================< original content functions >===================
00749 
00750   //--------------------------------------------------
00751   // Returns the count of "orig_file" properties
00752   // pEncData - EncryptedData object [REQUIRED]
00753   // returns count or -1 for error.
00754   //--------------------------------------------------
00755   EXP_OPTION int dencOrigContent_count(DEncEncryptedData* pEncData);
00756 
00757   //--------------------------------------------------
00758   // Creates a new property of type "orig_file"
00759   // pEncData - EncryptedData object [REQUIRED]
00760   // szOrigContentId - Id atribute for new Property object [OPTIONAL]
00761   // szName - original file name [REQUIRED]
00762   // szSize - size as string or irginal file [REQUIRED]
00763   // szMime - mime type or original file [REQUIRED]
00764   // szDfId - Id atribute of original file [REQUIRED]
00765   // returns error code or ERR_OK
00766   //--------------------------------------------------
00767   EXP_OPTION int dencOrigContent_add(DEncEncryptedData* pEncData, const char* szOrigContentId,
00768            const char* szName, const char* szSize, const char* szMime, const char* szDfId);
00769 
00770   //--------------------------------------------------
00771   // Returns the info from "orig_file" properties
00772   // pEncData - EncryptedData object [REQUIRED]
00773   // szOrigContentId - Id atribute for new Property object [OPTIONAL]
00774   // szName - buffer for original file name [REQUIRED]
00775   // szSize - buffer for size as string or irginal file [REQUIRED]
00776   // szMime - buffer for mime type or original file [REQUIRED]
00777   // szDfId - buffer for Id atribute of original file [REQUIRED]
00778   // returns error code or ERR_OK
00779   //--------------------------------------------------
00780   EXP_OPTION int dencOrigContent_findByIndex(DEncEncryptedData* pEncData, int origContIdx,
00781                    char* szName, char* szSize, char* szMime, char* szDfId);
00782 
00783   //--------------------------------------------------
00784   // Checks if there is a digidoc document in this
00785   // encrypted document.
00786   // pEncData - EncryptedData object [REQUIRED]
00787   // returns 1 if digidoc document is inside
00788   //--------------------------------------------------
00789   EXP_OPTION int dencOrigContent_isDigiDocInside(DEncEncryptedData* pEncData);
00790 
00791   //--------------------------------------------------
00792   // Registers digidoc document as encrypted datatype
00793   // and stores it's data file info.
00794   // pEncData - EncryptedData object [REQUIRED]
00795   // pSigDoc - SignedDoc object [REQUIRED]
00796   // returns 1 if digidoc document is inside
00797   //--------------------------------------------------
00798   EXP_OPTION int dencOrigContent_registerDigiDoc(DEncEncryptedData* pEncData, SignedDoc* pSigDoc);
00799 
00800 //====================< other meta-info functions >===================
00801 
00802   //--------------------------------------------------
00803   // Sets the library name and version property
00804   // pEncData - EncryptedData object [REQUIRED]
00805   // returns count or -1 for error.
00806   //--------------------------------------------------
00807   EXP_OPTION int dencMetaInfo_SetLibVersion(DEncEncryptedData* pEncData);
00808 
00809   //--------------------------------------------------
00810   // Sets the format name and version property
00811   // pEncData - EncryptedData object [REQUIRED]
00812   // returns count or -1 for error.
00813   //--------------------------------------------------
00814   EXP_OPTION int dencMetaInfo_SetFormatVersion(DEncEncryptedData* pEncData);
00815 
00816   //--------------------------------------------------
00817   // Returns the library name and version meta-info of this document
00818   // pEncData - EncryptedData object [REQUIRED]
00819   // returns count or -1 for error.
00820   //--------------------------------------------------
00821   EXP_OPTION int dencMetaInfo_GetLibVersion(DEncEncryptedData* pEncData, char* szLibrary, char* szVersion);
00822 
00823   //--------------------------------------------------
00824   // Returns the format name and version meta-info of this document
00825   // pEncData - EncryptedData object [REQUIRED]
00826   // returns count or -1 for error.
00827   //--------------------------------------------------
00828   EXP_OPTION int dencMetaInfo_GetFormatVersion(DEncEncryptedData* pEncData, char* szFormat, char* szVersion);
00829 
00830   //--------------------------------------------------
00831   // Deletes the meta-info properties
00832   // pEncData - EncryptedData object [REQUIRED]
00833   // returns error code or ERR_OK
00834   //--------------------------------------------------
00835   EXP_OPTION int dencMetaInfo_deleteVersionInfo(DEncEncryptedData* pEncData);
00836 
00837 
00838 #ifdef  __cplusplus
00839 }
00840 #endif
00841 
00842 #endif // __DIGIDOC_ENC_H__
00843 
00844 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'