Merge with ENGINE-581 sequoia_windows
authorThomas
Tue, 25 Jun 2019 20:26:39 +0200
branchsequoia_windows
changeset 3876739c8e54b738
parent 3873 d020bf7cf4f8
parent 3875 01d0bda44169
child 3878 37426cf0d1fe
Merge with ENGINE-581
     1.1 --- a/src/message_api.c	Tue Jun 25 19:26:57 2019 +0200
     1.2 +++ b/src/message_api.c	Tue Jun 25 20:26:39 2019 +0200
     1.3 @@ -3328,98 +3328,6 @@
     1.4  
     1.5  }
     1.6  
     1.7 -static PEP_STATUS set_key_if_exists_and_no_default(
     1.8 -        PEP_SESSION session,
     1.9 -        pEp_identity* identity
    1.10 -    )
    1.11 -{
    1.12 -    // assert(session);
    1.13 -    // assert(identity);
    1.14 -    // assert(!(EMPTYSTR(identity->address) || EMPTYSTR(identity->user_id)));
    1.15 -    PEP_STATUS status = PEP_STATUS_OK;
    1.16 -    
    1.17 -    if (!session || !identity || EMPTYSTR(identity->address) || EMPTYSTR(identity->user_id))
    1.18 -        return PEP_ILLEGAL_VALUE;
    1.19 -
    1.20 -    if (is_me(session, identity))
    1.21 -        return PEP_STATUS_OK; // we won't set this, but it's not an error
    1.22 -        
    1.23 -    bool has_default = false;
    1.24 -    PEP_comm_type cached_ct = PEP_ct_unknown;
    1.25 -    char* cached_fpr = NULL;
    1.26 -    
    1.27 -    if (EMPTYSTR(identity->fpr)) {
    1.28 -        // OK, we may have imported one. Let's check it out.
    1.29 -        status = update_identity(session, identity);
    1.30 -        
    1.31 -        if (status != PEP_STATUS_OK)
    1.32 -            return status;
    1.33 -            
    1.34 -        if (EMPTYSTR(identity->fpr))
    1.35 -            return PEP_STATUS_OK; // ok, we've got nothing, bye!
    1.36 -        
    1.37 -        cached_ct = identity->comm_type;
    1.38 -    
    1.39 -        // see if we have trust info for this fpr
    1.40 -        status = get_trust(session, identity);
    1.41 -        
    1.42 -        if (status == PEP_CANNOT_FIND_IDENTITY) // nope, use update_ident info
    1.43 -            identity->comm_type = cached_ct;
    1.44 -        else {
    1.45 -            // there's already a trust entry for this fpr in the DB.
    1.46 -            // should be all good
    1.47 -            return PEP_STATUS_OK;
    1.48 -        }            
    1.49 -    }
    1.50 -    else {
    1.51 -        // See if there is a trust entry for the input fpr
    1.52 -        status = get_trust(session, identity);
    1.53 -    
    1.54 -        if (status == PEP_CANNOT_FIND_IDENTITY) {
    1.55 -            // there's no trust for this key/user
    1.56 -            // So: 
    1.57 -            // 1. find out if we have a default key at all 
    1.58 -            cached_fpr = identity->fpr;
    1.59 -            identity->fpr = NULL;
    1.60 -            status = update_identity(session, identity);
    1.61 -
    1.62 -            if (EMPTYSTR(identity->fpr)) {
    1.63 -                // We don't.
    1.64 -                has_default = false;
    1.65 -                identity->fpr = cached_fpr;
    1.66 -                cached_fpr = NULL;
    1.67 -                status = get_key_rating(session, identity->fpr, &(identity->comm_type));
    1.68 -                if (status != PEP_STATUS_OK)
    1.69 -                    goto pEp_free;
    1.70 -            }
    1.71 -            else if (strcasecmp(identity->fpr, cached_fpr) != 0) {
    1.72 -                // We do, but they don't match.
    1.73 -                // make sure identity->fpr has an entry
    1.74 -                cached_ct = identity->comm_type;
    1.75 -                status = get_trust(session, identity);
    1.76 -                if (status == PEP_CANNOT_FIND_IDENTITY)
    1.77 -                    identity->comm_type = cached_ct;    
    1.78 -                else {
    1.79 -                    status = PEP_STATUS_OK;
    1.80 -                    goto pEp_free;
    1.81 -                }                        
    1.82 -            }
    1.83 -        }
    1.84 -        else { 
    1.85 -            status = PEP_STATUS_OK;
    1.86 -            goto pEp_free;
    1.87 -        }    
    1.88 -    }
    1.89 -    
    1.90 -    // At this point, if there was a valid, set trust entry, we've returned.
    1.91 -    // there isn't, so:
    1.92 -    status = set_identity(session, identity);
    1.93 -    
    1.94 -pEp_free:
    1.95 -    free(cached_fpr);
    1.96 -    return status;
    1.97 -}    
    1.98 -
    1.99  static PEP_STATUS _decrypt_message(
   1.100          PEP_SESSION session,
   1.101          message *src,
   1.102 @@ -3514,6 +3422,7 @@
   1.103              
   1.104      import_header_keys(session, src);
   1.105      
   1.106 +    // FIXME: is this really necessary here?
   1.107      if (src->from) {
   1.108          if (!is_me(session, src->from))
   1.109              status = update_identity(session, src->from);
   1.110 @@ -3553,11 +3462,6 @@
   1.111                                      
   1.112          pull_up_attached_main_msg(src);
   1.113          
   1.114 -        //
   1.115 -        // We may have imported a key.
   1.116 -        //
   1.117 -        set_key_if_exists_and_no_default(session, src->from);
   1.118 -        
   1.119          return PEP_UNENCRYPTED;
   1.120      }
   1.121  
   1.122 @@ -3802,8 +3706,7 @@
   1.123              goto pEp_error;
   1.124          
   1.125          /* We decrypted ok, hallelujah. */
   1.126 -        msg->enc_format = PEP_enc_none;  
   1.127 -          
   1.128 +        msg->enc_format = PEP_enc_none;    
   1.129      } 
   1.130      else {
   1.131          // We did not get a plaintext out of the decryption process.
   1.132 @@ -3838,9 +3741,6 @@
   1.133      // 2. Clean up message and prepare for return 
   1.134      if (msg) {
   1.135          
   1.136 -        /* if the sender has no default and we have a key for them, set it. */
   1.137 -        set_key_if_exists_and_no_default(session, msg->from);
   1.138 -        
   1.139          /* add pEp-related status flags to header */
   1.140          decorate_message(msg, *rating, _keylist, false, false);
   1.141  
   1.142 @@ -4293,6 +4193,21 @@
   1.143      return PEP_color_no_color;
   1.144  }
   1.145  
   1.146 +DYNAMIC_API PEP_STATUS get_rating_from_bare_key(
   1.147 +        PEP_SESSION session, 
   1.148 +        const char* fpr,
   1.149 +        PEP_rating* rating
   1.150 +    )
   1.151 +{
   1.152 +    PEP_comm_type comm_type = PEP_ct_unknown;
   1.153 +    *rating = PEP_rating_undefined;
   1.154 +    PEP_STATUS status = get_key_rating(session, fpr, &comm_type);
   1.155 +    if (status == PEP_STATUS_OK)
   1.156 +        *rating = _rating(comm_type);
   1.157 +    
   1.158 +    return status;    
   1.159 +}
   1.160 +
   1.161  /* [0-9]: 0x30 - 0x39; [A-F] = 0x41 - 0x46; [a-f] = 0x61 - 0x66 */
   1.162  static short asciihex_to_num(char a) {
   1.163      short conv_num = -1;
     2.1 --- a/src/message_api.h	Tue Jun 25 19:26:57 2019 +0200
     2.2 +++ b/src/message_api.h	Tue Jun 25 20:26:39 2019 +0200
     2.3 @@ -507,6 +507,23 @@
     2.4          PEP_rating *rating
     2.5      );
     2.6  
     2.7 +// get_rating_from_bare_key() - get the rating of a certain key (instead of just the comm_type)
     2.8 +//
     2.9 +//  parameters:
    2.10 +//
    2.11 +//      session (in)            session handle
    2.12 +//      fpr (in)                string with fingerprint
    2.13 +//      rating (out)            rating of key for this user
    2.14 +//
    2.15 +//  returns:
    2.16 +//      status from get_key_rating, which only returns comm_type.
    2.17 +
    2.18 +DYNAMIC_API PEP_STATUS get_rating_from_bare_key(
    2.19 +        PEP_SESSION session, 
    2.20 +        const char* fpr,
    2.21 +        PEP_rating* rating
    2.22 +    );
    2.23 +
    2.24  #ifdef __cplusplus
    2.25  }
    2.26  #endif