src/keymanagement.c
branchENGINE-289
changeset 2371 05c495924fde
parent 2370 b37530bf26fa
child 2385 974de9c65cbb
     1.1 --- a/src/keymanagement.c	Wed Jan 10 09:19:44 2018 +0100
     1.2 +++ b/src/keymanagement.c	Wed Jan 10 16:19:07 2018 +0100
     1.3 @@ -114,14 +114,18 @@
     1.4          return ADD_TO_LOG(status);
     1.5      
     1.6      PEP_comm_type ct = ident->comm_type;
     1.7 +
     1.8 +    if (ct == PEP_ct_unknown) {
     1.9 +        // If status is bad, it's ok, we get the rating
    1.10 +        // we should use then (PEP_ct_unknown)
    1.11 +        get_key_rating(session, fpr, &ct);
    1.12 +    }
    1.13      
    1.14      bool revoked, expired;
    1.15      bool blacklisted = false;
    1.16      
    1.17      status = key_revoked(session, fpr, &revoked);    
    1.18 -    
    1.19 -    assert(status == PEP_STATUS_OK);
    1.20 -    
    1.21 +        
    1.22      if (status != PEP_STATUS_OK) {
    1.23          return ADD_TO_LOG(status);
    1.24      }
    1.25 @@ -230,16 +234,18 @@
    1.26                        -1, SQLITE_STATIC);
    1.27      
    1.28      const int result = sqlite3_step(session->get_user_default_key);
    1.29 -    const char* user_fpr = NULL;
    1.30 +    char* user_fpr = NULL;
    1.31      if (result == SQLITE_ROW) {
    1.32 -        user_fpr =
    1.33 +        const char* u_fpr =
    1.34              (char *) sqlite3_column_text(session->get_user_default_key, 0);
    1.35 +        if (u_fpr)
    1.36 +            user_fpr = strdup(u_fpr);
    1.37      }
    1.38      sqlite3_reset(session->get_user_default_key);
    1.39      
    1.40      if (user_fpr) {             
    1.41          // There exists a default key for user, so validate
    1.42 -        stored_identity->fpr = strdup(user_fpr);
    1.43 +        stored_identity->fpr = user_fpr;
    1.44          status = validate_fpr(session, stored_identity);
    1.45          if (status == PEP_STATUS_OK && stored_identity->fpr) {
    1.46              *is_user_default = true;
    1.47 @@ -251,24 +257,24 @@
    1.48      }
    1.49      
    1.50      status = elect_pubkey(session, stored_identity);
    1.51 +    if (status == PEP_STATUS_OK)
    1.52 +        validate_fpr(session, stored_identity);    
    1.53      
    1.54 -    if (status == PEP_STATUS_OK) {
    1.55 -        switch (stored_identity->comm_type) {
    1.56 -            case PEP_ct_key_revoked:
    1.57 -            case PEP_ct_key_b0rken:
    1.58 -            case PEP_ct_key_expired:
    1.59 -            case PEP_ct_compromized:
    1.60 -            case PEP_ct_mistrusted:
    1.61 -                // this only happens when it's all there is
    1.62 -                status = PEP_KEY_NOT_FOUND;
    1.63 -                free(stored_identity->fpr);
    1.64 -                stored_identity->fpr = NULL;
    1.65 -                stored_identity->comm_type = PEP_ct_unknown;
    1.66 -                break;
    1.67 -            default:
    1.68 -                // FIXME: blacklisting?
    1.69 -                break;
    1.70 -        }
    1.71 +    switch (stored_identity->comm_type) {
    1.72 +        case PEP_ct_key_revoked:
    1.73 +        case PEP_ct_key_b0rken:
    1.74 +        case PEP_ct_key_expired:
    1.75 +        case PEP_ct_compromized:
    1.76 +        case PEP_ct_mistrusted:
    1.77 +            // this only happens when it's all there is
    1.78 +            status = PEP_KEY_NOT_FOUND;
    1.79 +            free(stored_identity->fpr);
    1.80 +            stored_identity->fpr = NULL;
    1.81 +            stored_identity->comm_type = PEP_ct_unknown;
    1.82 +            break;
    1.83 +        default:
    1.84 +            // FIXME: blacklisting?
    1.85 +            break;
    1.86      }
    1.87      return status;
    1.88  }
    1.89 @@ -322,6 +328,9 @@
    1.90          return_id->comm_type = stored_ident->comm_type;            
    1.91      }
    1.92      else {
    1.93 +        free(return_id->fpr);
    1.94 +        return_id->fpr = NULL;
    1.95 +        return_id->comm_type = PEP_ct_key_not_found;
    1.96          return status; // Couldn't find a key.
    1.97      }
    1.98