Fixing own_message_private_key_details, since decrypt does auto key removal now. (continued) import_own_key
authorEdouard Tisserant
Thu, 16 Jun 2016 10:50:43 +0200
branchimport_own_key
changeset 741548a07ff87b9
parent 740 3b1eacc35400
child 746 753b1ec63285
child 925 a02241302e39
Fixing own_message_private_key_details, since decrypt does auto key removal now. (continued)
src/message_api.c
     1.1 --- a/src/message_api.c	Thu Jun 16 10:02:51 2016 +0200
     1.2 +++ b/src/message_api.c	Thu Jun 16 10:50:43 2016 +0200
     1.3 @@ -1175,13 +1175,14 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 -DYNAMIC_API PEP_STATUS decrypt_message(
     1.8 +DYNAMIC_API PEP_STATUS _decrypt_message(
     1.9          PEP_SESSION session,
    1.10          message *src,
    1.11          message **dst,
    1.12          stringlist_t **keylist,
    1.13          PEP_color *color,
    1.14 -        PEP_decrypt_flags_t *flags 
    1.15 +        PEP_decrypt_flags_t *flags, 
    1.16 +        identity_list **private_il
    1.17      )
    1.18  {
    1.19      PEP_STATUS status = PEP_STATUS_OK;
    1.20 @@ -1246,7 +1247,7 @@
    1.21  
    1.22      decrypt_status = status;
    1.23  
    1.24 -    char *imported_private_key_address = NULL; 
    1.25 +    bool imported_private_key_address = false; 
    1.26  
    1.27      if (ptext) {
    1.28          switch (src->enc_format) {
    1.29 @@ -1382,16 +1383,20 @@
    1.30          }
    1.31         
    1.32          // check for private key in decrypted message attachement while inporting
    1.33 -        identity_list *private_il = NULL;
    1.34 -        imported_keys = import_attached_keys(session, msg, &private_il);
    1.35 -        if (private_il && 
    1.36 -            identity_list_length(private_il) == 1 &&
    1.37 -            private_il->ident->address)
    1.38 +        identity_list *_private_il = NULL;
    1.39 +        imported_keys = import_attached_keys(session, msg, &_private_il);
    1.40 +        if (_private_il && 
    1.41 +            identity_list_length(_private_il) == 1 &&
    1.42 +            _private_il->ident->address)
    1.43          {
    1.44 -            imported_private_key_address = 
    1.45 -                strdup(private_il->ident->address);
    1.46 +            imported_private_key_address = true;
    1.47          }
    1.48 -        free_identity_list(private_il);
    1.49 +
    1.50 +        if(private_il && imported_private_key_address){
    1.51 +            *private_il = _private_il;
    1.52 +        }else{
    1.53 +            free_identity_list(_private_il);
    1.54 +        }
    1.55           
    1.56          if(decrypt_status == PEP_DECRYPTED){
    1.57  
    1.58 @@ -1473,8 +1478,6 @@
    1.59          *flags |= PEP_decrypt_flag_own_private_key;
    1.60      }
    1.61  
    1.62 -    free(imported_private_key_address);
    1.63 -
    1.64      if (msg){
    1.65          decorate_message(msg, *color, _keylist);
    1.66          if (imported_keys)
    1.67 @@ -1490,20 +1493,30 @@
    1.68      status = PEP_OUT_OF_MEMORY;
    1.69  
    1.70  pep_error:
    1.71 -    free(imported_private_key_address);
    1.72      free_message(msg);
    1.73      free_stringlist(_keylist);
    1.74  
    1.75      return status;
    1.76  }
    1.77  
    1.78 +DYNAMIC_API PEP_STATUS decrypt_message(
    1.79 +        PEP_SESSION session,
    1.80 +        message *src,
    1.81 +        message **dst,
    1.82 +        stringlist_t **keylist,
    1.83 +        PEP_color *color,
    1.84 +        PEP_decrypt_flags_t *flags 
    1.85 +    )
    1.86 +{
    1.87 +    return _decrypt_message( session, src, dst, keylist, color, flags, NULL );
    1.88 +}
    1.89 +
    1.90  DYNAMIC_API PEP_STATUS own_message_private_key_details(
    1.91          PEP_SESSION session,
    1.92          message *msg,
    1.93          pEp_identity **ident 
    1.94      )
    1.95  {
    1.96 -    PEP_STATUS status = PEP_STATUS_OK;
    1.97      assert(session);
    1.98      assert(msg);
    1.99      assert(ident);
   1.100 @@ -1519,18 +1532,19 @@
   1.101      *ident = NULL;
   1.102  
   1.103      identity_list *private_il = NULL;
   1.104 -    import_attached_keys(session, msg, &private_il);
   1.105 -
   1.106 -    status = decrypt_message(session, msg,  &dst, &keylist, &color, &flags);
   1.107 +    PEP_STATUS status = _decrypt_message(session, msg,  &dst, &keylist, &color, &flags, &private_il);
   1.108  
   1.109      if (status == PEP_STATUS_OK &&
   1.110 -        flags & PEP_decrypt_flag_own_private_key)
   1.111 +        flags & PEP_decrypt_flag_own_private_key &&
   1.112 +        private_il)
   1.113      {
   1.114          *ident = identity_dup(private_il->ident);
   1.115 -        free_identity_list(private_il);
   1.116      }
   1.117  
   1.118 +    free_identity_list(private_il);
   1.119 +
   1.120      return status;
   1.121 +
   1.122  }
   1.123  
   1.124  DYNAMIC_API PEP_STATUS outgoing_message_color(