Eneboo - Documentación para desarrolladores
src/libdigidoc/DigiDocLib.h
Ir a la documentación de este archivo.
00001 #ifndef __DIGI_DOC_LIB_H__
00002 #define __DIGI_DOC_LIB_H__
00003 //==================================================
00004 // FILE:        DigiDocLib.h
00005 // PROJECT: Digi Doc
00006 // DESCRIPTION: Digi Doc functions for creating
00007 //      and reading signed documents. 
00008 // AUTHOR:  Veiko Sinivee, S|E|B IT Partner Estonia
00009 //==================================================
00010 // Copyright (C) AS Sertifitseerimiskeskus
00011 // This library is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU Lesser General Public
00013 // License as published by the Free Software Foundation; either
00014 // version 2.1 of the License, or (at your option) any later version.
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.ode
00019 // GNU Lesser General Public Licence is available at
00020 // http://www.gnu.org/copyleft/lesser.html
00021 //==========< HISTORY >=============================
00022 //      10.02.2004      Integrated
00023 //      02.01.2004      Veiko Sinivee
00024 //                      Added support for format 1.3
00025 //      29.10.2003      Aare Amenberg
00026 //                      Added some function headers 
00027 //                      (needed for compiling COM)
00028 // 1.0  09.04.2002      Veiko Sinivee   
00029 //  Supports XML format (Type: SK-XML-1.0)
00030 //==================================================
00031 
00032 #ifdef  __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 #include <openssl/x509.h>
00037 #include <openssl/ocsp.h>
00038 #include <libdigidoc/DigiDocMem.h>
00039 #include <libdigidoc/DigiDocDefs.h>
00040 #include <libdigidoc/DigiDocError.h>
00041 #include <libdigidoc/DigiDocObj.h>
00042 #include <libdigidoc/DigiDocVerify.h>
00043 
00044 
00045 //==========< data structures >====================
00046 
00047 // supported format and version combination
00048 typedef struct FormatAndVer_st {
00049         char* szFormat;
00050         char* szVersion;        
00051 } FormatAndVer;
00052 
00053 
00054 //==========< admin functions >====================
00055 
00056 // returns the library name
00057 EXP_OPTION const char* getLibName();
00058 // returns the library version
00059 EXP_OPTION const char* getLibVersion();
00060 // returns an array of supported formats terminated by NULL
00061 EXP_OPTION const char** getSupportedFormats();
00062 // returns an array of supported formats  and versions terminated by NULL
00063 EXP_OPTION FormatAndVer* getSupportedFormatsAndVersions();
00064 // returns the GUI version
00065 EXP_OPTION const char* getGUIVersion();
00066 // sets the GUI version
00067 EXP_OPTION void setGUIVersion(const char* szVer);
00068 
00069 // initializes error library
00070 EXP_OPTION void initDigiDocLib();
00071 // cleanup of error library
00072 EXP_OPTION void finalizeDigiDocLib();
00073 
00074 // trim leading and trailing whitespace
00075 EXP_OPTION char* trim(char* src);
00076 
00077 // Sets a string element of a struct to a new value
00078 int setString(char** dest, const char* value, int valLen);
00079 
00080 EXP_OPTION int checkFileExists(const char* szFileName);
00081 
00082 int ddocPullUrl(const char* url, DigiDocMemBuf* pSendData, DigiDocMemBuf* pRecvData, 
00083                 const char* proxyHost, const char* proxyPort);
00084 
00085 // Cheks a combination of format and version for validity
00086 int ddocCheckFormatAndVer(const char* format, const char* version);
00087 
00088 
00089 //--------------------------------------------------
00090 // Converts timestamp (time_t) value to a struct
00091 // tm value. Caller must provide address of tm struct.
00092 // This function is used because loacltime() is not
00093 // thread-safe and win32 has no equvalent of localtime_r().
00094 // pTime - time_t value address
00095 // pTmStruct - struct tm address
00096 // bLocal - 1=localtime_r, 0=gmtime_r
00097 // returns error code or ERR_OK
00098 //--------------------------------------------------
00099 EXP_OPTION int ddocLocalTime(time_t* pTime, struct tm* pTmStruct, int bLocal);
00100 
00101 EXP_OPTION int getTempFileName(char* szFileName, int len);
00102 
00103 //==========< general crypto fucntions >============
00104 
00105 // calculates input files digest.
00106 // supports only SHA1
00107 EXP_OPTION int calculateFileDigest(const char* szFileName, int nDigestType,
00108                                                 byte* pDigestBuf, int* nDigestLen, long* lFileLen);
00109 
00110 // calculate file size
00111 EXP_OPTION int calculateFileSize(const char* szFileName, long* lFileLen);
00112 
00113 // calculates files RSA+SHA1 signature
00114 EXP_OPTION int calculateFileSignature(const char* szFileName, int nDigestType,
00115                                                         byte* pSigBuf, int* nSigLen,
00116                                                         const char *keyfile, const char* passwd);
00117 
00118 // sign some arbitrary daya
00119 EXP_OPTION int signData(const byte* data, int dlen, byte* pSigBuf, int* nSigLen,
00120                          int nDigestType, const char *keyfile, const char* passwd);
00121 
00122 // calculate digest over some arbitrary data
00123 EXP_OPTION int calculateDigest(const byte* data, int nDataLen, int nDigestType,
00124                                         byte* pDigestBuf, int* nDigestLen);
00125 
00126 
00127 
00128 //--------------------------------------------------
00129 // Prepares a new signature for signing and calculates
00130 // the final hash value to sign.
00131 // pSigDoc - signed document object
00132 // ppSigInfo - pointer for address of newly allocated signature
00133 // manifest - manifest or role
00134 // city - signers address , city
00135 // state - signers address , state or province
00136 // zip - signers address , postal code
00137 // country - signers address , country name
00138 // id - id for new signature. Optional, use NULL for default
00139 
00140 // return returns error code or ERR_OK
00141 //--------------------------------------------------
00142 EXP_OPTION int ddocPrepareSignature(SignedDoc* pSigDoc, SignatureInfo** ppSigInfo,
00143                          const char* manifest, const char* city, 
00144                          const char* state, const char* zip, 
00145                          const char* country, X509* pCert, const char* id);
00146 
00147 //--------------------------------------------------
00148 // Returns the hash to be signed with or without ASN1
00149 // prefix and with or without base64 encoding
00150 // pSigInfo - signature address
00151 // pBuf - buffer for hash value with or without prefix
00152 // pBufLen - pointer to buffer length
00153 // enc - return 0=unencoded, 1=base64, 2=hex
00154 // bWithAsn1Prefix - return with or without ASN1 prefix 1/0
00155 // return returns error code or ERR_OK
00156 //--------------------------------------------------
00157 EXP_OPTION int ddocGetSignedHash(SignatureInfo* pSigInfo, char* pBuf, int* pBufLen, int enc, int bWithAsn1Prefix);
00158 
00159 
00160 //==========< XML generating functions >=================
00161 // thse functions generate certain XML form info, that
00162 // is used as input data for either signing or digesting
00163 
00164 // creates XML <SignedInfo> block (actually signed info)
00165 EXP_OPTION char* createXMLSignedInfo(const SignedDoc* pSigDoc, const SignatureInfo* pSigInfo);
00166 // creates XML mime type <SinatureProperty> block for signing
00167 EXP_OPTION int createMimeType(char* buf, const char* mime, 
00168                                    const char* sigId, const char* docId);
00169 
00170 //==========< memory mgmt functions >=================
00171 
00172 // Get the filename part of full file name
00173 EXP_OPTION const char* getSimpleFileName(const char* szFileName);
00174 // Get the absolute filename with path
00175 EXP_OPTION int getFullFileName(const char* szFileName, char* szDest, int len);
00176 // Get the path part of full file name
00177   EXP_OPTION int getFileNamePath(const char* szFileName, char* szPath, int len);
00178 
00179 
00180 //------------------------ ??
00181 
00182 // Sets the signatures certificate and calculates
00183 EXP_OPTION int setSignatureCertFile(SignatureInfo* pSigInfo, const char* certFile);
00184 // Sets the signatures certificate and calculates it's digest
00185 EXP_OPTION int setSignatureCert(SignatureInfo* pSigInfo, X509* cert);
00186 
00187 // Sets the signature value 
00188 EXP_OPTION int setSignatureValue(SignatureInfo* pSigInfo, byte* szSignature, int sigLen);
00189 
00190 // Sets the signature value from a file that contains
00191 // the base64 encoded signature value
00192 EXP_OPTION int setSignatureValueFromFile(SignatureInfo* pSigInfo, char* szSigFile);
00193 
00194 
00195 //================< certficate info functions> =================================
00196 
00197 // Decodes a signature value
00198 void decodeSignatureValue(const char* b64val, int b64len, char* value, int* vlen);
00199 
00200 // Returns the user signatures certificate data
00201 EXP_OPTION X509* getSignCertData(const SignatureInfo* pSignInfo);
00202 // Returns the notary signatures certificate data
00203 //EXP_OPTION X509* getNotCertData(const NotaryInfo* pNotInfo);
00204 
00205 
00206 
00207 //================< deprecated functions> =================================
00208 // these functions are deprecated. Use the replacements in DigiDocCert.h
00209 // these functions will be removed in future releases!
00210 #ifdef WITH_DEPRECATED_FUNCTIONS
00211 
00212 // get signers id-code
00213 // USE: ddocCertGetSubjectPerCode(getSignCertData(pSignInfo), pMemBuf);
00214 EXP_OPTION int getSignerCode(const SignatureInfo* pSigInfo, char* buf);
00215 
00216 // get signers first name
00217 // USE: ddocCertGetSubjectFirstName(getSignCertData(pSignInfo), pMemBuf);
00218 EXP_OPTION int getSignerFirstName(const SignatureInfo* pSigInfo, char* buf);
00219 
00220 // get signers last name
00221 // USE: ddocCertGetSubjectLastName(getSignCertData(pSignInfo), pMemBuf);
00222 EXP_OPTION int getSignerLastName(const SignatureInfo* pSigInfo, char* buf);
00223 
00224 // get the whole signers CN in desired charset
00225 // USE: ddocCertGetSubjectCN(getSignCertData(pSignInfo), pMemBuf);
00226 EXP_OPTION int getSignerCN(const SignatureInfo* pSigInfo, char* buf, int bUTF8);
00227 
00228 #endif // WITH_DEPRECATED_FUNCTIONS
00229 
00230 //==================================================================================
00231 void CorrectCharacters(char *psText);
00232 
00233 #ifdef  __cplusplus
00234 }
00235 #endif
00236 
00237 
00238 #endif // __DIGI_DOC_LIB_H__
00239 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'