src/keymanagement.c
branchENGINE-209
changeset 1791 0253b2e1b8ff
parent 1765 1693d16c36ea
child 1793 74cf3813c28e
     1.1 --- a/src/keymanagement.c	Mon May 15 15:02:46 2017 +0200
     1.2 +++ b/src/keymanagement.c	Wed May 17 13:34:55 2017 +0200
     1.3 @@ -144,6 +144,19 @@
     1.4  
     1.5          /* if we have a stored_identity fpr */
     1.6          if (!EMPTYSTR(stored_identity->fpr)) {
     1.7 +            bool revoked = false;
     1.8 +            status = key_revoked(session, stored_identity->fpr, &revoked);
     1.9 +            
    1.10 +            if (status != PEP_STATUS_OK || revoked)
    1.11 +                dont_use_stored_fpr = true;
    1.12 +                
    1.13 +            if (revoked) {
    1.14 +                // Do stuff
    1.15 +                status = change_key_comm_type(session, fpr, PEP_ct_key_revoked);
    1.16 +                // What to do on failure? FIXME
    1.17 +                status = remove_key_as_id_default(session, fpr);
    1.18 +            }
    1.19 +                
    1.20              status = blacklist_is_listed(session, stored_identity->fpr, &dont_use_stored_fpr);
    1.21              if (status != PEP_STATUS_OK)
    1.22                  dont_use_stored_fpr = true; 
    1.23 @@ -1048,3 +1061,60 @@
    1.24  
    1.25      return session->cryptotech[PEP_crypt_OpenPGP].contains_priv_key(session, fpr, has_private);
    1.26  }
    1.27 +
    1.28 +static PEP_STATUS change_key_comm_type(PEP_SESSION session, 
    1.29 +                                       const char* fpr,
    1.30 +                                       PEP_comm_type comm_type) {
    1.31 +                                           
    1.32 +    // get all user ids associated with this key
    1.33 +    stringlist_t* user_id_list = NULL;
    1.34 +    
    1.35 +    PEP_STATUS status = get_key_userids(session, fpr, &user_id_list);
    1.36 +    
    1.37 +    if (status != PEP_STATUS_OK) {
    1.38 +        free_stringlist(user_id_list);
    1.39 +        return status;
    1.40 +    }
    1.41 +        
    1.42 +    if (!user_id_list || !user_id_list->value())
    1.43 +        return PEP_KEY_NOT_FOUND;
    1.44 +        
    1.45 +    stringlist_t* curr_id = user_id_list;
    1.46 +    
    1.47 +    while (curr_id) {
    1.48 +        status = set_trust(session, curr_id->value, fpr, comm_type);
    1.49 +        if (status != PEP_STATUS_OK) {
    1.50 +            free_stringlist(user_id_list);
    1.51 +            return status;
    1.52 +        }
    1.53 +        curr_id = curr_id->next;
    1.54 +    }
    1.55 +    
    1.56 +    return PEP_STATUS_OK;
    1.57 +}
    1.58 +
    1.59 +static PEP_STATUS remove_key_as_id_default(PEP_SESSIONS session, 
    1.60 +                                           const char* fpr)
    1.61 +{
    1.62 +    identity_list* affected_ids = NULL;
    1.63 +    
    1.64 +    PEP_STATUS status get_identities_by_fpr(session, fpr, &identity_list);
    1.65 +    
    1.66 +    if (status != PEP_STATUS_OK) {
    1.67 +        free_identity_list(affected_ids);
    1.68 +        return status;
    1.69 +    }
    1.70 +    if (!affected_ids)
    1.71 +        return PEP_STATUS_OK; // it's fine if none are found;
    1.72 +        
    1.73 +    identity_list* curr_identity = affected_ids;
    1.74 +    
    1.75 +    while (curr_identity) {
    1.76 +        free(curr_identity->fpr);
    1.77 +        curr_identity->fpr = (char*)calloc(1, sizeof(char)); // ""
    1.78 +        set_identity(session, curr_identity);
    1.79 +        curr_identity = curr_identity->next;
    1.80 +    }
    1.81 +    
    1.82 +    
    1.83 +}