changing rating and color keysync
authorVolker Birk <vb@pep.foundation>
Thu, 11 Aug 2016 21:48:26 +0200
branchkeysync
changeset 10049828752c0751
parent 1003 e5eef6e5b153
child 1006 0dc1800f8b2d
changing rating and color
src/message_api.c
src/message_api.h
src/sync_actions.c
     1.1 --- a/src/message_api.c	Thu Aug 11 12:39:51 2016 +0200
     1.2 +++ b/src/message_api.c	Thu Aug 11 21:48:26 2016 +0200
     1.3 @@ -603,9 +603,9 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -static const char * color_to_string(PEP_color color)
     1.8 +static const char * rating_to_string(PEP_rating rating)
     1.9  {
    1.10 -    switch (color) {
    1.11 +    switch (rating) {
    1.12      case PEP_rating_cannot_decrypt:
    1.13          return "cannot_decrypt";
    1.14      case PEP_rating_have_no_key:
    1.15 @@ -637,7 +637,7 @@
    1.16  
    1.17  static void decorate_message(
    1.18      message *msg,
    1.19 -    PEP_color color,
    1.20 +    PEP_rating rating,
    1.21      stringlist_t *keylist
    1.22      )
    1.23  {
    1.24 @@ -645,8 +645,8 @@
    1.25  
    1.26      add_opt_field(msg, "X-pEp-Version", PEP_VERSION);
    1.27      
    1.28 -    if (color != PEP_rating_undefined)
    1.29 -        add_opt_field(msg, "X-EncStatus", color_to_string(color));
    1.30 +    if (rating != PEP_rating_undefined)
    1.31 +        add_opt_field(msg, "X-EncStatus", rating_to_string(rating));
    1.32  
    1.33      if (keylist) {
    1.34          char *_keylist = keylist_to_string(keylist);
    1.35 @@ -655,7 +655,7 @@
    1.36      }
    1.37  }
    1.38  
    1.39 -static PEP_color _rating(PEP_comm_type ct, PEP_color color)
    1.40 +static PEP_rating _rating(PEP_comm_type ct, PEP_rating rating)
    1.41  {
    1.42      if (ct == PEP_ct_unknown)
    1.43          return PEP_rating_undefined;
    1.44 @@ -666,18 +666,18 @@
    1.45      else if (ct == PEP_ct_mistrusted)
    1.46          return PEP_rating_mistrust;
    1.47      
    1.48 -    if (color == PEP_rating_unencrypted_for_some)
    1.49 +    if (rating == PEP_rating_unencrypted_for_some)
    1.50          return PEP_rating_unencrypted_for_some;
    1.51  
    1.52      if (ct == PEP_ct_no_encryption || ct == PEP_ct_no_encrypted_channel ||
    1.53              ct == PEP_ct_my_key_not_included) {
    1.54 -        if (color > PEP_rating_unencrypted_for_some)
    1.55 +        if (rating > PEP_rating_unencrypted_for_some)
    1.56              return PEP_rating_unencrypted_for_some;
    1.57          else
    1.58              return PEP_rating_unencrypted;
    1.59      }
    1.60  
    1.61 -    if (color == PEP_rating_unencrypted)
    1.62 +    if (rating == PEP_rating_unencrypted)
    1.63          return PEP_rating_unencrypted_for_some;
    1.64  
    1.65      if (ct >= PEP_ct_confirmed_enc_anon)
    1.66 @@ -750,7 +750,7 @@
    1.67      return result;
    1.68  }
    1.69  
    1.70 -static PEP_color decrypt_color(PEP_STATUS status)
    1.71 +static PEP_rating decrypt_rating(PEP_STATUS status)
    1.72  {
    1.73      switch (status) {
    1.74      case PEP_UNENCRYPTED:
    1.75 @@ -777,7 +777,7 @@
    1.76      }
    1.77  }
    1.78  
    1.79 -static PEP_color key_color(PEP_SESSION session, const char *fpr)
    1.80 +static PEP_rating key_rating(PEP_SESSION session, const char *fpr)
    1.81  {
    1.82      PEP_comm_type comm_type = PEP_ct_unknown;
    1.83  
    1.84 @@ -794,9 +794,9 @@
    1.85      return _rating(comm_type, PEP_rating_undefined);
    1.86  }
    1.87  
    1.88 -static PEP_color keylist_color(PEP_SESSION session, stringlist_t *keylist)
    1.89 +static PEP_rating keylist_rating(PEP_SESSION session, stringlist_t *keylist)
    1.90  {
    1.91 -    PEP_color color = PEP_rating_reliable;
    1.92 +    PEP_rating rating = PEP_rating_reliable;
    1.93  
    1.94      assert(keylist && keylist->value);
    1.95      if (keylist == NULL || keylist->value == NULL)
    1.96 @@ -807,29 +807,29 @@
    1.97          PEP_comm_type ct;
    1.98          PEP_STATUS status;
    1.99  
   1.100 -        PEP_color _color = key_color(session, _kl->value);
   1.101 -        if (_color <= PEP_rating_mistrust)
   1.102 -            return _color;
   1.103 +        PEP_rating _rating_ = key_rating(session, _kl->value);
   1.104 +        if (_rating_ <= PEP_rating_mistrust)
   1.105 +            return _rating_;
   1.106  
   1.107 -        if (color == PEP_rating_undefined)
   1.108 -            color = _color;
   1.109 +        if (rating == PEP_rating_undefined)
   1.110 +            rating = _rating_;
   1.111  
   1.112 -        if (_color >= PEP_rating_reliable) {
   1.113 +        if (_rating_ >= PEP_rating_reliable) {
   1.114              status = least_trust(session, _kl->value, &ct);
   1.115              if (status != PEP_STATUS_OK)
   1.116                  return PEP_rating_undefined;
   1.117              if (ct == PEP_ct_unknown)
   1.118 -                color = PEP_rating_unencrypted_for_some;
   1.119 +                rating = PEP_rating_unencrypted_for_some;
   1.120              else
   1.121 -                color = _rating(ct, color);
   1.122 +                rating = _rating(ct, rating);
   1.123          }
   1.124 -        else if (_color == PEP_rating_unencrypted) {
   1.125 -            if (color > PEP_rating_unencrypted_for_some)
   1.126 -                color = PEP_rating_unencrypted_for_some;
   1.127 +        else if (_rating_ == PEP_rating_unencrypted) {
   1.128 +            if (rating > PEP_rating_unencrypted_for_some)
   1.129 +                rating = PEP_rating_unencrypted_for_some;
   1.130          }
   1.131      }
   1.132  
   1.133 -    return color;
   1.134 +    return rating;
   1.135  }
   1.136  
   1.137  static PEP_comm_type _get_comm_type(
   1.138 @@ -1347,7 +1347,7 @@
   1.139          message *src,
   1.140          message **dst,
   1.141          stringlist_t **keylist,
   1.142 -        PEP_color *color,
   1.143 +        PEP_rating *rating,
   1.144          PEP_decrypt_flags_t *flags, 
   1.145          identity_list **private_il
   1.146      )
   1.147 @@ -1365,10 +1365,10 @@
   1.148      assert(src);
   1.149      assert(dst);
   1.150      assert(keylist);
   1.151 -    assert(color);
   1.152 +    assert(rating);
   1.153      assert(flags);
   1.154  
   1.155 -    if (!(session && src && dst && keylist && color && flags))
   1.156 +    if (!(session && src && dst && keylist && rating && flags))
   1.157          return PEP_ILLEGAL_VALUE;
   1.158  
   1.159      *flags = 0;
   1.160 @@ -1386,11 +1386,11 @@
   1.161  
   1.162      *dst = NULL;
   1.163      *keylist = NULL;
   1.164 -    *color = PEP_rating_undefined;
   1.165 +    *rating = PEP_rating_undefined;
   1.166   
   1.167      switch (src->enc_format) {
   1.168          case PEP_enc_none:
   1.169 -            *color = PEP_rating_unencrypted;
   1.170 +            *rating = PEP_rating_unencrypted;
   1.171              if (imported_keys)
   1.172                  remove_attached_keys(src);
   1.173              return PEP_UNENCRYPTED;
   1.174 @@ -1596,25 +1596,25 @@
   1.175              decrypt_status = status;
   1.176          }
   1.177          
   1.178 -        *color = decrypt_color(decrypt_status);
   1.179 +        *rating = decrypt_rating(decrypt_status);
   1.180          
   1.181 -        if (*color > PEP_rating_mistrust) {
   1.182 -            PEP_color kl_color = PEP_rating_undefined;
   1.183 +        if (*rating > PEP_rating_mistrust) {
   1.184 +            PEP_rating kl_rating = PEP_rating_undefined;
   1.185              
   1.186              if (_keylist)
   1.187 -                kl_color = keylist_color(session, _keylist);
   1.188 +                kl_rating = keylist_rating(session, _keylist);
   1.189              
   1.190 -            if (kl_color <= PEP_rating_mistrust) {
   1.191 -                *color = kl_color;
   1.192 +            if (kl_rating <= PEP_rating_mistrust) {
   1.193 +                *rating = kl_rating;
   1.194              }
   1.195 -            else if (*color >= PEP_rating_reliable &&
   1.196 -                     kl_color < PEP_rating_reliable) {
   1.197 -                *color = PEP_rating_unreliable;
   1.198 +            else if (*rating >= PEP_rating_reliable &&
   1.199 +                     kl_rating < PEP_rating_reliable) {
   1.200 +                *rating = PEP_rating_unreliable;
   1.201              }
   1.202 -            else if (*color >= PEP_rating_reliable &&
   1.203 -                     kl_color >= PEP_rating_reliable) {
   1.204 +            else if (*rating >= PEP_rating_reliable &&
   1.205 +                     kl_rating >= PEP_rating_reliable) {
   1.206                  if (!(src->from && src->from->user_id && src->from->user_id[0])) {
   1.207 -                    *color = PEP_rating_unreliable;
   1.208 +                    *rating = PEP_rating_unreliable;
   1.209                  }
   1.210                  else {
   1.211                      char *fpr = _keylist->value;
   1.212 @@ -1624,7 +1624,7 @@
   1.213                          goto enomem;
   1.214                      status = update_identity(session, _from);
   1.215                      if (_from->comm_type != PEP_ct_unknown)
   1.216 -                        *color = _rating(_from->comm_type, PEP_rating_undefined);
   1.217 +                        *rating = _rating(_from->comm_type, PEP_rating_undefined);
   1.218                      free_identity(_from);
   1.219                      if (status != PEP_STATUS_OK)
   1.220                          goto pep_error;
   1.221 @@ -1634,14 +1634,14 @@
   1.222      }
   1.223      else
   1.224      {
   1.225 -        *color = decrypt_color(decrypt_status);
   1.226 +        *rating = decrypt_rating(decrypt_status);
   1.227          goto pep_error;
   1.228      }
   1.229  
   1.230      // Case of own key imported from own trusted message
   1.231      if (// Message have been reliably decrypted 
   1.232          msg &&
   1.233 -        *color >= PEP_rating_green &&
   1.234 +        *rating >= PEP_rating_trusted &&
   1.235          imported_private_key_address &&
   1.236          // to is [own]
   1.237          msg->to->ident->user_id &&
   1.238 @@ -1652,7 +1652,7 @@
   1.239      }
   1.240  
   1.241      if (msg) {
   1.242 -        decorate_message(msg, *color, _keylist);
   1.243 +        decorate_message(msg, *rating, _keylist);
   1.244          if (imported_keys)
   1.245              remove_attached_keys(msg);
   1.246      }
   1.247 @@ -1687,11 +1687,11 @@
   1.248          message *src,
   1.249          message **dst,
   1.250          stringlist_t **keylist,
   1.251 -        PEP_color *color,
   1.252 +        PEP_rating *rating,
   1.253          PEP_decrypt_flags_t *flags 
   1.254      )
   1.255  {
   1.256 -    return _decrypt_message( session, src, dst, keylist, color, flags, NULL );
   1.257 +    return _decrypt_message( session, src, dst, keylist, rating, flags, NULL );
   1.258  }
   1.259  
   1.260  DYNAMIC_API PEP_STATUS own_message_private_key_details(
   1.261 @@ -1709,13 +1709,13 @@
   1.262  
   1.263      message *dst = NULL; 
   1.264      stringlist_t *keylist = NULL;
   1.265 -    PEP_color color;
   1.266 +    PEP_rating rating;
   1.267      PEP_decrypt_flags_t flags; 
   1.268  
   1.269      *ident = NULL;
   1.270  
   1.271      identity_list *private_il = NULL;
   1.272 -    PEP_STATUS status = _decrypt_message(session, msg,  &dst, &keylist, &color, &flags, &private_il);
   1.273 +    PEP_STATUS status = _decrypt_message(session, msg,  &dst, &keylist, &rating, &flags, &private_il);
   1.274      free_message(dst);
   1.275      free_stringlist(keylist);
   1.276  
   1.277 @@ -1757,10 +1757,10 @@
   1.278      }
   1.279  }
   1.280  
   1.281 -DYNAMIC_API PEP_STATUS outgoing_message_color(
   1.282 +DYNAMIC_API PEP_STATUS outgoing_message_rating(
   1.283          PEP_SESSION session,
   1.284          message *msg,
   1.285 -        PEP_color *color
   1.286 +        PEP_rating *rating
   1.287      )
   1.288  {
   1.289      PEP_STATUS status = PEP_STATUS_OK;
   1.290 @@ -1771,15 +1771,15 @@
   1.291      assert(msg);
   1.292      assert(msg->from);
   1.293      assert(msg->dir == PEP_dir_outgoing);
   1.294 -    assert(color);
   1.295 +    assert(rating);
   1.296  
   1.297 -    if (!(session && msg && color))
   1.298 +    if (!(session && msg && rating))
   1.299          return PEP_ILLEGAL_VALUE;
   1.300  
   1.301      if (msg->from == NULL || msg->dir != PEP_dir_outgoing)
   1.302          return PEP_ILLEGAL_VALUE;
   1.303  
   1.304 -    *color = PEP_rating_undefined;
   1.305 +    *rating = PEP_rating_undefined;
   1.306  
   1.307      status = myself(session, msg->from);
   1.308      if (status != PEP_STATUS_OK)
   1.309 @@ -1795,27 +1795,27 @@
   1.310                                        &max_comm_type, &comm_type_determined);
   1.311  
   1.312      if (comm_type_determined == false)
   1.313 -        *color = PEP_rating_undefined;
   1.314 +        *rating = PEP_rating_undefined;
   1.315      else
   1.316 -        *color = _MAX(_rating(max_comm_type, PEP_rating_undefined),
   1.317 +        *rating = _MAX(_rating(max_comm_type, PEP_rating_undefined),
   1.318                  PEP_rating_unencrypted);
   1.319  
   1.320      return PEP_STATUS_OK;
   1.321  }
   1.322  
   1.323 -DYNAMIC_API PEP_STATUS identity_color(
   1.324 +DYNAMIC_API PEP_STATUS identity_rating(
   1.325          PEP_SESSION session,
   1.326          pEp_identity *ident,
   1.327 -        PEP_color *color
   1.328 +        PEP_rating *rating
   1.329      )
   1.330  {
   1.331      PEP_STATUS status = PEP_STATUS_OK;
   1.332  
   1.333      assert(session);
   1.334      assert(ident);
   1.335 -    assert(color);
   1.336 +    assert(rating);
   1.337  
   1.338 -    if (!(session && ident && color))
   1.339 +    if (!(session && ident && rating))
   1.340          return PEP_ILLEGAL_VALUE;
   1.341  
   1.342      if (ident->me)
   1.343 @@ -1824,7 +1824,7 @@
   1.344          status = update_identity(session, ident);
   1.345  
   1.346      if (status == PEP_STATUS_OK)
   1.347 -        *color = _rating(ident->comm_type, PEP_rating_undefined);
   1.348 +        *rating = _rating(ident->comm_type, PEP_rating_undefined);
   1.349  
   1.350      return status;
   1.351  }
   1.352 @@ -1845,3 +1845,25 @@
   1.353      return status;
   1.354  }
   1.355  
   1.356 +
   1.357 +DYNAMIC_API PEP_color color_from_rating(PEP_rating rating)
   1.358 +{
   1.359 +    if (rating == PEP_rating_b0rken)
   1.360 +        return PEP_color_no_color;
   1.361 +
   1.362 +    if (rating < PEP_rating_undefined)
   1.363 +        return PEP_color_red;
   1.364 +
   1.365 +    if (rating < PEP_rating_reliable)
   1.366 +        return PEP_color_no_color;
   1.367 +
   1.368 +    if (rating < PEP_rating_trusted)
   1.369 +        return PEP_color_yellow;
   1.370 +
   1.371 +    if (rating >= PEP_rating_trusted)
   1.372 +        return PEP_color_green;
   1.373 +
   1.374 +    // this should never happen
   1.375 +    assert(false);
   1.376 +}
   1.377 +
     2.1 --- a/src/message_api.h	Thu Aug 11 12:39:51 2016 +0200
     2.2 +++ b/src/message_api.h	Thu Aug 11 21:48:26 2016 +0200
     2.3 @@ -90,7 +90,7 @@
     2.4          PEP_enc_format enc_format
     2.5      );
     2.6  
     2.7 -typedef enum _PEP_color {
     2.8 +typedef enum _PEP_rating {
     2.9      PEP_rating_undefined = 0,
    2.10      PEP_rating_cannot_decrypt,
    2.11      PEP_rating_have_no_key,
    2.12 @@ -98,18 +98,24 @@
    2.13      PEP_rating_unencrypted_for_some,
    2.14      PEP_rating_unreliable,
    2.15      PEP_rating_reliable,
    2.16 -    PEP_rating_yellow = PEP_rating_reliable,
    2.17      PEP_rating_trusted,
    2.18 -    PEP_rating_green = PEP_rating_trusted,
    2.19      PEP_rating_trusted_and_anonymized,
    2.20      PEP_rating_fully_anonymous,   
    2.21  
    2.22      PEP_rating_mistrust = -1,
    2.23 -    PEP_rating_red = PEP_rating_mistrust,
    2.24      PEP_rating_b0rken = -2,
    2.25      PEP_rating_under_attack = -3
    2.26 +} PEP_rating;
    2.27 +
    2.28 +typedef enum _PEP_color {
    2.29 +    PEP_color_no_color = 0,
    2.30 +    PEP_color_yellow,
    2.31 +    PEP_color_green,
    2.32 +    PEP_color_red = -1,
    2.33  } PEP_color;
    2.34  
    2.35 +DYNAMIC_API PEP_color color_from_rating(PEP_rating rating);
    2.36 +
    2.37  typedef enum _PEP_decrypt_flags {
    2.38      PEP_decrypt_flag_own_private_key = 0x1
    2.39  } PEP_decrypt_flags; 
    2.40 @@ -141,7 +147,7 @@
    2.41          message *src,
    2.42          message **dst,
    2.43          stringlist_t **keylist,
    2.44 -        PEP_color *color,
    2.45 +        PEP_rating *rating,
    2.46          PEP_decrypt_flags_t *flags
    2.47  );
    2.48  
    2.49 @@ -177,7 +183,7 @@
    2.50  //  parameters:
    2.51  //      session (in)        session handle
    2.52  //      msg (in)            message to get the color for
    2.53 -//      color (out)         color for the message
    2.54 +//      rating (out)        color for the message
    2.55  //
    2.56  //  return value:
    2.57  //      error status or PEP_STATUS_OK on success
    2.58 @@ -190,7 +196,7 @@
    2.59  DYNAMIC_API PEP_STATUS outgoing_message_color(
    2.60          PEP_SESSION session,
    2.61          message *msg,
    2.62 -        PEP_color *color
    2.63 +        PEP_rating *rating
    2.64      );
    2.65  
    2.66  
    2.67 @@ -210,7 +216,7 @@
    2.68  DYNAMIC_API PEP_STATUS identity_color(
    2.69          PEP_SESSION session,
    2.70          pEp_identity *ident,
    2.71 -        PEP_color *color
    2.72 +        PEP_rating *rating
    2.73      );
    2.74  
    2.75  
     3.1 --- a/src/sync_actions.c	Thu Aug 11 12:39:51 2016 +0200
     3.2 +++ b/src/sync_actions.c	Thu Aug 11 21:48:26 2016 +0200
     3.3 @@ -10,7 +10,7 @@
     3.4  // conditions
     3.5  
     3.6  static const char *sql_stored_group_keys =
     3.7 -        "select count(device_group) from person where id = "PEP_OWN_USERID";"; 
     3.8 +        "select count(device_group) from person where id = '" PEP_OWN_USERID "';"; 
     3.9  
    3.10  static int _stored_group_keys(void *_gc, int count, char **text, char **name)
    3.11  {