Fixed call to _myself in trust_personal_key (should now be set_own_key), and also made sure that when an own identity comes in but the key is public only, that it gets verified but never set as the default when being trusted.
authorKrista Bennett <krista@pep-project.org>
Mon, 05 Mar 2018 18:02:34 +0100
changeset 255209d77d1177ce
parent 2551 a5ea813f1315
child 2553 f66efd53d8b1
Fixed call to _myself in trust_personal_key (should now be set_own_key), and also made sure that when an own identity comes in but the key is public only, that it gets verified but never set as the default when being trusted.
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Wed Feb 28 15:59:16 2018 +0100
     1.2 +++ b/src/keymanagement.c	Mon Mar 05 18:02:34 2018 +0100
     1.3 @@ -1345,37 +1345,54 @@
     1.4      pEp_identity* tmp_user_ident = NULL;
     1.5  
     1.6      if (me) {
     1.7 -        status = myself(session, ident_copy); 
     1.8 -        goto pep_free;
     1.9 +        bool has_private = false;
    1.10 +        // first of all, does this key even have a private component.
    1.11 +        status = contains_priv_key(session, ident->fpr, &has_private);
    1.12 +        if (status != PEP_STATUS_OK && status != PEP_KEY_NOT_FOUND)
    1.13 +            goto pep_free;
    1.14 +            
    1.15 +        if (has_private) {
    1.16 +            status = set_own_key(session, ident_copy, ident->fpr); 
    1.17 +            goto pep_free;
    1.18 +        }
    1.19      }
    1.20      
    1.21 +    // Either it's not me, or it's me but the key has no private key. 
    1.22 +    // We're only talking about pub keys here. Moving on.
    1.23 +    
    1.24      // Save the input fpr, which we already tested as non-NULL
    1.25      cached_fpr = strdup(ident->fpr);
    1.26  
    1.27 -    // First, set up a temp trusted identity for the input fpr without a comm type;
    1.28 +    // Set up a temp trusted identity for the input fpr without a comm type;
    1.29      tmp_id = new_identity(ident->address, ident->fpr, ident->user_id, NULL);
    1.30 +    
    1.31 +    // ->me isn't set, even if this is an own identity, so this will work.
    1.32      status = validate_fpr(session, tmp_id, false);
    1.33          
    1.34      if (status == PEP_STATUS_OK) {
    1.35          // Validate fpr gets trust DB or, when that fails, key comm type. we checked
    1.36          // above that the key was ok. (not revoked or expired), but we want the max.
    1.37          tmp_id->comm_type = _MAX(tmp_id->comm_type, input_default_ct) | PEP_ct_confirmed;
    1.38 -                                       
    1.39 -        // Get the default identity without setting the fpr
    1.40 -        status = update_identity(session, ident_copy);
    1.41 +
    1.42 +        // Get the default identity without setting the fpr                                       
    1.43 +        if (me)
    1.44 +            status = _myself(session, ident_copy, false, true);
    1.45 +        else    
    1.46 +            status = update_identity(session, ident_copy);
    1.47 +            
    1.48          ident_default_fpr = (EMPTYSTR(ident_copy->fpr) ? NULL : strdup(ident_copy->fpr));
    1.49  
    1.50          if (status == PEP_STATUS_OK) {
    1.51              bool trusted_default = false;
    1.52  
    1.53              // If there's no default, or the default is different from the input...
    1.54 -            if (EMPTYSTR(ident_default_fpr) || strcmp(cached_fpr, ident_default_fpr) != 0) {
    1.55 +            if (me || EMPTYSTR(ident_default_fpr) || strcmp(cached_fpr, ident_default_fpr) != 0) {
    1.56                  
    1.57                  // If the default fpr (if there is one) is trusted and key is strong enough,
    1.58                  // don't replace, we just set the trusted bit on this key for this user_id...
    1.59                  // (If there's no default fpr, this won't be true anyway.)
    1.60 -                if (ident->comm_type >= PEP_ct_strong_but_unconfirmed && 
    1.61 -                    (ident->comm_type & PEP_ct_confirmed)) {                        
    1.62 +                if (me || (ident_copy->comm_type >= PEP_ct_strong_but_unconfirmed && 
    1.63 +                          (ident_copy->comm_type & PEP_ct_confirmed))) {                        
    1.64  
    1.65                      trusted_default = true;
    1.66