trying to get a better key in update_identity, when existing key has been revoked fixing_revoke
authorEdouard Tisserant
Wed, 22 Jun 2016 16:58:27 +0200
branchfixing_revoke
changeset 7553bac36e6fb86
parent 753 dd21cdff7492
child 757 667fbb1ee478
child 924 2092a20b19df
trying to get a better key in update_identity, when existing key has been revoked
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Wed Jun 22 10:03:35 2016 +0200
     1.2 +++ b/src/keymanagement.c	Wed Jun 22 16:58:27 2016 +0200
     1.3 @@ -56,6 +56,56 @@
     1.4      return ai == fpras && bi == fprbs;
     1.5  }
     1.6  
     1.7 +PEP_STATUS elect_key(
     1.8 +        PEP_SESSION session, pEp_identity * identity
     1.9 +    )
    1.10 +{
    1.11 +    PEP_STATUS status;
    1.12 +    stringlist_t *keylist;
    1.13 +    char *_fpr = NULL;
    1.14 +    identity->comm_type = PEP_ct_unknown;
    1.15 +
    1.16 +    status = find_keys(session, identity->address, &keylist);
    1.17 +    assert(status != PEP_OUT_OF_MEMORY);
    1.18 +    if (status == PEP_OUT_OF_MEMORY)
    1.19 +        return PEP_OUT_OF_MEMORY;
    1.20 +
    1.21 +    stringlist_t *_keylist;
    1.22 +    for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
    1.23 +        PEP_comm_type _comm_type_key;
    1.24 +
    1.25 +        status = get_key_rating(session, _keylist->value, &_comm_type_key);
    1.26 +        assert(status != PEP_OUT_OF_MEMORY);
    1.27 +        if (status == PEP_OUT_OF_MEMORY) {
    1.28 +            free_stringlist(keylist);
    1.29 +            return PEP_OUT_OF_MEMORY;
    1.30 +        }
    1.31 +
    1.32 +        if (_comm_type_key != PEP_ct_compromized &&
    1.33 +            _comm_type_key != PEP_ct_unknown)
    1.34 +        {
    1.35 +            if (identity->comm_type == PEP_ct_unknown ||
    1.36 +                _comm_type_key > identity->comm_type)
    1.37 +            {
    1.38 +                identity->comm_type = _comm_type_key;
    1.39 +                _fpr = _keylist->value;
    1.40 +            }
    1.41 +        }
    1.42 +    }
    1.43 +
    1.44 +    if (_fpr) {
    1.45 +        free(identity->fpr);
    1.46 +
    1.47 +        identity->fpr = strdup(_fpr);
    1.48 +        if (identity->fpr == NULL) {
    1.49 +            free_stringlist(keylist);
    1.50 +            return PEP_OUT_OF_MEMORY;
    1.51 +        }
    1.52 +    }
    1.53 +    free_stringlist(keylist);
    1.54 +    return PEP_STATUS_OK;
    1.55 +}
    1.56 +
    1.57  DYNAMIC_API PEP_STATUS update_identity(
    1.58          PEP_SESSION session, pEp_identity * identity
    1.59      )
    1.60 @@ -115,7 +165,9 @@
    1.61              if (identity->fpr == NULL)
    1.62                  return PEP_OUT_OF_MEMORY;
    1.63              if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
    1.64 -                identity->comm_type = _comm_type_key;
    1.65 +                PEP_STATUS status = elect_key(session, identity);
    1.66 +                if (status != PEP_STATUS_OK)
    1.67 +                    return status;
    1.68              }
    1.69              else {
    1.70                  identity->comm_type = stored_identity->comm_type;
    1.71 @@ -162,49 +214,9 @@
    1.72              identity->comm_type = _comm_type_key;
    1.73          }
    1.74          else /* EMPTYSTR(identity->fpr) */ {
    1.75 -            PEP_STATUS status;
    1.76 -            stringlist_t *keylist;
    1.77 -            char *_fpr = NULL;
    1.78 -            identity->comm_type = PEP_ct_unknown;
    1.79 -
    1.80 -            status = find_keys(session, identity->address, &keylist);
    1.81 -            assert(status != PEP_OUT_OF_MEMORY);
    1.82 -            if (status == PEP_OUT_OF_MEMORY)
    1.83 -                return PEP_OUT_OF_MEMORY;
    1.84 -
    1.85 -            stringlist_t *_keylist;
    1.86 -            for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
    1.87 -                PEP_comm_type _comm_type_key;
    1.88 -
    1.89 -                status = get_key_rating(session, _keylist->value, &_comm_type_key);
    1.90 -                assert(status != PEP_OUT_OF_MEMORY);
    1.91 -                if (status == PEP_OUT_OF_MEMORY) {
    1.92 -                    free_stringlist(keylist);
    1.93 -                    return PEP_OUT_OF_MEMORY;
    1.94 -                }
    1.95 -
    1.96 -                if (_comm_type_key != PEP_ct_compromized &&
    1.97 -                    _comm_type_key != PEP_ct_unknown)
    1.98 -                {
    1.99 -                    if (identity->comm_type == PEP_ct_unknown ||
   1.100 -                        _comm_type_key > identity->comm_type)
   1.101 -                    {
   1.102 -                        identity->comm_type = _comm_type_key;
   1.103 -                        _fpr = _keylist->value;
   1.104 -                    }
   1.105 -                }
   1.106 -            }
   1.107 -
   1.108 -            if (_fpr) {
   1.109 -                free(identity->fpr);
   1.110 -
   1.111 -                identity->fpr = strdup(_fpr);
   1.112 -                if (identity->fpr == NULL) {
   1.113 -                    free_stringlist(keylist);
   1.114 -                    return PEP_OUT_OF_MEMORY;
   1.115 -                }
   1.116 -            }
   1.117 -            free_stringlist(keylist);
   1.118 +            PEP_STATUS status = elect_key(session, identity);
   1.119 +            if (status != PEP_STATUS_OK)
   1.120 +                return status;
   1.121          }
   1.122      }
   1.123  
   1.124 @@ -220,8 +232,8 @@
   1.125                  return PEP_OUT_OF_MEMORY;
   1.126          }
   1.127  
   1.128 -        // Identity doesn't get stored if is was just about checking existing
   1.129 -        // user by address (i.e. no user id but already stored)
   1.130 +        // Identity doesn't get stored if call was just about checking existing
   1.131 +        // user by address (i.e. no user id given but already stored)
   1.132          if (!(_no_user_id && stored_identity))
   1.133          {
   1.134              status = set_identity(session, identity);