cryptplug.h
Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 00003 this is a C++-ification of: 00004 CRYPTPLUG - an independent cryptography plug-in API 00005 00006 Copyright (C) 2001,2004 Klarälvdalens Datakonsult AB 00007 00008 CRYPTPLUG is free software; you can redistribute it and/or modify 00009 it under the terms of GNU General Public License as published by 00010 the Free Software Foundation; version 2 of the License. 00011 00012 CRYPTPLUG is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #ifndef CRYPTPLUG_H 00023 #define CRYPTPLUG_H 00024 00025 #include <stdlib.h> 00026 00027 #include <gpgmepp/context.h> 00028 #include <gpgme.h> // need it for gpgme_protocol_t :( 00029 #include <tdepimmacros.h> 00030 00031 namespace GpgME { 00032 class ImportResult; 00033 } 00034 00162 typedef enum { 00163 Feature_undef = 0, 00164 00165 Feature_SignMessages = 1, 00166 Feature_VerifySignatures = 2, 00167 Feature_EncryptMessages = 3, 00168 Feature_DecryptMessages = 4, 00169 Feature_SendCertificates = 5, 00170 Feature_WarnSignCertificateExpiry = 6, 00171 Feature_WarnSignEmailNotInCertificate = 7, 00172 Feature_PinEntrySettings = 8, 00173 Feature_StoreMessagesWithSigs = 9, 00174 Feature_EncryptionCRLs = 10, 00175 Feature_WarnEncryptCertificateExpiry = 11, 00176 Feature_WarnEncryptEmailNotInCertificate = 12, 00177 Feature_StoreMessagesEncrypted = 13, 00178 Feature_CheckCertificatePath = 14, 00179 Feature_CertificateDirectoryService = 15, 00180 Feature_CRLDirectoryService = 16, 00181 Feature_CertificateInfo = 17 00182 } Feature; 00183 00184 /* dummy values */ 00185 typedef enum { 00186 PinRequest_undef = 0, 00187 00188 PinRequest_Always = 1, 00189 PinRequest_WhenAddingCerts = 2, 00190 PinRequest_AlwaysWhenSigning = 3, 00191 PinRequest_OncePerSession = 4, 00192 PinRequest_AfterMinutes = 5 00193 } PinRequests; 00194 00195 00196 typedef enum { 00197 SignatureCompoundMode_undef = 0, 00198 00199 SignatureCompoundMode_Opaque = 1, 00200 SignatureCompoundMode_Detached = 2 00201 } SignatureCompoundMode; 00202 00203 00204 typedef enum { 00205 SendCert_undef = 0, 00206 00207 SendCert_DontSend = 1, 00208 SendCert_SendOwn = 2, 00209 SendCert_SendChainWithoutRoot = 3, 00210 SendCert_SendChainWithRoot = 4 00211 } SendCertificates; 00212 00213 00214 typedef enum { 00215 SignAlg_undef = 0, 00216 00217 SignAlg_SHA1 = 1 00218 } SignatureAlgorithm; 00219 00220 00221 00222 typedef enum { 00223 EncryptAlg_undef = 0, 00224 00225 EncryptAlg_RSA = 1, 00226 EncryptAlg_SHA1 = 2, 00227 EncryptAlg_TripleDES = 3 00228 } EncryptionAlgorithm; 00229 00230 typedef enum { 00231 SignEmail_undef = 0, 00232 00233 SignEmail_SignAll = 1, 00234 SignEmail_Ask = 2, 00235 SignEmail_DontSign = 3 00236 } SignEmail; 00237 00238 typedef enum { 00239 EncryptEmail_undef = 0, 00240 00241 EncryptEmail_EncryptAll = 1, 00242 EncryptEmail_Ask = 2, 00243 EncryptEmail_DontEncrypt = 3 00244 } EncryptEmail; 00245 00246 typedef enum { 00247 CertSrc_undef = 0, 00248 00249 CertSrc_Server = 1, 00250 CertSrc_Local = 2, 00251 CertSrc_ServerLocal = CertSrc_Server | CertSrc_Local 00252 } CertificateSource; 00253 00254 00280 enum { 00281 SigStat_VALID = 0x0001, /* The signature is fully valid */ 00282 SigStat_GREEN = 0x0002, /* The signature is good. */ 00283 SigStat_RED = 0x0004, /* The signature is bad. */ 00284 SigStat_KEY_REVOKED = 0x0010, /* One key has been revoked. */ 00285 SigStat_KEY_EXPIRED = 0x0020, /* One key has expired. */ 00286 SigStat_SIG_EXPIRED = 0x0040, /* The signature has expired. */ 00287 SigStat_KEY_MISSING = 0x0080, /* Can't verify: key missing. */ 00288 SigStat_CRL_MISSING = 0x0100, /* CRL not available. */ 00289 SigStat_CRL_TOO_OLD = 0x0200, /* Available CRL is too old. */ 00290 SigStat_BAD_POLICY = 0x0400, /* A policy was not met. */ 00291 SigStat_SYS_ERROR = 0x0800, /* A system error occurred. */ 00292 00293 SigStat_NUMERICAL_CODE = 0x8000 /* An other error occurred. */ 00294 }; 00295 typedef unsigned long SigStatusFlags; 00296 00297 class CryptPlugWrapper; 00298 00299 class KDE_EXPORT CryptPlug { 00300 friend class CryptPlugWrapper; 00301 protected: 00302 CryptPlug(); 00303 virtual ~CryptPlug(); 00304 00305 // these must be set by subclasses: 00306 gpgme_protocol_t GPGMEPLUG_PROTOCOL; 00307 GpgME::Context::Protocol mProtocol; 00308 00309 /* definitions for signing */ 00310 // 1. opaque signatures (only used for S/MIME) 00311 int GPGMEPLUG_OPA_SIGN_INCLUDE_CLEARTEXT; 00312 int GPGMEPLUG_OPA_SIGN_MAKE_MIME_OBJECT; 00313 int GPGMEPLUG_OPA_SIGN_MAKE_MULTI_MIME; 00314 const char * GPGMEPLUG_OPA_SIGN_CTYPE_MAIN; 00315 const char * GPGMEPLUG_OPA_SIGN_CDISP_MAIN; 00316 const char * GPGMEPLUG_OPA_SIGN_CTENC_MAIN; 00317 const char * GPGMEPLUG_OPA_SIGN_CTYPE_VERSION; 00318 const char * GPGMEPLUG_OPA_SIGN_CDISP_VERSION; 00319 const char * GPGMEPLUG_OPA_SIGN_CTENC_VERSION; 00320 const char * GPGMEPLUG_OPA_SIGN_BTEXT_VERSION; 00321 const char * GPGMEPLUG_OPA_SIGN_CTYPE_CODE; 00322 const char * GPGMEPLUG_OPA_SIGN_CDISP_CODE; 00323 const char * GPGMEPLUG_OPA_SIGN_CTENC_CODE; 00324 const char * GPGMEPLUG_OPA_SIGN_FLAT_PREFIX; 00325 const char * GPGMEPLUG_OPA_SIGN_FLAT_SEPARATOR; 00326 const char * GPGMEPLUG_OPA_SIGN_FLAT_POSTFIX; 00327 // 2. detached signatures (used for S/MIME and for OpenPGP) 00328 int GPGMEPLUG_DET_SIGN_INCLUDE_CLEARTEXT; 00329 int GPGMEPLUG_DET_SIGN_MAKE_MIME_OBJECT; 00330 int GPGMEPLUG_DET_SIGN_MAKE_MULTI_MIME; 00331 const char * GPGMEPLUG_DET_SIGN_CTYPE_MAIN; 00332 const char * GPGMEPLUG_DET_SIGN_CDISP_MAIN; 00333 const char * GPGMEPLUG_DET_SIGN_CTENC_MAIN; 00334 const char * GPGMEPLUG_DET_SIGN_CTYPE_VERSION; 00335 const char * GPGMEPLUG_DET_SIGN_CDISP_VERSION; 00336 const char * GPGMEPLUG_DET_SIGN_CTENC_VERSION; 00337 const char * GPGMEPLUG_DET_SIGN_BTEXT_VERSION; 00338 const char * GPGMEPLUG_DET_SIGN_CTYPE_CODE; 00339 const char * GPGMEPLUG_DET_SIGN_CDISP_CODE; 00340 const char * GPGMEPLUG_DET_SIGN_CTENC_CODE; 00341 const char * GPGMEPLUG_DET_SIGN_FLAT_PREFIX; 00342 const char * GPGMEPLUG_DET_SIGN_FLAT_SEPARATOR; 00343 const char * GPGMEPLUG_DET_SIGN_FLAT_POSTFIX; 00344 // 3. common definitions for opaque and detached signing 00345 int __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY; 00346 00347 /* definitions for encoding */ 00348 int GPGMEPLUG_ENC_INCLUDE_CLEARTEXT; 00349 int GPGMEPLUG_ENC_MAKE_MIME_OBJECT; 00350 int GPGMEPLUG_ENC_MAKE_MULTI_MIME; 00351 const char * GPGMEPLUG_ENC_CTYPE_MAIN; 00352 const char * GPGMEPLUG_ENC_CDISP_MAIN; 00353 const char * GPGMEPLUG_ENC_CTENC_MAIN; 00354 const char * GPGMEPLUG_ENC_CTYPE_VERSION; 00355 const char * GPGMEPLUG_ENC_CDISP_VERSION; 00356 const char * GPGMEPLUG_ENC_CTENC_VERSION; 00357 const char * GPGMEPLUG_ENC_BTEXT_VERSION; 00358 const char * GPGMEPLUG_ENC_CTYPE_CODE; 00359 const char * GPGMEPLUG_ENC_CDISP_CODE; 00360 const char * GPGMEPLUG_ENC_CTENC_CODE; 00361 const char * GPGMEPLUG_ENC_FLAT_PREFIX; 00362 const char * GPGMEPLUG_ENC_FLAT_SEPARATOR; 00363 const char * GPGMEPLUG_ENC_FLAT_POSTFIX; 00364 int __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY; 00365 // end-of(these must be set by subclasses) 00366 00367 public: 00368 00369 #define CRYPTPLUG_CERT_DOES_NEVER_EXPIRE 365000 00370 #define CRYPTPLUG_ERR_WRONG_KEY_USAGE 0x7070 00371 00384 bool initialize( void ); 00385 00397 //void deinitialize( void ); 00398 00411 bool hasFeature( ::Feature ); 00412 00622 struct StructuringInfo { 00623 bool includeCleartext; 00633 bool makeMimeObject; 00635 /* the following are used for MIME messages only */ 00636 bool makeMultiMime; 00644 char* contentTypeMain; 00648 char* contentDispMain; 00652 char* contentTEncMain; 00656 char* contentTypeVersion; 00663 char* contentDispVersion; 00671 char* contentTEncVersion; 00679 char* bodyTextVersion; 00686 char* contentTypeCode; 00692 char* contentDispCode; 00697 char* contentTEncCode; 00702 /* the following are used for flat non-MIME messages only */ 00703 char* flatTextPrefix; 00708 char* flatTextSeparator; 00714 char* flatTextPostfix; 00718 }; 00719 00720 00746 inline void init_StructuringInfo( struct StructuringInfo* s ) 00747 { 00748 if( ! s ) return; 00749 00750 s->includeCleartext = false; 00751 00752 s->makeMimeObject = false; 00753 s->makeMultiMime = false; 00754 00755 s->contentTypeMain = 0; 00756 s->contentDispMain = 0; 00757 s->contentTEncMain = 0; 00758 00759 s->contentTypeVersion = 0; 00760 s->contentDispVersion = 0; 00761 s->contentTEncVersion = 0; 00762 s->bodyTextVersion = 0; 00763 00764 s->contentTypeCode = 0; 00765 s->contentDispCode = 0; 00766 s->contentTEncCode = 0; 00767 00768 s->flatTextPrefix = 0; 00769 s->flatTextSeparator = 0; 00770 s->flatTextPostfix = 0; 00771 } 00772 00787 inline void free_StructuringInfo( struct StructuringInfo* s ) 00788 { 00789 if( ! s ) return; 00790 if( s->contentTypeMain ) free( s->contentTypeMain ); 00791 if( s->contentDispMain ) free( s->contentDispMain ); 00792 if( s->contentTEncMain ) free( s->contentTEncMain ); 00793 if( s->contentTypeVersion ) free( s->contentTypeVersion ); 00794 if( s->contentDispVersion ) free( s->contentDispVersion ); 00795 if( s->contentTEncVersion ) free( s->contentTEncVersion ); 00796 if( s->bodyTextVersion ) free( s->bodyTextVersion ); 00797 if( s->contentTypeCode ) free( s->contentTypeCode ); 00798 if( s->contentDispCode ) free( s->contentDispCode ); 00799 if( s->contentTEncCode ) free( s->contentTEncCode ); 00800 if( s->flatTextPrefix ) free( s->flatTextPrefix ); 00801 if( s->flatTextSeparator ) free( s->flatTextSeparator ); 00802 if( s->flatTextPostfix ) free( s->flatTextPostfix ); 00803 } 00804 00805 00808 struct SignatureMetaDataExtendedInfo 00809 { 00810 struct tm* creation_time; 00811 SigStatusFlags sigStatusFlags; 00812 char* status_text; 00813 char* keyid; 00814 char* fingerprint; 00815 char* algo; 00816 char* userid; 00817 char* name; 00818 char* comment; 00819 char** emailList; 00820 int emailCount; 00821 unsigned long algo_num; 00822 unsigned long validity; 00823 unsigned long userid_num; 00824 unsigned long keylen; 00825 unsigned long key_created; 00826 unsigned long key_expires; 00827 }; 00828 00831 struct SignatureMetaData { 00832 char* status; 00833 struct SignatureMetaDataExtendedInfo* extended_info; 00834 int extended_info_count; 00835 int status_code; 00836 }; 00837 00859 bool checkMessageSignature( char** cleartext, 00860 const char* signaturetext, 00861 bool signatureIsBinary, 00862 int signatureLen, 00863 struct SignatureMetaData* sigmeta, 00864 char** attrOrder, 00865 const char* unknownAttrsHandling ); 00866 00867 00878 bool decryptMessage( const char* ciphertext, 00879 bool cipherIsBinary, 00880 int cipherLen, 00881 const char** cleartext, 00882 const char* certificate, 00883 int* errId, 00884 char** errTxt ); 00885 00897 bool decryptAndCheckMessage( const char* ciphertext, 00898 bool cipherIsBinary, 00899 int cipherLen, 00900 const char** cleartext, 00901 const char* certificate, 00902 bool* signatureFound, 00903 struct SignatureMetaData* sigmeta, 00904 int* errId, 00905 char** errTxt, 00906 char** attrOrder, 00907 const char* unknownAttrsHandling ); 00908 00909 struct DnPair { 00910 char *key; 00911 char *value; 00912 }; 00913 00914 struct CertificateInfo { 00915 char** userid; 00916 char* userid_0_org; 00917 char* serial; 00918 char* fingerprint; 00919 00920 char* issuer_org; 00921 char* issuer_reord; 00922 char* chainid; 00923 00924 char* caps; 00925 00926 unsigned long created; 00927 unsigned long expire; 00928 00929 int secret : 1; 00930 int invalid : 1; 00931 int expired : 1; 00932 int disabled : 1; 00933 00934 struct DnPair *dnarray; /* parsed values from userid[0] */ 00935 }; 00936 00940 GpgME::ImportResult importCertificateFromMem( const char* data, size_t length ); 00941 }; // class CryptPlug 00942 00943 class SMIMECryptPlug : public CryptPlug { 00944 public: 00945 SMIMECryptPlug(); 00946 }; 00947 00948 class OpenPGPCryptPlug : public CryptPlug { 00949 public: 00950 OpenPGPCryptPlug(); 00951 }; 00952 00953 #endif /*CRYPTPLUG_H*/ 00954