merged in default ENGINE-463
authorKrista Bennett <krista@pep-project.org>
Thu, 04 Oct 2018 07:10:08 +0200
branchENGINE-463
changeset 29849399e0ee7dcb
parent 2977 dbb4edf4d231
parent 2979 104040105413
child 2985 536d628a21a2
merged in default
src/pEpEngine.c
src/pEpEngine.h
test/src/SuiteMaker.cc
     1.1 --- a/default.conf	Wed Oct 03 13:43:18 2018 +0200
     1.2 +++ b/default.conf	Thu Oct 04 07:10:08 2018 +0200
     1.3 @@ -238,6 +238,16 @@
     1.4  #NETPGP_INC=-I$(PREFIX)/include
     1.5  
     1.6  
     1.7 +######### OpenPGP #########
     1.8 +# CppUnit library search flag
     1.9 +CPPUNIT_LIB=
    1.10 +#CPPUNIT_LIB=-L$(HOME)/local/lib
    1.11 +
    1.12 +# CppUnit include search flag
    1.13 +CPPUNIT_INC=
    1.14 +#CPPUNIT_INC=-I$(HOME)/local/inc
    1.15 +
    1.16 +
    1.17  ######### Engine internals #########
    1.18  # C macros (not environment variables) that can be overridden:
    1.19  # DEFAULT_KEYSERVER - string with default keyserver
     2.1 --- a/src/cryptotech.h	Wed Oct 03 13:43:18 2018 +0200
     2.2 +++ b/src/cryptotech.h	Thu Oct 04 07:10:08 2018 +0200
     2.3 @@ -19,7 +19,8 @@
     2.4  typedef PEP_STATUS (*decrypt_and_verify_t)(
     2.5          PEP_SESSION session, const char *ctext, size_t csize,
     2.6          const char *dsigtext, size_t dsigsize,
     2.7 -        char **ptext, size_t *psize, stringlist_t **keylist
     2.8 +        char **ptext, size_t *psize, stringlist_t **keylist,
     2.9 +        char **filename_ptr 
    2.10      );
    2.11  
    2.12  typedef PEP_STATUS (*verify_text_t)(
     3.1 --- a/src/message_api.c	Wed Oct 03 13:43:18 2018 +0200
     3.2 +++ b/src/message_api.c	Thu Oct 04 07:10:08 2018 +0200
     3.3 @@ -1170,6 +1170,7 @@
     3.4          return false;
     3.5  
     3.6      const char* bare_filename_ptr = _get_resource_ptr_noown(blob->filename);
     3.7 +    bare_filename_ptr += strlen(bare_filename_ptr) - 15;
     3.8      if (strncmp(bare_filename_ptr, "PGPexch.htm.", 12) == 0) {
     3.9          if (strcmp(bare_filename_ptr + 11, ".pgp") == 0 ||
    3.10              strcmp(bare_filename_ptr + 11, ".asc") == 0)
    3.11 @@ -1455,7 +1456,8 @@
    3.12                                                          blob_value, blob_size,
    3.13                                                          NULL, 0,
    3.14                                                          &bl_ptext, &bl_psize, 
    3.15 -                                                        &bl_keylist);
    3.16 +                                                        &bl_keylist,
    3.17 +                                                        NULL);
    3.18                  free_stringlist(bl_keylist); // we don't care about key encryption as long as we decrypt
    3.19                  if (_status == PEP_DECRYPTED || _status == PEP_DECRYPTED_AND_VERIFIED) {
    3.20                      free_blobval = true;
    3.21 @@ -2700,7 +2702,8 @@
    3.22          free_stringlist(*keylist);
    3.23          *decrypt_status = decrypt_and_verify(session, ctext, csize,
    3.24                                               NULL, 0,
    3.25 -                                             &ptext, &psize, keylist);
    3.26 +                                             &ptext, &psize, keylist,
    3.27 +                                             NULL);
    3.28          
    3.29      }
    3.30  
    3.31 @@ -2750,9 +2753,12 @@
    3.32              free(ptext);
    3.33              ptext = NULL;
    3.34  
    3.35 +            char* pgp_filename = NULL;
    3.36              status = decrypt_and_verify(session, attctext, attcsize,
    3.37                                          NULL, 0,
    3.38 -                                        &ptext, &psize, &_keylist);
    3.39 +                                        &ptext, &psize, &_keylist,
    3.40 +                                        &pgp_filename);
    3.41 +                                        
    3.42              free_stringlist(_keylist);
    3.43  
    3.44              if (ptext) {
    3.45 @@ -2762,17 +2768,25 @@
    3.46                  }
    3.47                  else {
    3.48                      static const char * const mime_type = "application/octet-stream";
    3.49 -                    char * const filename =
    3.50 -                        without_double_ending(_s->filename);
    3.51 -                    if (filename == NULL)
    3.52 -                        return PEP_OUT_OF_MEMORY;
    3.53 -
    3.54 -                    _m = bloblist_add(_m, ptext, psize, mime_type,
    3.55 -                        filename);
    3.56 -                    free(filename);
    3.57 -                    if (_m == NULL)
    3.58 -                        return PEP_OUT_OF_MEMORY;
    3.59 -
    3.60 +                    if (pgp_filename) {
    3.61 +                        _m = bloblist_add(_m, ptext, psize, mime_type,
    3.62 +                             pgp_filename);
    3.63 +                        free(pgp_filename);                        
    3.64 +                        if (_m == NULL)
    3.65 +                            return PEP_OUT_OF_MEMORY;
    3.66 +                    }
    3.67 +                    else {
    3.68 +                        char * const filename =
    3.69 +                            without_double_ending(_s->filename);
    3.70 +                        if (filename == NULL)
    3.71 +                            return PEP_OUT_OF_MEMORY;
    3.72 +
    3.73 +                        _m = bloblist_add(_m, ptext, psize, mime_type,
    3.74 +                            filename);
    3.75 +                        free(filename);
    3.76 +                        if (_m == NULL)
    3.77 +                            return PEP_OUT_OF_MEMORY;
    3.78 +                    }
    3.79                      ptext = NULL;
    3.80  
    3.81                      if (msg->attachments == NULL)
    3.82 @@ -2801,6 +2815,7 @@
    3.83                  return PEP_OUT_OF_MEMORY;
    3.84          }
    3.85      }
    3.86 +
    3.87      return status;
    3.88  }
    3.89  
    3.90 @@ -3195,7 +3210,8 @@
    3.91      /** Ok, we should be ready to decrypt. Try decrypt and verify first! **/
    3.92      status = cryptotech[crypto].decrypt_and_verify(session, ctext,
    3.93                                                     csize, dsig_text, dsig_size,
    3.94 -                                                   &ptext, &psize, &_keylist);
    3.95 +                                                   &ptext, &psize, &_keylist,
    3.96 +                                                   NULL);
    3.97  
    3.98      if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
    3.99          goto pep_error;
     4.1 --- a/src/pEpEngine.c	Wed Oct 03 13:43:18 2018 +0200
     4.2 +++ b/src/pEpEngine.c	Thu Oct 04 07:10:08 2018 +0200
     4.3 @@ -3478,7 +3478,8 @@
     4.4  DYNAMIC_API PEP_STATUS decrypt_and_verify(
     4.5      PEP_SESSION session, const char *ctext, size_t csize,
     4.6      const char *dsigtext, size_t dsigsize,
     4.7 -    char **ptext, size_t *psize, stringlist_t **keylist
     4.8 +    char **ptext, size_t *psize, stringlist_t **keylist,
     4.9 +    char** filename_ptr
    4.10      )
    4.11  {
    4.12      assert(session);
    4.13 @@ -3492,7 +3493,8 @@
    4.14          return PEP_ILLEGAL_VALUE;
    4.15  
    4.16      return session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(
    4.17 -            session, ctext, csize, dsigtext, dsigsize, ptext, psize, keylist);
    4.18 +            session, ctext, csize, dsigtext, dsigsize, ptext, psize, keylist,
    4.19 +            filename_ptr);
    4.20  }
    4.21  
    4.22  DYNAMIC_API PEP_STATUS encrypt_and_sign(
     5.1 --- a/src/pEpEngine.h	Wed Oct 03 13:43:18 2018 +0200
     5.2 +++ b/src/pEpEngine.h	Thu Oct 04 07:10:08 2018 +0200
     5.3 @@ -232,16 +232,20 @@
     5.4  // decrypt_and_verify() - decrypt and/or verify a message
     5.5  //
     5.6  //    parameters:
     5.7 -//        session (in)    session handle
     5.8 -//        ctext (in)      cipher text to decrypt and/or verify
     5.9 -//        csize (in)      size of cipher text
    5.10 -//        dsigtext (in)   if extant, *detached* signature text for this
    5.11 -//                        message (or NULL if not)
    5.12 -//        dsize (in)      size of *detached* signature text for this
    5.13 -//                        message (0, if no detached sig exists)
    5.14 -//        ptext (out)     pointer to internal buffer with plain text
    5.15 -//        psize (out)     size of plain text
    5.16 -//        keylist (out)   list of key ids which where used to encrypt
    5.17 +//        session (in)          session handle
    5.18 +//        ctext (in)            cipher text to decrypt and/or verify
    5.19 +//        csize (in)            size of cipher text
    5.20 +//        dsigtext (in)         if extant, *detached* signature text for this
    5.21 +//                              message (or NULL if not)
    5.22 +//        dsize (in)            size of *detached* signature text for this
    5.23 +//                              message (0, if no detached sig exists)
    5.24 +//        ptext (out)           pointer to internal buffer with plain text
    5.25 +//        psize (out)           size of plain text
    5.26 +//        keylist (out)         list of key ids which where used to encrypt
    5.27 +//        filename_ptr (out)    mails produced by certain PGP implementations 
    5.28 +//                              may return a decrypted filename here for attachments. 
    5.29 +//                              Externally, this can generally be NULL, and is an optional
    5.30 +//                              parameter.
    5.31  //
    5.32  //    return value:
    5.33  //        PEP_UNENCRYPTED               message was unencrypted and not signed
    5.34 @@ -263,7 +267,8 @@
    5.35  DYNAMIC_API PEP_STATUS decrypt_and_verify(
    5.36          PEP_SESSION session, const char *ctext, size_t csize,
    5.37          const char *dsigtext, size_t dsigsize,
    5.38 -        char **ptext, size_t *psize, stringlist_t **keylist
    5.39 +        char **ptext, size_t *psize, stringlist_t **keylist,
    5.40 +        char ** filename_ptr
    5.41      );
    5.42  
    5.43  
     6.1 --- a/src/pgp_gpg.c	Wed Oct 03 13:43:18 2018 +0200
     6.2 +++ b/src/pgp_gpg.c	Thu Oct 04 07:10:08 2018 +0200
     6.3 @@ -577,7 +577,8 @@
     6.4  PEP_STATUS pgp_decrypt_and_verify(
     6.5      PEP_SESSION session, const char *ctext, size_t csize,
     6.6      const char *dsigtext, size_t dsigsize,
     6.7 -    char **ptext, size_t *psize, stringlist_t **keylist
     6.8 +    char **ptext, size_t *psize, stringlist_t **keylist,
     6.9 +    char** filename_ptr
    6.10      )
    6.11  {
    6.12      PEP_STATUS result;
    6.13 @@ -693,6 +694,15 @@
    6.14                          *keylist = NULL;
    6.15                          result = PEP_OUT_OF_MEMORY;
    6.16                      }
    6.17 +                    // Get filename, if desired
    6.18 +                    if (filename_ptr) {
    6.19 +                        const char* fname = gpgme_decrypt_result->file_name;
    6.20 +                        if (fname) {
    6.21 +                            *filename_ptr = strdup(fname);
    6.22 +                            if (!(*filename_ptr))
    6.23 +                                result = PEP_OUT_OF_MEMORY;
    6.24 +                        }
    6.25 +                    }
    6.26                  } /* Ok, so now we have any recipients it was encrypted for
    6.27                       in recipient_keylist */
    6.28              
    6.29 @@ -811,7 +821,7 @@
    6.30                          }
    6.31                          case GPG_ERR_CERT_REVOKED:
    6.32                          case GPG_ERR_BAD_SIGNATURE:
    6.33 -			    result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    6.34 +                            result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    6.35                              //result = PEP_DECRYPT_BAD_SIGNATURE;
    6.36                              break;
    6.37                          case GPG_ERR_SIG_EXPIRED:
     7.1 --- a/src/pgp_gpg.h	Wed Oct 03 13:43:18 2018 +0200
     7.2 +++ b/src/pgp_gpg.h	Thu Oct 04 07:10:08 2018 +0200
     7.3 @@ -11,7 +11,8 @@
     7.4  PEP_STATUS pgp_decrypt_and_verify(
     7.5          PEP_SESSION session, const char *ctext, size_t csize,
     7.6          const char *dsigtext, size_t dsigsize,
     7.7 -        char **ptext, size_t *psize, stringlist_t **keylist
     7.8 +        char **ptext, size_t *psize, stringlist_t **keylist,
     7.9 +        char** filename_ptr
    7.10      );
    7.11  
    7.12  PEP_STATUS pgp_encrypt_and_sign(
     8.1 --- a/src/pgp_netpgp.c	Wed Oct 03 13:43:18 2018 +0200
     8.2 +++ b/src/pgp_netpgp.c	Thu Oct 04 07:10:08 2018 +0200
     8.3 @@ -373,7 +373,8 @@
     8.4  PEP_STATUS pgp_decrypt_and_verify(
     8.5      PEP_SESSION session, const char *ctext, size_t csize,
     8.6      const char *dsigtext, size_t dsigsize,
     8.7 -    char **ptext, size_t *psize, stringlist_t **keylist
     8.8 +    char **ptext, size_t *psize, stringlist_t **keylist,
     8.9 +    char** filename_ptr // will be ignored
    8.10      )
    8.11  {
    8.12      char *_ptext = NULL;
     9.1 --- a/src/pgp_netpgp.h	Wed Oct 03 13:43:18 2018 +0200
     9.2 +++ b/src/pgp_netpgp.h	Thu Oct 04 07:10:08 2018 +0200
     9.3 @@ -10,7 +10,8 @@
     9.4  PEP_STATUS pgp_decrypt_and_verify(
     9.5          PEP_SESSION session, const char *ctext, size_t csize,
     9.6          const char *dsigtext, size_t dsigsize,
     9.7 -        char **ptext, size_t *psize, stringlist_t **keylist
     9.8 +        char **ptext, size_t *psize, stringlist_t **keylist,
     9.9 +        char** filename_ptr // will be ignored
    9.10      );
    9.11  
    9.12  PEP_STATUS pgp_encrypt_and_sign(
    10.1 --- a/test/Makefile	Wed Oct 03 13:43:18 2018 +0200
    10.2 +++ b/test/Makefile	Thu Oct 04 07:10:08 2018 +0200
    10.3 @@ -18,14 +18,14 @@
    10.4  DEPS := $(OBJS:.o=.d)
    10.5  
    10.6  INC_DIRS := ./include /usr/local/include 
    10.7 -INC_FLAGS := $(addprefix -I,$(INC_DIRS)) $(GPGME_INC)
    10.8 +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) $(GPGME_INC) $(CPPUNIT_INC)
    10.9  
   10.10  LDFLAGS += -L/usr/local/lib
   10.11  
   10.12  CFLAGS += -Wno-deprecated
   10.13  CXXFLAGS += -Wno-deprecated
   10.14  
   10.15 -LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
   10.16 +LDFLAGS+= $(ETPAN_LIB) $(CPPUNIT_LIB) -L../asn.1 -L../src
   10.17  LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
   10.18  
   10.19  ifeq ($(BUILD_FOR),Linux)