certmanager/lib

cryptplug.h
Go to the documentation of this file.
1/*
2 this is a C++-ification of:
3 CRYPTPLUG - an independent cryptography plug-in API
4
5 Copyright (C) 2001,2004 Klarälvdalens Datakonsult AB
6
7 CRYPTPLUG is free software; you can redistribute it and/or modify
8 it under the terms of GNU General Public License as published by
9 the Free Software Foundation; version 2 of the License.
10
11 CRYPTPLUG is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19*/
20
21#ifndef CRYPTPLUG_H
22#define CRYPTPLUG_H
23
24#include <stdlib.h>
25
26#include <gpgmepp/context.h>
27#include <gpgme.h> // need it for gpgme_protocol_t :(
28#include <tdemacros.h>
29
30namespace GpgME {
31 class ImportResult;
32}
33
161typedef enum {
162 Feature_undef = 0,
163
164 Feature_SignMessages = 1,
165 Feature_VerifySignatures = 2,
166 Feature_EncryptMessages = 3,
167 Feature_DecryptMessages = 4,
168 Feature_SendCertificates = 5,
169 Feature_WarnSignCertificateExpiry = 6,
170 Feature_WarnSignEmailNotInCertificate = 7,
171 Feature_PinEntrySettings = 8,
172 Feature_StoreMessagesWithSigs = 9,
173 Feature_EncryptionCRLs = 10,
174 Feature_WarnEncryptCertificateExpiry = 11,
175 Feature_WarnEncryptEmailNotInCertificate = 12,
176 Feature_StoreMessagesEncrypted = 13,
177 Feature_CheckCertificatePath = 14,
178 Feature_CertificateDirectoryService = 15,
179 Feature_CRLDirectoryService = 16,
180 Feature_CertificateInfo = 17
181} Feature;
182
183/* dummy values */
184typedef enum {
185 PinRequest_undef = 0,
186
187 PinRequest_Always = 1,
188 PinRequest_WhenAddingCerts = 2,
189 PinRequest_AlwaysWhenSigning = 3,
190 PinRequest_OncePerSession = 4,
191 PinRequest_AfterMinutes = 5
192} PinRequests;
193
194
195typedef enum {
196 SignatureCompoundMode_undef = 0,
197
198 SignatureCompoundMode_Opaque = 1,
199 SignatureCompoundMode_Detached = 2
200} SignatureCompoundMode;
201
202
203typedef enum {
204 SendCert_undef = 0,
205
206 SendCert_DontSend = 1,
207 SendCert_SendOwn = 2,
208 SendCert_SendChainWithoutRoot = 3,
209 SendCert_SendChainWithRoot = 4
210} SendCertificates;
211
212
213typedef enum {
214 SignAlg_undef = 0,
215
216 SignAlg_SHA1 = 1
217} SignatureAlgorithm;
218
219
220
221typedef enum {
222 EncryptAlg_undef = 0,
223
224 EncryptAlg_RSA = 1,
225 EncryptAlg_SHA1 = 2,
226 EncryptAlg_TripleDES = 3
227} EncryptionAlgorithm;
228
229typedef enum {
230 SignEmail_undef = 0,
231
232 SignEmail_SignAll = 1,
233 SignEmail_Ask = 2,
234 SignEmail_DontSign = 3
235} SignEmail;
236
237typedef enum {
238 EncryptEmail_undef = 0,
239
240 EncryptEmail_EncryptAll = 1,
241 EncryptEmail_Ask = 2,
242 EncryptEmail_DontEncrypt = 3
243} EncryptEmail;
244
245typedef enum {
246 CertSrc_undef = 0,
247
248 CertSrc_Server = 1,
249 CertSrc_Local = 2,
250 CertSrc_ServerLocal = CertSrc_Server | CertSrc_Local
251} CertificateSource;
252
253
279enum {
280 SigStat_VALID = 0x0001, /* The signature is fully valid */
281 SigStat_GREEN = 0x0002, /* The signature is good. */
282 SigStat_RED = 0x0004, /* The signature is bad. */
283 SigStat_KEY_REVOKED = 0x0010, /* One key has been revoked. */
284 SigStat_KEY_EXPIRED = 0x0020, /* One key has expired. */
285 SigStat_SIG_EXPIRED = 0x0040, /* The signature has expired. */
286 SigStat_KEY_MISSING = 0x0080, /* Can't verify: key missing. */
287 SigStat_CRL_MISSING = 0x0100, /* CRL not available. */
288 SigStat_CRL_TOO_OLD = 0x0200, /* Available CRL is too old. */
289 SigStat_BAD_POLICY = 0x0400, /* A policy was not met. */
290 SigStat_SYS_ERROR = 0x0800, /* A system error occurred. */
291
292 SigStat_NUMERICAL_CODE = 0x8000 /* An other error occurred. */
293};
294typedef unsigned long SigStatusFlags;
295
296class CryptPlugWrapper;
297
298class TDE_EXPORT CryptPlug {
299 friend class CryptPlugWrapper;
300protected:
301 CryptPlug();
302 virtual ~CryptPlug();
303
304 // these must be set by subclasses:
305 gpgme_protocol_t GPGMEPLUG_PROTOCOL;
306 GpgME::Context::Protocol mProtocol;
307
308 /* definitions for signing */
309 // 1. opaque signatures (only used for S/MIME)
310 int GPGMEPLUG_OPA_SIGN_INCLUDE_CLEARTEXT;
311 int GPGMEPLUG_OPA_SIGN_MAKE_MIME_OBJECT;
312 int GPGMEPLUG_OPA_SIGN_MAKE_MULTI_MIME;
313 const char * GPGMEPLUG_OPA_SIGN_CTYPE_MAIN;
314 const char * GPGMEPLUG_OPA_SIGN_CDISP_MAIN;
315 const char * GPGMEPLUG_OPA_SIGN_CTENC_MAIN;
316 const char * GPGMEPLUG_OPA_SIGN_CTYPE_VERSION;
317 const char * GPGMEPLUG_OPA_SIGN_CDISP_VERSION;
318 const char * GPGMEPLUG_OPA_SIGN_CTENC_VERSION;
319 const char * GPGMEPLUG_OPA_SIGN_BTEXT_VERSION;
320 const char * GPGMEPLUG_OPA_SIGN_CTYPE_CODE;
321 const char * GPGMEPLUG_OPA_SIGN_CDISP_CODE;
322 const char * GPGMEPLUG_OPA_SIGN_CTENC_CODE;
323 const char * GPGMEPLUG_OPA_SIGN_FLAT_PREFIX;
324 const char * GPGMEPLUG_OPA_SIGN_FLAT_SEPARATOR;
325 const char * GPGMEPLUG_OPA_SIGN_FLAT_POSTFIX;
326 // 2. detached signatures (used for S/MIME and for OpenPGP)
327 int GPGMEPLUG_DET_SIGN_INCLUDE_CLEARTEXT;
328 int GPGMEPLUG_DET_SIGN_MAKE_MIME_OBJECT;
329 int GPGMEPLUG_DET_SIGN_MAKE_MULTI_MIME;
330 const char * GPGMEPLUG_DET_SIGN_CTYPE_MAIN;
331 const char * GPGMEPLUG_DET_SIGN_CDISP_MAIN;
332 const char * GPGMEPLUG_DET_SIGN_CTENC_MAIN;
333 const char * GPGMEPLUG_DET_SIGN_CTYPE_VERSION;
334 const char * GPGMEPLUG_DET_SIGN_CDISP_VERSION;
335 const char * GPGMEPLUG_DET_SIGN_CTENC_VERSION;
336 const char * GPGMEPLUG_DET_SIGN_BTEXT_VERSION;
337 const char * GPGMEPLUG_DET_SIGN_CTYPE_CODE;
338 const char * GPGMEPLUG_DET_SIGN_CDISP_CODE;
339 const char * GPGMEPLUG_DET_SIGN_CTENC_CODE;
340 const char * GPGMEPLUG_DET_SIGN_FLAT_PREFIX;
341 const char * GPGMEPLUG_DET_SIGN_FLAT_SEPARATOR;
342 const char * GPGMEPLUG_DET_SIGN_FLAT_POSTFIX;
343 // 3. common definitions for opaque and detached signing
344 int __GPGMEPLUG_SIGNATURE_CODE_IS_BINARY;
345
346 /* definitions for encoding */
347 int GPGMEPLUG_ENC_INCLUDE_CLEARTEXT;
348 int GPGMEPLUG_ENC_MAKE_MIME_OBJECT;
349 int GPGMEPLUG_ENC_MAKE_MULTI_MIME;
350 const char * GPGMEPLUG_ENC_CTYPE_MAIN;
351 const char * GPGMEPLUG_ENC_CDISP_MAIN;
352 const char * GPGMEPLUG_ENC_CTENC_MAIN;
353 const char * GPGMEPLUG_ENC_CTYPE_VERSION;
354 const char * GPGMEPLUG_ENC_CDISP_VERSION;
355 const char * GPGMEPLUG_ENC_CTENC_VERSION;
356 const char * GPGMEPLUG_ENC_BTEXT_VERSION;
357 const char * GPGMEPLUG_ENC_CTYPE_CODE;
358 const char * GPGMEPLUG_ENC_CDISP_CODE;
359 const char * GPGMEPLUG_ENC_CTENC_CODE;
360 const char * GPGMEPLUG_ENC_FLAT_PREFIX;
361 const char * GPGMEPLUG_ENC_FLAT_SEPARATOR;
362 const char * GPGMEPLUG_ENC_FLAT_POSTFIX;
363 int __GPGMEPLUG_ENCRYPTED_CODE_IS_BINARY;
364 // end-of(these must be set by subclasses)
365
366public:
367
368#define CRYPTPLUG_CERT_DOES_NEVER_EXPIRE 365000
369#define CRYPTPLUG_ERR_WRONG_KEY_USAGE 0x7070
370
383bool initialize( void );
384
396//void deinitialize( void );
397
410bool hasFeature( ::Feature );
411
634 /* the following are used for MIME messages only */
701 /* the following are used for flat non-MIME messages only */
717};
718
719
745 inline void init_StructuringInfo( struct StructuringInfo* s )
746 {
747 if( ! s ) return;
748
749 s->includeCleartext = false;
750
751 s->makeMimeObject = false;
752 s->makeMultiMime = false;
753
754 s->contentTypeMain = 0;
755 s->contentDispMain = 0;
756 s->contentTEncMain = 0;
757
758 s->contentTypeVersion = 0;
759 s->contentDispVersion = 0;
760 s->contentTEncVersion = 0;
761 s->bodyTextVersion = 0;
762
763 s->contentTypeCode = 0;
764 s->contentDispCode = 0;
765 s->contentTEncCode = 0;
766
767 s->flatTextPrefix = 0;
768 s->flatTextSeparator = 0;
769 s->flatTextPostfix = 0;
770 }
771
786 inline void free_StructuringInfo( struct StructuringInfo* s )
787 {
788 if( ! s ) return;
789 if( s->contentTypeMain ) free( s->contentTypeMain );
790 if( s->contentDispMain ) free( s->contentDispMain );
791 if( s->contentTEncMain ) free( s->contentTEncMain );
792 if( s->contentTypeVersion ) free( s->contentTypeVersion );
793 if( s->contentDispVersion ) free( s->contentDispVersion );
794 if( s->contentTEncVersion ) free( s->contentTEncVersion );
795 if( s->bodyTextVersion ) free( s->bodyTextVersion );
796 if( s->contentTypeCode ) free( s->contentTypeCode );
797 if( s->contentDispCode ) free( s->contentDispCode );
798 if( s->contentTEncCode ) free( s->contentTEncCode );
799 if( s->flatTextPrefix ) free( s->flatTextPrefix );
800 if( s->flatTextSeparator ) free( s->flatTextSeparator );
801 if( s->flatTextPostfix ) free( s->flatTextPostfix );
802 }
803
804
807struct SignatureMetaDataExtendedInfo
808{
809 struct tm* creation_time;
810 SigStatusFlags sigStatusFlags;
811 char* status_text;
812 char* keyid;
813 char* fingerprint;
814 char* algo;
815 char* userid;
816 char* name;
817 char* comment;
818 char** emailList;
819 int emailCount;
820 unsigned long algo_num;
821 unsigned long validity;
822 unsigned long userid_num;
823 unsigned long keylen;
824 unsigned long key_created;
825 unsigned long key_expires;
826};
827
830struct SignatureMetaData {
831 char* status;
832 struct SignatureMetaDataExtendedInfo* extended_info;
833 int extended_info_count;
834 int status_code;
835};
836
858bool checkMessageSignature( char** cleartext,
859 const char* signaturetext,
860 bool signatureIsBinary,
861 int signatureLen,
862 struct SignatureMetaData* sigmeta,
863 char** attrOrder,
864 const char* unknownAttrsHandling );
865
866
877bool decryptMessage( const char* ciphertext,
878 bool cipherIsBinary,
879 int cipherLen,
880 const char** cleartext,
881 const char* certificate,
882 int* errId,
883 char** errTxt );
884
896bool decryptAndCheckMessage( const char* ciphertext,
897 bool cipherIsBinary,
898 int cipherLen,
899 const char** cleartext,
900 const char* certificate,
901 bool* signatureFound,
902 struct SignatureMetaData* sigmeta,
903 int* errId,
904 char** errTxt,
905 char** attrOrder,
906 const char* unknownAttrsHandling );
907
908struct DnPair {
909 char *key;
910 char *value;
911};
912
913struct CertificateInfo {
914 char** userid;
915 char* userid_0_org;
916 char* serial;
917 char* fingerprint;
918
919 char* issuer_org;
920 char* issuer_reord;
921 char* chainid;
922
923 char* caps;
924
925 unsigned long created;
926 unsigned long expire;
927
928 int secret : 1;
929 int invalid : 1;
930 int expired : 1;
931 int disabled : 1;
932
933 struct DnPair *dnarray; /* parsed values from userid[0] */
934};
935
939 GpgME::ImportResult importCertificateFromMem( const char* data, size_t length );
940}; // class CryptPlug
941
942class SMIMECryptPlug : public CryptPlug {
943public:
944 SMIMECryptPlug();
945};
946
947class OpenPGPCryptPlug : public CryptPlug {
948public:
949 OpenPGPCryptPlug();
950};
951
952#endif /*CRYPTPLUG_H*/
953
This class provides C++ access to the CRYPTPLUG API.
void init_StructuringInfo(struct StructuringInfo *s)
If you are not planning to write your own cryptography plugin you should ignore this function!
Definition: cryptplug.h:745
bool hasFeature(::Feature)
This function returns true if the specified feature is available in the plugin, and false otherwise.
void free_StructuringInfo(struct StructuringInfo *s)
Important method for freeing all memory that was allocated for the char* members of a StructuringInfo...
Definition: cryptplug.h:786
Information record returned by signing and by encrypting functions - this record should be used toget...
Definition: cryptplug.h:621