ENGINE-633 commit merged - was actually 630, but this is a subtask ENGINE-630
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 20 Sep 2019 11:29:33 +0200
branchENGINE-630
changeset 40725d367773c44f
parent 4065 7f0cf93bc2af
parent 4071 68f242584e18
child 4073 3d6b760e5c11
ENGINE-633 commit merged - was actually 630, but this is a subtask
     1.1 --- a/src/message_api.c	Tue Sep 10 15:04:36 2019 +0200
     1.2 +++ b/src/message_api.c	Fri Sep 20 11:29:33 2019 +0200
     1.3 @@ -33,6 +33,7 @@
     1.4      return false;
     1.5  }
     1.6  
     1.7 +
     1.8  static char * keylist_to_string(const stringlist_t *keylist)
     1.9  {
    1.10      if (keylist) {
    1.11 @@ -1435,7 +1436,8 @@
    1.12  bool import_attached_keys(
    1.13          PEP_SESSION session,
    1.14          message *msg,
    1.15 -        identity_list **private_idents
    1.16 +        identity_list **private_idents,
    1.17 +        stringlist_t **imported_fprs
    1.18      )
    1.19  {
    1.20      assert(session);
    1.21 @@ -1496,7 +1498,7 @@
    1.22                  }
    1.23              }
    1.24              identity_list *local_private_idents = NULL;
    1.25 -            PEP_STATUS import_status = import_key(session, blob_value, blob_size, &local_private_idents);
    1.26 +            PEP_STATUS import_status = _import_key_with_fpr_return(session, blob_value, blob_size, &local_private_idents, imported_fprs);
    1.27              bloblist_t* to_delete = NULL;
    1.28              switch (import_status) {
    1.29                  case PEP_NO_KEY_IMPORTED:
    1.30 @@ -2956,11 +2958,12 @@
    1.31      return status;
    1.32  }
    1.33  
    1.34 -static PEP_STATUS import_priv_keys_from_decrypted_msg(PEP_SESSION session,
    1.35 +static PEP_STATUS import_keys_from_decrypted_msg(PEP_SESSION session,
    1.36                                                        message* msg,
    1.37                                                        bool* imported_keys,
    1.38                                                        bool* imported_private,
    1.39 -                                                      identity_list** private_il)
    1.40 +                                                      identity_list** private_il,
    1.41 +                                                      stringlist_t** imported_fprs)
    1.42  {
    1.43      assert(msg && imported_keys && imported_private);
    1.44      if (!(msg && imported_keys && imported_private))
    1.45 @@ -2975,7 +2978,7 @@
    1.46      // check for private key in decrypted message attachment while importing
    1.47      identity_list *_private_il = NULL;
    1.48  
    1.49 -    bool _imported_keys = import_attached_keys(session, msg, &_private_il);
    1.50 +    bool _imported_keys = import_attached_keys(session, msg, &_private_il, imported_fprs);
    1.51      bool _imported_private = false;
    1.52      if (_private_il && _private_il->ident && _private_il->ident->address)
    1.53          _imported_private = true;
    1.54 @@ -3272,7 +3275,7 @@
    1.55      return NULL;
    1.56  }
    1.57  
    1.58 -static bool import_header_keys(PEP_SESSION session, message* src) {
    1.59 +static bool import_header_keys(PEP_SESSION session, message* src, stringlist_t** imported_fprs) {
    1.60      stringpair_list_t* header_keys = stringpair_list_find(src->opt_fields, "Autocrypt"); 
    1.61      if (!header_keys || !header_keys->value)
    1.62          return false;
    1.63 @@ -3287,7 +3290,7 @@
    1.64      bloblist_t* the_key = base64_str_to_binary_blob(start_key, length);
    1.65      if (!the_key)
    1.66          return false;
    1.67 -    PEP_STATUS status = import_key(session, the_key->value, the_key->size, NULL);
    1.68 +    PEP_STATUS status = _import_key_with_fpr_return(session, the_key->value, the_key->size, NULL, imported_fprs);
    1.69      free_bloblist(the_key);
    1.70      if (status == PEP_STATUS_OK || status == PEP_KEY_IMPORTED)
    1.71          return true;
    1.72 @@ -3387,6 +3390,7 @@
    1.73      message* msg = NULL;
    1.74      message* calculated_src = src;
    1.75      message* reset_msg = NULL;
    1.76 +    stringlist_t* imported_fprs = NULL;
    1.77      
    1.78      char *ctext;
    1.79      size_t csize;
    1.80 @@ -3452,9 +3456,9 @@
    1.81      bool imported_keys = false;
    1.82      PEP_cryptotech enc_type = determine_encryption_format(src);
    1.83      if (enc_type != PEP_crypt_OpenPGP || !(src->enc_format == PEP_enc_PGP_MIME || src->enc_format == PEP_enc_PGP_MIME_Outlook1))
    1.84 -        imported_keys = import_attached_keys(session, src, NULL);
    1.85 +        imported_keys = import_attached_keys(session, src, NULL, &imported_fprs);
    1.86              
    1.87 -    import_header_keys(session, src);
    1.88 +    bool had_header_key = import_header_keys(session, src, &imported_fprs);
    1.89      
    1.90      // FIXME: is this really necessary here?
    1.91      // if (src->from) {
    1.92 @@ -3546,10 +3550,11 @@
    1.93                  //
    1.94                  // We are importing from the decrypted outermost message now.
    1.95                  //
    1.96 -                status = import_priv_keys_from_decrypted_msg(session, msg,
    1.97 -                                                             &imported_keys,
    1.98 -                                                             &imported_private_key_address,
    1.99 -                                                             private_il);
   1.100 +                status = import_keys_from_decrypted_msg(session, msg,
   1.101 +                                                         &imported_keys,
   1.102 +                                                         &imported_private_key_address,
   1.103 +                                                         private_il,
   1.104 +                                                         &imported_fprs);
   1.105                  if (status != PEP_STATUS_OK)
   1.106                      goto pEp_error;            
   1.107  
   1.108 @@ -3738,10 +3743,12 @@
   1.109                              private_il = NULL;
   1.110                              
   1.111                              // import keys from decrypted INNER source
   1.112 -                            status = import_priv_keys_from_decrypted_msg(session, inner_message,
   1.113 -                                                                         &imported_keys,
   1.114 -                                                                         &imported_private_key_address,
   1.115 -                                                                         private_il);
   1.116 +                            status = import_keys_from_decrypted_msg(session, inner_message,
   1.117 +                                                                     &imported_keys,
   1.118 +                                                                     &imported_private_key_address,
   1.119 +                                                                     private_il,
   1.120 +                                                                     &imported_fprs);
   1.121 +                                                                                                              
   1.122                              if (status != PEP_STATUS_OK)
   1.123                                  goto pEp_error;            
   1.124  
     2.1 --- a/src/message_api.h	Tue Sep 10 15:04:36 2019 +0200
     2.2 +++ b/src/message_api.h	Fri Sep 20 11:29:33 2019 +0200
     2.3 @@ -15,7 +15,8 @@
     2.4  bool import_attached_keys(
     2.5          PEP_SESSION session, 
     2.6          message *msg,
     2.7 -        identity_list **private_idents
     2.8 +        identity_list **private_idents,
     2.9 +        stringlist_t **imported_keys
    2.10      );
    2.11  
    2.12  void attach_own_key(PEP_SESSION session, message *msg);
     3.1 --- a/src/pEpEngine.c	Tue Sep 10 15:04:36 2019 +0200
     3.2 +++ b/src/pEpEngine.c	Fri Sep 20 11:29:33 2019 +0200
     3.3 @@ -4543,7 +4543,7 @@
     3.4          PEP_SESSION session,
     3.5          const char *key_data,
     3.6          size_t size,
     3.7 -        identity_list **private_idents
     3.8 +        identity_list **private_keys
     3.9      )
    3.10  {
    3.11      assert(session);
    3.12 @@ -4552,26 +4552,22 @@
    3.13      if (!(session && key_data))
    3.14          return PEP_ILLEGAL_VALUE;
    3.15  
    3.16 -    return _import_key_with_fpr_return(session, key_data,
    3.17 -            size, private_idents, NULL);
    3.18 +    return session->cryptotech[PEP_crypt_OpenPGP]._import_key_with_fpr_return(
    3.19 +                                                        session, key_data,
    3.20 +                                                        size, private_keys, NULL);
    3.21  }
    3.22  
    3.23  PEP_STATUS _import_key_with_fpr_return(
    3.24          PEP_SESSION session,
    3.25          const char *key_data,
    3.26          size_t size,
    3.27 -        identity_list **private_idents,
    3.28 +        identity_list **private_keys,
    3.29          stringlist_t** imported_keys
    3.30      )
    3.31  {
    3.32 -    assert(session);
    3.33 -    assert(key_data);
    3.34 -
    3.35 -    if (!(session && key_data))
    3.36 -        return PEP_ILLEGAL_VALUE;
    3.37 -
    3.38 -    return session->cryptotech[PEP_crypt_OpenPGP]._import_key_with_fpr_return(session, key_data,
    3.39 -            size, private_idents, imported_keys);    
    3.40 +    return session->cryptotech[PEP_crypt_OpenPGP]._import_key_with_fpr_return(
    3.41 +                                                        session, key_data,
    3.42 +                                                        size, private_keys, imported_keys);    
    3.43  }    
    3.44  
    3.45  DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
     4.1 --- a/src/pgp_gpg.c	Tue Sep 10 15:04:36 2019 +0200
     4.2 +++ b/src/pgp_gpg.c	Fri Sep 20 11:29:33 2019 +0200
     4.3 @@ -1542,12 +1542,13 @@
     4.4                         gpgme_import_result->new_sub_keys |
     4.5                         gpgme_import_result->new_revocations |
     4.6                         gpgme_import_result->new_signatures;
     4.7 +
     4.8 +        identity_list** identcurr_pp = private_idents;
     4.9 +        stringlist_t** keylist_pp = advance_to_end(imported_keys);
    4.10              
    4.11 -        if(private_idents || imported_keys)
    4.12 +        if(identcurr_pp || keylist_pp)
    4.13          {
    4.14              gpgme_import_status_t import;
    4.15 -            identity_list** identcurr_pp = private_idents;
    4.16 -            stringlist_t** keylist_pp = imported_keys;
    4.17              for (import = gpgme_import_result->imports;
    4.18                   import;
    4.19                   import = import->next)
     5.1 --- a/src/stringlist.c	Tue Sep 10 15:04:36 2019 +0200
     5.2 +++ b/src/stringlist.c	Fri Sep 20 11:29:33 2019 +0200
     5.3 @@ -285,3 +285,15 @@
     5.4          curr = next;
     5.5      }
     5.6  }
     5.7 +
     5.8 +stringlist_t** advance_to_end(stringlist_t** head_pp) {
     5.9 +    if (!head_pp)
    5.10 +        return NULL;
    5.11 +    
    5.12 +    stringlist_t** retval = head_pp;
    5.13 +    
    5.14 +    while (*retval) {
    5.15 +        retval = &((*retval)->next);
    5.16 +    }    
    5.17 +    return retval;
    5.18 +}
     6.1 --- a/src/stringlist.h	Tue Sep 10 15:04:36 2019 +0200
     6.2 +++ b/src/stringlist.h	Fri Sep 20 11:29:33 2019 +0200
     6.3 @@ -134,6 +134,7 @@
     6.4  DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
     6.5  
     6.6  stringlist_t* stringlist_search(stringlist_t* head, const char* value);
     6.7 +stringlist_t** advance_to_end(stringlist_t** head_pp);
     6.8  
     6.9  void dedup_stringlist(stringlist_t* stringlist);
    6.10