ENGINE-649: maaaybe fixing up dirty semantic changes. ENGINE-649
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 30 Sep 2019 13:58:09 +0200
branchENGINE-649
changeset 409764497d6b69ad
parent 4096 ef291fbfa5c6
child 4098 627522e248e6
ENGINE-649: maaaybe fixing up dirty semantic changes.
src/message_api.c
src/message_api.h
     1.1 --- a/src/message_api.c	Fri Sep 27 14:26:09 2019 +0200
     1.2 +++ b/src/message_api.c	Mon Sep 30 13:58:09 2019 +0200
     1.3 @@ -2318,17 +2318,21 @@
     1.4      if (status != PEP_STATUS_OK)
     1.5          goto pEp_error;
     1.6  
     1.7 -    if (msg && msg->shortmsg == NULL) {
     1.8 -        if (session->unencrypted_subject && src->shortmsg)
     1.9 -            msg->shortmsg = strdup(src->shortmsg);
    1.10 -        else
    1.11 +    if (msg) {
    1.12 +        if (!src->shortmsg) {
    1.13 +            free(msg->shortmsg);
    1.14              msg->shortmsg = _pEp_subj_copy();
    1.15 -        assert(msg->shortmsg);
    1.16 -        if (msg->shortmsg == NULL)
    1.17 -            goto enomem;
    1.18 -    }
    1.19 -
    1.20 -    if (msg) {
    1.21 +            assert(msg->shortmsg);
    1.22 +            if (msg->shortmsg == NULL)
    1.23 +                goto enomem;
    1.24 +        }
    1.25 +        else {
    1.26 +            if (session->unencrypted_subject && (flags & PEP_encrypt_reencrypt)) {
    1.27 +                free(msg->shortmsg);
    1.28 +                msg->shortmsg = strdup(src->shortmsg);
    1.29 +            }    
    1.30 +        }
    1.31 +
    1.32          if (_src->id) {
    1.33              msg->id = strdup(_src->id);
    1.34              assert(msg->id);
    1.35 @@ -3935,17 +3939,14 @@
    1.36          }
    1.37      }
    1.38  
    1.39 -    // 4. Set up return values
    1.40 -    *dst = msg;
    1.41 -    *keylist = _keylist;
    1.42  
    1.43      bool reenc_signer_key_is_own_key = false; // only matters for reencrypted messages 
    1.44      
    1.45 -    // 5. Reencrypt if necessary
    1.46 +    // 4. Reencrypt if necessary
    1.47      if (reencrypt) {
    1.48          if (decrypt_status == PEP_DECRYPTED || decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.49              const char* sfpr = NULL;
    1.50 -            if (_have_extrakeys(*keylist))
    1.51 +            if (_have_extrakeys(extra))
    1.52                  sfpr = _keylist->value;
    1.53               
    1.54              if (sfpr && decrypt_status == PEP_DECRYPTED_AND_VERIFIED) {
    1.55 @@ -3966,7 +3967,7 @@
    1.56                              if (target_id) {
    1.57                                  reencrypt_status = encrypt_message_for_self(session, target_id, msg,
    1.58                                                                              extra, &reencrypt_msg, PEP_enc_PGP_MIME,
    1.59 -                                                                            0);
    1.60 +                                                                            PEP_encrypt_reencrypt);
    1.61                                  if (reencrypt_status != PEP_STATUS_OK)
    1.62                                      reencrypt_status = PEP_CANNOT_REENCRYPT;
    1.63                                  
    1.64 @@ -3987,7 +3988,7 @@
    1.65                          decrypt_status = PEP_CANNOT_REENCRYPT;
    1.66                  }
    1.67              }            
    1.68 -            else if (!_have_extrakeys(*keylist) && session->unencrypted_subject) {
    1.69 +            else if (!_have_extrakeys(extra) && session->unencrypted_subject) {
    1.70                  free(src->shortmsg);
    1.71                  src->shortmsg = strdup(msg->shortmsg);
    1.72                  assert(src->shortmsg);
    1.73 @@ -3998,6 +3999,10 @@
    1.74          }
    1.75      }
    1.76      
    1.77 +    // 5. Set up return values
    1.78 +    *dst = msg;
    1.79 +    *keylist = _keylist;
    1.80 +    
    1.81      // Double-check for message 2.1: (note, we don't do this for already-reencrypted-messages)
    1.82      if (!(reencrypt && reenc_signer_key_is_own_key)) { 
    1.83          if (major_ver > 2 || (major_ver == 2 && minor_ver > 0)) {
     2.1 --- a/src/message_api.h	Fri Sep 27 14:26:09 2019 +0200
     2.2 +++ b/src/message_api.h	Mon Sep 30 13:58:09 2019 +0200
     2.3 @@ -41,8 +41,12 @@
     2.4      // This is mainly used by pEp clients to send private keys to 
     2.5      // their own PGP-only device
     2.6      PEP_encrypt_flag_force_version_1 = 0x10,
     2.7 +        
     2.8 +    PEP_encrypt_flag_key_reset_only = 0x20,
     2.9      
    2.10 -    PEP_encrypt_flag_key_reset_only = 0x20
    2.11 +    // This flag is used to let internal functions know that an encryption 
    2.12 +    // call is being used as part of a reencryption operation
    2.13 +    PEP_encrypt_reencrypt = 0x40
    2.14      
    2.15  } PEP_encrypt_flags; 
    2.16