ENGINE-174 this should fix side effects on Sync - take key comm_type instead of least_trust when trust is not set ENGINE-188
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 08 Mar 2017 23:10:30 +0100
branchENGINE-188
changeset 1632ab9a7a180cfe
parent 1630 a507a5006bea
child 1635 b23f60d69fb8
ENGINE-174 this should fix side effects on Sync - take key comm_type instead of least_trust when trust is not set
src/message_api.c
src/pEpEngine.c
     1.1 --- a/src/message_api.c	Tue Mar 07 23:52:44 2017 +0100
     1.2 +++ b/src/message_api.c	Wed Mar 08 23:10:30 2017 +0100
     1.3 @@ -789,7 +789,6 @@
     1.4  
     1.5  static PEP_rating key_rating(PEP_SESSION session, const char *fpr)
     1.6  {
     1.7 -    PEP_comm_type bare_comm_type = PEP_ct_unknown;
     1.8  
     1.9      assert(session);
    1.10      assert(fpr);
    1.11 @@ -797,20 +796,20 @@
    1.12      if (session == NULL || fpr == NULL)
    1.13          return PEP_rating_undefined;
    1.14  
    1.15 +
    1.16 +    PEP_comm_type bare_comm_type = PEP_ct_unknown;
    1.17      PEP_STATUS status = get_key_rating(session, fpr, &bare_comm_type);
    1.18      if (status != PEP_STATUS_OK)
    1.19          return PEP_rating_undefined;
    1.20  
    1.21 -    /* FIXME: All this tells us is that the bare key is ok. It's
    1.22 -       fine to check - if there's something wrong with the key in
    1.23 -       the keyring we should probably do something about it -
    1.24 -       but it doesn't deal with overall trust. We also need 
    1.25 -       trust in here. */
    1.26 -    
    1.27      PEP_comm_type least_trust_type = PEP_ct_unknown;
    1.28 -    status = least_trust(session, fpr, &least_trust_type);
    1.29 -
    1.30 -    return _rating(least_trust_type, PEP_rating_undefined);
    1.31 +    least_trust(session, fpr, &least_trust_type);
    1.32 +
    1.33 +    if (least_trust_type == PEP_ct_unknown) {
    1.34 +        return _rating(bare_comm_type, PEP_rating_undefined);
    1.35 +    } else {
    1.36 +        return _rating(least_trust_type, PEP_rating_undefined);
    1.37 +    }
    1.38  }
    1.39  
    1.40  static PEP_rating worst_rating(PEP_rating rating1, PEP_rating rating2) {
     2.1 --- a/src/pEpEngine.c	Tue Mar 07 23:52:44 2017 +0100
     2.2 +++ b/src/pEpEngine.c	Wed Mar 08 23:10:30 2017 +0100
     2.3 @@ -90,7 +90,10 @@
     2.4      "and pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
     2.5  
     2.6  static const char *sql_least_trust = 
     2.7 -    "select min(comm_type) from trust where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
     2.8 +    "select min(comm_type) from trust where"
     2.9 +    " pgp_keypair_fpr = upper(replace(?1,' ',''))"
    2.10 +    " and comm_type != 0;"; // ignores PEP_ct_unknown
    2.11 +    // returns PEP_ct_unknown only when no known trust is recorded
    2.12  
    2.13  static const char *sql_mark_as_compromized = 
    2.14      "update trust not indexed set comm_type = 15"
    2.15 @@ -1425,6 +1428,7 @@
    2.16              break;
    2.17          }
    2.18          default:
    2.19 +            // never reached because of sql min()
    2.20              status = PEP_CANNOT_FIND_IDENTITY;
    2.21      }
    2.22