00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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>
00029
00030 namespace GpgME {
00031 class ImportResult;
00032 }
00033
00161 typedef enum {
00162 Feature_undef = 0,
00163
00164 Feature_SignMessages = 1,
00165 Feature_VerifySignatures = 2,
00166 Feature_EncryptMessages = 3,
00167 Feature_DecryptMessages = 4,
00168 Feature_SendCertificates = 5,
00169 Feature_WarnSignCertificateExpiry = 6,
00170 Feature_WarnSignEmailNotInCertificate = 7,
00171 Feature_PinEntrySettings = 8,
00172 Feature_StoreMessagesWithSigs = 9,
00173 Feature_EncryptionCRLs = 10,
00174 Feature_WarnEncryptCertificateExpiry = 11,
00175 Feature_WarnEncryptEmailNotInCertificate = 12,
00176 Feature_StoreMessagesEncrypted = 13,
00177 Feature_CheckCertificatePath = 14,
00178 Feature_CertificateDirectoryService = 15,
00179 Feature_CRLDirectoryService = 16,
00180 Feature_CertificateInfo = 17
00181 } Feature;
00182
00183
00184 typedef enum {
00185 PinRequest_undef = 0,
00186
00187 PinRequest_Always = 1,
00188 PinRequest_WhenAddingCerts = 2,
00189 PinRequest_AlwaysWhenSigning = 3,
00190 PinRequest_OncePerSession = 4,
00191 PinRequest_AfterMinutes = 5
00192 } PinRequests;
00193
00194
00195 typedef enum {
00196 SignatureCompoundMode_undef = 0,
00197
00198 SignatureCompoundMode_Opaque = 1,
00199 SignatureCompoundMode_Detached = 2
00200 } SignatureCompoundMode;
00201
00202
00203 typedef enum {
00204 SendCert_undef = 0,
00205
00206 SendCert_DontSend = 1,
00207 SendCert_SendOwn = 2,
00208 SendCert_SendChainWithoutRoot = 3,
00209 SendCert_SendChainWithRoot = 4
00210 } SendCertificates;
00211
00212
00213 typedef enum {
00214 SignAlg_undef = 0,
00215
00216 SignAlg_SHA1 = 1
00217 } SignatureAlgorithm;
00218
00219
00220
00221 typedef enum {
00222 EncryptAlg_undef = 0,
00223
00224 EncryptAlg_RSA = 1,
00225 EncryptAlg_SHA1 = 2,
00226 EncryptAlg_TripleDES = 3
00227 } EncryptionAlgorithm;
00228
00229 typedef enum {
00230 SignEmail_undef = 0,
00231
00232 SignEmail_SignAll = 1,
00233 SignEmail_Ask = 2,
00234 SignEmail_DontSign = 3
00235 } SignEmail;
00236
00237 typedef enum {
00238 EncryptEmail_undef = 0,
00239
00240 EncryptEmail_EncryptAll = 1,
00241 EncryptEmail_Ask = 2,
00242 EncryptEmail_DontEncrypt = 3
00243 } EncryptEmail;
00244
00245 typedef enum {
00246 CertSrc_undef = 0,
00247
00248 CertSrc_Server = 1,
00249 CertSrc_Local = 2,
00250 CertSrc_ServerLocal = CertSrc_Server | CertSrc_Local
00251 } CertificateSource;
00252
00253
00279 enum {
00280 SigStat_VALID = 0x0001,
00281 SigStat_GREEN = 0x0002,
00282 SigStat_RED = 0x0004,
00283 SigStat_KEY_REVOKED = 0x0010,
00284 SigStat_KEY_EXPIRED = 0x0020,
00285 SigStat_SIG_EXPIRED = 0x0040,
00286 SigStat_KEY_MISSING = 0x0080,
00287 SigStat_CRL_MISSING = 0x0100,
00288 SigStat_CRL_TOO_OLD = 0x0200,
00289 SigStat_BAD_POLICY = 0x0400,
00290 SigStat_SYS_ERROR = 0x0800,
00291
00292 SigStat_NUMERICAL_CODE = 0x8000
00293 };
00294 typedef unsigned long SigStatusFlags;
00295
00296 class CryptPlugWrapper;
00297
00298 class CryptPlug {
00299 friend class CryptPlugWrapper;
00300 protected:
00301 CryptPlug();
00302 virtual ~CryptPlug();
00303
00304
00305 gpgme_protocol_t GPGMEPLUG_PROTOCOL;
00306 GpgME::Context::Protocol mProtocol;
00307
00308
00309
00310 int GPGMEPLUG_OPA_SIGN_INCLUDE_CLEARTEXT;
00311 int GPGMEPLUG_OPA_SIGN_MAKE_MIME_OBJECT;
00312 int GPGMEPLUG_OPA_SIGN_MAKE_MULTI_MIME;
00313 const char * GPGMEPLUG_OPA_SIGN_CTYPE_MAIN;
00314 const char * GPGMEPLUG_OPA_SIGN_CDISP_MAIN;
00315 const char * GPGMEPLUG_OPA_SIGN_CTENC_MAIN;
00316 const char * GPGMEPLUG_OPA_SIGN_CTYPE_VERSION;
00317 const char * GPGMEPLUG_OPA_SIGN_CDISP_VERSION;
00318 const char * GPGMEPLUG_OPA_SIGN_CTENC_VERSION;
00319 const char * GPGMEPLUG_OPA_SIGN_BTEXT_VERSION;
00320 const char * GPGMEPLUG_OPA_SIGN_CTYPE_CODE;
00321 const char * GPGMEPLUG_OPA_SIGN_CDISP_CODE;
00322 const char * GPGMEPLUG_OPA_SIGN_CTENC_CODE;
00323 const char * GPGMEPLUG_OPA_SIGN_FLAT_PREFIX;
00324 const char * GPGMEPLUG_OPA_SIGN_FLAT_SEPARATOR;
00325 const char * GPGMEPLUG_OPA_SIGN_FLAT_POSTFIX;
00326
00327 int GPGMEPLUG_DET_SIGN_INCLUDE_CLEARTEXT;
00328 int GPGMEPLUG_DET_SIGN_MAKE_MIME_OBJECT;
00329 int GPGMEPLUG_DET_SIGN_MAKE_MULTI_MIME;
00330 const char * GPGMEPLUG_DET_SIGN_CTYPE_MAIN;
00331 const char * GPGMEPLUG_DET_SIGN_CDISP_MAIN;
00332 const char * GPGMEPLUG_DET_SIGN_CTENC_MAIN;
00333 const char * GPGMEPLUG_DET_SIGN_CTYPE_VERSION;
00334 const char * GPGMEPLUG_DET_SIGN_CDISP_VERSION;
00335 const char * GPGMEPLUG_DET_SIGN_CTENC_VERSION;
00336 const char * GPGMEPLUG_DET_SIGN_BTEXT_VERSION;
00337 const char * GPGMEPLUG_DET_SIGN_CTYPE_CODE;
00338 const char * GPGMEPLUG_DET_SIGN_CDISP_CODE;
00339 const char * GPGMEPLUG_DET_SIGN_CTENC_CODE;
00340 const char * GPGMEPLUG_DET_SIGN_FLAT_PREFIX;
00341 const char * GPGMEPLUG_DET_SIGN_FLAT_SEPARATOR;
00342 const char * GPGMEPLUG_DET_SIGN_FLAT_POSTFIX;
00343
00344 int __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY;
00345
00346
00347 int GPGMEPLUG_ENC_INCLUDE_CLEARTEXT;
00348 int GPGMEPLUG_ENC_MAKE_MIME_OBJECT;
00349 int GPGMEPLUG_ENC_MAKE_MULTI_MIME;
00350 const char * GPGMEPLUG_ENC_CTYPE_MAIN;
00351 const char * GPGMEPLUG_ENC_CDISP_MAIN;
00352 const char * GPGMEPLUG_ENC_CTENC_MAIN;
00353 const char * GPGMEPLUG_ENC_CTYPE_VERSION;
00354 const char * GPGMEPLUG_ENC_CDISP_VERSION;
00355 const char * GPGMEPLUG_ENC_CTENC_VERSION;
00356 const char * GPGMEPLUG_ENC_BTEXT_VERSION;
00357 const char * GPGMEPLUG_ENC_CTYPE_CODE;
00358 const char * GPGMEPLUG_ENC_CDISP_CODE;
00359 const char * GPGMEPLUG_ENC_CTENC_CODE;
00360 const char * GPGMEPLUG_ENC_FLAT_PREFIX;
00361 const char * GPGMEPLUG_ENC_FLAT_SEPARATOR;
00362 const char * GPGMEPLUG_ENC_FLAT_POSTFIX;
00363 int __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY;
00364
00365
00366 public:
00367
00368 #define CRYPTPLUG_CERT_DOES_NEVER_EXPIRE 365000
00369 #define CRYPTPLUG_ERR_WRONG_KEY_USAGE 0x7070
00370
00383 bool initialize( void );
00384
00396
00397
00410 bool hasFeature( Feature );
00411
00621 struct StructuringInfo {
00622 bool includeCleartext;
00632 bool makeMimeObject;
00634
00635 bool makeMultiMime;
00643 char* contentTypeMain;
00647 char* contentDispMain;
00651 char* contentTEncMain;
00655 char* contentTypeVersion;
00662 char* contentDispVersion;
00670 char* contentTEncVersion;
00678 char* bodyTextVersion;
00685 char* contentTypeCode;
00691 char* contentDispCode;
00696 char* contentTEncCode;
00701
00702 char* flatTextPrefix;
00707 char* flatTextSeparator;
00713 char* flatTextPostfix;
00717 };
00718
00719
00745 inline void init_StructuringInfo( struct StructuringInfo* s )
00746 {
00747 if( ! s ) return;
00748
00749 s->includeCleartext = false;
00750
00751 s->makeMimeObject = false;
00752 s->makeMultiMime = false;
00753
00754 s->contentTypeMain = 0;
00755 s->contentDispMain = 0;
00756 s->contentTEncMain = 0;
00757
00758 s->contentTypeVersion = 0;
00759 s->contentDispVersion = 0;
00760 s->contentTEncVersion = 0;
00761 s->bodyTextVersion = 0;
00762
00763 s->contentTypeCode = 0;
00764 s->contentDispCode = 0;
00765 s->contentTEncCode = 0;
00766
00767 s->flatTextPrefix = 0;
00768 s->flatTextSeparator = 0;
00769 s->flatTextPostfix = 0;
00770 }
00771
00786 inline void free_StructuringInfo( struct StructuringInfo* s )
00787 {
00788 if( ! s ) return;
00789 if( s->contentTypeMain ) free( s->contentTypeMain );
00790 if( s->contentDispMain ) free( s->contentDispMain );
00791 if( s->contentTEncMain ) free( s->contentTEncMain );
00792 if( s->contentTypeVersion ) free( s->contentTypeVersion );
00793 if( s->contentDispVersion ) free( s->contentDispVersion );
00794 if( s->contentTEncVersion ) free( s->contentTEncVersion );
00795 if( s->bodyTextVersion ) free( s->bodyTextVersion );
00796 if( s->contentTypeCode ) free( s->contentTypeCode );
00797 if( s->contentDispCode ) free( s->contentDispCode );
00798 if( s->contentTEncCode ) free( s->contentTEncCode );
00799 if( s->flatTextPrefix ) free( s->flatTextPrefix );
00800 if( s->flatTextSeparator ) free( s->flatTextSeparator );
00801 if( s->flatTextPostfix ) free( s->flatTextPostfix );
00802 }
00803
00804
00807 struct SignatureMetaDataExtendedInfo
00808 {
00809 struct tm* creation_time;
00810 SigStatusFlags sigStatusFlags;
00811 char* status_text;
00812 char* keyid;
00813 char* fingerprint;
00814 char* algo;
00815 char* userid;
00816 char* name;
00817 char* comment;
00818 char** emailList;
00819 int emailCount;
00820 unsigned long algo_num;
00821 unsigned long validity;
00822 unsigned long userid_num;
00823 unsigned long keylen;
00824 unsigned long key_created;
00825 unsigned long key_expires;
00826 };
00827
00830 struct SignatureMetaData {
00831 char* status;
00832 struct SignatureMetaDataExtendedInfo* extended_info;
00833 int extended_info_count;
00834 int status_code;
00835 };
00836
00858 bool checkMessageSignature( char** cleartext,
00859 const char* signaturetext,
00860 bool signatureIsBinary,
00861 int signatureLen,
00862 struct SignatureMetaData* sigmeta,
00863 char** attrOrder,
00864 const char* unknownAttrsHandling );
00865
00866
00877 bool decryptMessage( const char* ciphertext,
00878 bool cipherIsBinary,
00879 int cipherLen,
00880 const char** cleartext,
00881 const char* certificate,
00882 int* errId,
00883 char** errTxt );
00884
00896 bool decryptAndCheckMessage( const char* ciphertext,
00897 bool cipherIsBinary,
00898 int cipherLen,
00899 const char** cleartext,
00900 const char* certificate,
00901 bool* signatureFound,
00902 struct SignatureMetaData* sigmeta,
00903 int* errId,
00904 char** errTxt,
00905 char** attrOrder,
00906 const char* unknownAttrsHandling );
00907
00908 struct DnPair {
00909 char *key;
00910 char *value;
00911 };
00912
00913 struct CertificateInfo {
00914 char** userid;
00915 char* userid_0_org;
00916 char* serial;
00917 char* fingerprint;
00918
00919 char* issuer_org;
00920 char* issuer_reord;
00921 char* chainid;
00922
00923 char* caps;
00924
00925 unsigned long created;
00926 unsigned long expire;
00927
00928 int secret : 1;
00929 int invalid : 1;
00930 int expired : 1;
00931 int disabled : 1;
00932
00933 struct DnPair *dnarray;
00934 };
00935
00939 GpgME::ImportResult importCertificateFromMem( const char* data, size_t length );
00940 };
00941
00942 class SMIMECryptPlug : public CryptPlug {
00943 public:
00944 SMIMECryptPlug();
00945 };
00946
00947 class OpenPGPCryptPlug : public CryptPlug {
00948 public:
00949 OpenPGPCryptPlug();
00950 };
00951
00952 #endif
00953