Fixed update_identity vs. myself calls in keymanagement, plus what would have been inconsistent behaviour in trust_personal_key for quite sometime (update_identity fprs have been write_only for some time, so calling it within the function without checking meant the input FPR was effectively ignored.
authorKrista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 16:36:27 +0100
changeset 24250cdb4ce00787
parent 2420 b022b37d6d92
child 2426 435c19d76cad
Fixed update_identity vs. myself calls in keymanagement, plus what would have been inconsistent behaviour in trust_personal_key for quite sometime (update_identity fprs have been write_only for some time, so calling it within the function without checking meant the input FPR was effectively ignored.
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Fri Jan 19 15:15:41 2018 +0100
     1.2 +++ b/src/keymanagement.c	Fri Jan 19 16:36:27 2018 +0100
     1.3 @@ -1098,11 +1098,18 @@
     1.4      assert(!EMPTYSTR(ident->address));
     1.5      assert(!EMPTYSTR(ident->user_id));
     1.6  
     1.7 -    if (!(session && ident && !ident->me && ident->fpr && ident->address &&
     1.8 +    // Nope. We should be able to reset trust on an own key.
     1.9 +    if (!(session && ident && ident->fpr && ident->fpr[0] != '\0' && ident->address &&
    1.10              ident->user_id))
    1.11          return PEP_ILLEGAL_VALUE;
    1.12 +        
    1.13 +    bool me = is_me(session, ident); 
    1.14  
    1.15 -    status = update_identity(session, ident);
    1.16 +    if (me)
    1.17 +        status = myself(session, ident);
    1.18 +    else     
    1.19 +        status = update_identity(session, ident);
    1.20 +        
    1.21      if (status != PEP_STATUS_OK)
    1.22          return status;
    1.23  
    1.24 @@ -1112,11 +1119,16 @@
    1.25          ident->comm_type &= ~PEP_ct_confirmed;
    1.26  
    1.27      status = set_identity(session, ident);
    1.28 +    
    1.29 +    // FIXME: remove key as default for user_id
    1.30 +    
    1.31      if (status != PEP_STATUS_OK)
    1.32          return status;
    1.33  
    1.34 -    if (ident->comm_type == PEP_ct_unknown)
    1.35 +    // FIXME: What is this point of this here??
    1.36 +    if (ident->comm_type == PEP_ct_unknown && !me) {
    1.37          status = update_identity(session, ident);
    1.38 +    }
    1.39      return status;
    1.40  }
    1.41  
    1.42 @@ -1137,7 +1149,28 @@
    1.43              EMPTYSTR(ident->fpr))
    1.44          return PEP_ILLEGAL_VALUE;
    1.45  
    1.46 -    status = update_identity(session, ident);
    1.47 +    bool me = is_me(session, ident);
    1.48 +
    1.49 +    if (me)
    1.50 +        status = myself(session, ident);
    1.51 +    else {
    1.52 +        char* saved_fpr = ident->fpr;
    1.53 +        ident->fpr = NULL;
    1.54 +        
    1.55 +        status = update_identity(session, ident);
    1.56 +        
    1.57 +        if (EMPTYSTR(ident->fpr) || strcmp(ident->fpr, saved_fpr) != 0) {
    1.58 +            ident->fpr = saved_fpr;
    1.59 +            ident->comm_type = PEP_ct_unknown;
    1.60 +            status = set_identity(session, ident);
    1.61 +            if (status == PEP_STATUS_OK)
    1.62 +                status = update_identity(session, ident);
    1.63 +        }
    1.64 +        // either saved_fpr got copied in update_identity and we're done
    1.65 +        // with it, or it's not referenced anymore because we didn't call
    1.66 +        // it.
    1.67 +        free(saved_fpr);            
    1.68 +    } 
    1.69      if (status != PEP_STATUS_OK)
    1.70          return status;
    1.71