src/message_api.c
branchENGINE-423
changeset 2615 5cd3625e0d91
parent 2614 3ea0f7f89ac3
child 2616 13e9725995f2
     1.1 --- a/src/message_api.c	Thu Apr 19 09:38:52 2018 +0200
     1.2 +++ b/src/message_api.c	Thu Apr 19 16:03:44 2018 +0200
     1.3 @@ -2041,7 +2041,7 @@
     1.4          if (status != PEP_STATUS_OK)
     1.5              goto pep_error;
     1.6      }
     1.7 -    else if (!target_fpr)
     1.8 +    else if (!target_id->fpr)
     1.9          return PEP_ILLEGAL_VALUE;
    1.10      
    1.11      *dst = NULL;
    1.12 @@ -2892,7 +2892,7 @@
    1.13      PEP_STATUS status = key_revoked(session, fpr, &reject);
    1.14  
    1.15      if (!reject) {
    1.16 -        status = key_expired(session, fpr, &reject);
    1.17 +        status = key_expired(session, fpr, time(NULL), &reject);
    1.18          if (reject) {
    1.19              timestamp *ts = new_timestamp(time(NULL) + KEY_EXPIRE_DELTA);
    1.20              status = renew_key(session, fpr, ts);
    1.21 @@ -2910,12 +2910,11 @@
    1.22          return NULL;
    1.23          
    1.24      stringlist_t* kl_curr = keylist;
    1.25 -    char* retval = NULL;
    1.26      while (kl_curr) {
    1.27          char* fpr = kl_curr->value;
    1.28          
    1.29 -        if (is_own_trusted_private_fpr(fpr)) { 
    1.30 -            if (!reject_fpr(fpr))
    1.31 +        if (is_trusted_own_priv_fpr(session, own_id, fpr)) { 
    1.32 +            if (!reject_fpr(session, fpr))
    1.33                  return strdup(fpr);
    1.34          }
    1.35              
    1.36 @@ -2925,12 +2924,12 @@
    1.37      char* target_own_fpr = NULL;
    1.38      
    1.39      // Last shot...
    1.40 -    status = get_user_default_key(session, own_id, 
    1.41 -                                  &target_own_fpr);
    1.42 +    PEP_STATUS status = get_user_default_key(session, own_id, 
    1.43 +                                             &target_own_fpr);
    1.44  
    1.45      if (status == PEP_STATUS_OK && !EMPTYSTR(target_own_fpr)) {
    1.46 -        if (is_own_trusted_private_fpr(target_own_fpr)) { 
    1.47 -            if (!reject_fpr(target_own_fpr))
    1.48 +        if (is_trusted_own_priv_fpr(session, own_id, target_own_fpr)) { 
    1.49 +            if (!reject_fpr(session, target_own_fpr))
    1.50                  return target_own_fpr;
    1.51          }
    1.52      }
    1.53 @@ -2976,7 +2975,7 @@
    1.54      bool is_pep_msg = is_a_pEpmessage(src);
    1.55  
    1.56      // Grab input flags
    1.57 -    bool reencrypt = (*flags & PEP_decrypt_flag_untrusted_server > 0);
    1.58 +    bool reencrypt = ((*flags & PEP_decrypt_flag_untrusted_server) > 0);
    1.59      
    1.60      // We own this pointer, and we take control of *keylist if reencrypting.
    1.61      stringlist_t* extra = NULL;
    1.62 @@ -3326,6 +3325,7 @@
    1.63  
    1.64      *dst = msg;
    1.65      *keylist = _keylist;
    1.66 +    message* reencrypt_msg;
    1.67  
    1.68      if (reencrypt) {
    1.69          if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.70 @@ -3337,28 +3337,30 @@
    1.71                                                                       own_id,
    1.72                                                                       _keylist);
    1.73                  if (target_own_fpr) {
    1.74 -                    pEp_identity* target_id = new_identity(NULL, own_id, 
    1.75 -                                                           target_own_fpr, NULL);
    1.76 +                    pEp_identity* target_id = new_identity(NULL, target_own_fpr, 
    1.77 +                                                           own_id, NULL);
    1.78                      if (target_id) {
    1.79                          *dst = NULL;
    1.80                          reencrypt_status = encrypt_message_for_self(session, target_id, msg,
    1.81 -                                                                    extra, dst, PEP_enc_PGP_MIME,
    1.82 +                                                                    extra, &reencrypt_msg, PEP_enc_PGP_MIME,
    1.83                                                                      0);
    1.84                          if (reencrypt_status != PEP_STATUS_OK)
    1.85                              reencrypt_status = PEP_CANNOT_REENCRYPT;
    1.86 -                            
    1.87 +                        
    1.88                          free_identity(target_id);
    1.89                      }
    1.90                      free(target_own_fpr);
    1.91                  }     
    1.92                  free(own_id);
    1.93              }
    1.94 -        }
    1.95 -        free_stringlist(extra); // This was an input variable for us. Keylist is overwritten above.
    1.96 -        if (reencrypt_status == PEP_CANNOT_REENCRYPT)
    1.97 -            decrypt_status = reencrypt_status;
    1.98 -        else {
    1.99 -            // Copy msg into src
   1.100 +            free_stringlist(extra); // This was an input variable for us. Keylist is overwritten above.
   1.101 +            
   1.102 +            if (reencrypt_status != PEP_CANNOT_REENCRYPT && reencrypt_msg) {
   1.103 +                message_transfer(src, reencrypt_msg);
   1.104 +                free_message(reencrypt_msg);
   1.105 +            }
   1.106 +            else
   1.107 +                decrypt_status = PEP_CANNOT_REENCRYPT;
   1.108          }
   1.109      }
   1.110