Merged in default ENGINE-427
authorKrista Bennett <krista@pep-project.org>
Wed, 27 Jun 2018 16:55:55 +0200
branchENGINE-427
changeset 2776003ce543c234
parent 2773 0bca1887355e
parent 2775 a513ca50bcd9
child 2777 d0a7c4766c0a
Merged in default
src/pEpEngine.h
     1.1 --- a/src/message_api.c	Wed Jun 27 16:42:07 2018 +0200
     1.2 +++ b/src/message_api.c	Wed Jun 27 16:55:55 2018 +0200
     1.3 @@ -148,6 +148,43 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +bool _memnmemn(const char* needle, 
     1.8 +                size_t needle_size,
     1.9 +                const char* haystack, 
    1.10 +                size_t haystack_size) 
    1.11 +{
    1.12 +    if (needle_size > haystack_size) {
    1.13 +        return false;
    1.14 +    }
    1.15 +    else if (needle_size == 0) {
    1.16 +        return true;
    1.17 +    }
    1.18 +                        
    1.19 +    bool found = true;
    1.20 +    const char* haystack_ptr = haystack;
    1.21 +    unsigned int i = 0;
    1.22 +    size_t remaining_hay = haystack_size;
    1.23 +    for (i = 0; i < haystack_size && (remaining_hay >= needle_size); i++, haystack_ptr++) {
    1.24 +        found = false;
    1.25 +        const char* needle_ptr = needle;
    1.26 +        if (*haystack_ptr == *needle) {
    1.27 +            const char* haystack_tmp = haystack_ptr;
    1.28 +            unsigned int j;
    1.29 +            found = true;
    1.30 +            for (j = 0; j < needle_size; j++) {
    1.31 +                if (*needle_ptr++ != *haystack_tmp++) {
    1.32 +                    found = false;
    1.33 +                    break;
    1.34 +                }
    1.35 +            }
    1.36 +            if (found)
    1.37 +                break;
    1.38 +        }
    1.39 +        remaining_hay--;
    1.40 +    }
    1.41 +    return found;
    1.42 +}
    1.43 +
    1.44  void add_opt_field(message *msg, const char *name, const char *value)
    1.45  {
    1.46      assert(msg && name && value);
    1.47 @@ -1103,18 +1140,18 @@
    1.48          return false;
    1.49  
    1.50      if (strcmp(blob->mime_type, "application/octet-stream") == 0) {
    1.51 -        if (strcmp(ext, ".pgp") == 0 || strcmp(ext, ".gpg") == 0 ||
    1.52 -            strcmp(ext, ".asc") == 0)
    1.53 +        if (strcmp(ext, ".pgp") == 0 || strcmp(ext, ".gpg") == 0)
    1.54              return true;
    1.55      }
    1.56 -    else if (strcmp(blob->mime_type, "text/plain") == 0) {
    1.57 -        if (strcmp(ext, ".asc") == 0) {
    1.58 -            // NOTE: if this ends up being too expensive, we can implement
    1.59 -            // strnstr...
    1.60 -            if (strstr(blob->value, "BEGIN PGP PUBLIC KEY") == NULL &&
    1.61 -                strstr(blob->value, "BEGIN PGP PRIVATE KEY") == NULL)
    1.62 -                return true;
    1.63 -        }
    1.64 +    if (strcmp(ext, ".asc") == 0 && blob->size > 0) {            
    1.65 +        const char* pubk_needle = "BEGIN PGP PUBLIC KEY";
    1.66 +        size_t pubk_needle_size = strlen(pubk_needle);
    1.67 +        const char* privk_needle = "BEGIN PGP PRIVATE KEY";
    1.68 +        size_t privk_needle_size = strlen(privk_needle);
    1.69 +
    1.70 +        if (!(_memnmemn(pubk_needle, pubk_needle_size, blob->value, blob->size)) &&
    1.71 +            !(_memnmemn(privk_needle, privk_needle_size, blob->value, blob->size)))
    1.72 +            return true;
    1.73      }
    1.74  
    1.75      return false;
    1.76 @@ -1365,9 +1402,7 @@
    1.77              size_t blob_size = bl->size;
    1.78              bool free_blobval = false;
    1.79              
    1.80 -            if (is_encrypted_attachment(bl) &&
    1.81 -                    strstr(blob_value, "BEGIN PGP PUBLIC KEY") == NULL &&
    1.82 -                    strstr(blob_value, "BEGIN PGP PRIVATE KEY") == NULL) {
    1.83 +            if (is_encrypted_attachment(bl)) {
    1.84                      
    1.85                  char* bl_ptext = NULL;
    1.86                  size_t bl_psize = 0;
    1.87 @@ -1549,6 +1584,8 @@
    1.88      if (src->enc_format != PEP_enc_none)
    1.89          return PEP_ILLEGAL_VALUE;
    1.90  
    1.91 +    bool force_v_1 = flags & PEP_encrypt_flag_force_version_1;
    1.92 +    
    1.93      *dst = NULL;
    1.94  
    1.95      if (src->from && (!src->from->user_id || src->from->user_id[0] == '\0')) {
    1.96 @@ -1766,7 +1803,7 @@
    1.97      }
    1.98      else {
    1.99          // FIXME - we need to deal with transport types (via flag)
   1.100 -        if ((max_comm_type | PEP_ct_confirmed) == PEP_ct_pEp) {
   1.101 +        if ((!force_v_1) && ((max_comm_type | PEP_ct_confirmed) == PEP_ct_pEp)) {
   1.102              _src = wrap_message_as_attachment(NULL, src, false);
   1.103              if (!_src)
   1.104                  goto pep_error;
   1.105 @@ -2011,7 +2048,7 @@
   1.106      }
   1.107              
   1.108      // Ok, it's in there. Let's do this.        
   1.109 -    status = encrypt_message(session, src, keys, dst, enc_format, 0);
   1.110 +    status = encrypt_message(session, src, keys, dst, enc_format, flags);
   1.111      
   1.112      // Delete what we added to src
   1.113      free_bloblist(created_bl);
     2.1 --- a/src/message_api.h	Wed Jun 27 16:42:07 2018 +0200
     2.2 +++ b/src/message_api.h	Wed Jun 27 16:55:55 2018 +0200
     2.3 @@ -37,7 +37,11 @@
     2.4      
     2.5      // This is used for outer messages (used to wrap the real message)
     2.6      // This is only used internally and (eventually) by transport functions
     2.7 -    PEP_encrypt_flag_inner_message = 0x8
     2.8 +    PEP_encrypt_flag_inner_message = 0x8,
     2.9 +    
    2.10 +    // This is mainly used by pEp clients to send private keys to 
    2.11 +    // their own PGP-only device
    2.12 +    PEP_encrypt_flag_force_version_1 = 0x16
    2.13      
    2.14  } PEP_encrypt_flags; 
    2.15  
     3.1 --- a/src/pEpEngine.h	Wed Jun 27 16:42:07 2018 +0200
     3.2 +++ b/src/pEpEngine.h	Wed Jun 27 16:55:55 2018 +0200
     3.3 @@ -300,9 +300,9 @@
     3.4  //
     3.5  //    return value:
     3.6  //        PEP_STATUS_OK = 0            encryption and signing succeeded
     3.7 -//        PEP_KEY_NOT_FOUND            at least one of the receipient keys
     3.8 +//        PEP_KEY_NOT_FOUND            at least one of the recipient keys
     3.9  //                                     could not be found
    3.10 -//        PEP_KEY_HAS_AMBIG_NAME       at least one of the receipient keys has
    3.11 +//        PEP_KEY_HAS_AMBIG_NAME       at least one of the recipient keys has
    3.12  //                                     an ambiguous name
    3.13  //        PEP_GET_KEY_FAILED           cannot retrieve key
    3.14  //
    3.15 @@ -462,7 +462,7 @@
    3.16      PEP_ct_confirmed_encryption = 0x90,         // generic
    3.17      PEP_ct_OpenPGP_weak = 0x91,                 // RSA 1024 is weak (unused)
    3.18  
    3.19 -    PEP_ct_to_be_checked_confirmed = 0xa0,      //generic
    3.20 +    PEP_ct_to_be_checked_confirmed = 0xa0,      // generic
    3.21      PEP_ct_SMIME = 0xa1,
    3.22      PEP_ct_CMS = 0xa2,
    3.23  
     4.1 Binary file test/test_files/427_old_db has changed