certmanager/lib

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