ENGINE-137 (fixing side effect of optimization) update_identity: added key re-election when a key has been deleted from keyring. fixed test blacklist_accept_new_key_test using that feature
authorEdouard Tisserant <edouard@pep-project.org>
Tue, 20 Dec 2016 22:51:41 +0100
changeset 152257c2dbcb70dd
parent 1521 48efea61cfcd
child 1523 bc4a9401af51
child 1525 9c91cb1eb4b2
ENGINE-137 (fixing side effect of optimization) update_identity: added key re-election when a key has been deleted from keyring. fixed test blacklist_accept_new_key_test using that feature
src/keymanagement.c
test/blacklist_accept_new_key_test.cc
     1.1 --- a/src/keymanagement.c	Thu Jan 05 13:07:31 2017 +0100
     1.2 +++ b/src/keymanagement.c	Tue Dec 20 22:51:41 2016 +0100
     1.3 @@ -151,37 +151,48 @@
     1.4              
     1.5  
     1.6          if (!dont_use_stored_fpr) {
     1.7 -            temp_id->fpr = strdup(stored_identity->fpr);
     1.8 -            assert(temp_id->fpr);
     1.9 -            if (temp_id->fpr == NULL) {
    1.10 -                status = PEP_OUT_OF_MEMORY;
    1.11 +            /* Check stored comm_type */
    1.12 +            PEP_comm_type _comm_type_key;
    1.13 +            status = get_key_rating(session, stored_identity->fpr, &_comm_type_key);
    1.14 +            assert(status != PEP_OUT_OF_MEMORY);
    1.15 +            if (status == PEP_OUT_OF_MEMORY) {
    1.16                  goto exit_free;
    1.17              }
    1.18 +            if (status == PEP_KEY_NOT_FOUND){
    1.19 +                /* stored key was deleted from keyring. any other candidate ?*/
    1.20 +                status = elect_pubkey(session, temp_id);
    1.21 +                if (status != PEP_STATUS_OK) {
    1.22 +                    goto exit_free;
    1.23 +                } else {
    1.24 +                    _did_elect_new_key = 1;
    1.25 +                }
    1.26 +            } else {
    1.27 +                temp_id->fpr = strdup(stored_identity->fpr);
    1.28 +                assert(temp_id->fpr);
    1.29 +                if (temp_id->fpr == NULL) {
    1.30 +                    status = PEP_OUT_OF_MEMORY;
    1.31 +                    goto exit_free;
    1.32 +                }
    1.33  
    1.34 -            /* Check stored comm_type */
    1.35 -            PEP_comm_type _comm_type_key;
    1.36 -            status = get_key_rating(session, temp_id->fpr, &_comm_type_key);
    1.37 -            assert(status != PEP_OUT_OF_MEMORY);
    1.38 -            if (status == PEP_OUT_OF_MEMORY)
    1.39 -                goto exit_free;
    1.40 -            if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
    1.41 -                /* if key not good anymore, 
    1.42 -                   downgrade eventually trusted comm_type */
    1.43 -                temp_id->comm_type = _comm_type_key;
    1.44 -            } else {
    1.45 -                /* otherwise take stored comm_type as-is */
    1.46 -                temp_id->comm_type = stored_identity->comm_type;
    1.47 -                if (temp_id->comm_type == PEP_ct_unknown) {
    1.48 -                    /* except if unknown */
    1.49 +                if (_comm_type_key < PEP_ct_unconfirmed_encryption) {
    1.50 +                    /* if key not good anymore, 
    1.51 +                       downgrade eventually trusted comm_type */
    1.52                      temp_id->comm_type = _comm_type_key;
    1.53 +                } else {
    1.54 +                    /* otherwise take stored comm_type as-is */
    1.55 +                    temp_id->comm_type = stored_identity->comm_type;
    1.56 +                    if (temp_id->comm_type == PEP_ct_unknown) {
    1.57 +                        /* except if unknown */
    1.58 +                        temp_id->comm_type = _comm_type_key;
    1.59 +                    }
    1.60                  }
    1.61              }
    1.62          }
    1.63          else {
    1.64              status = elect_pubkey(session, temp_id);
    1.65 -            if (status != PEP_STATUS_OK)
    1.66 +            if (status != PEP_STATUS_OK){
    1.67                  goto exit_free;
    1.68 -            else {
    1.69 +            } else {
    1.70                  _did_elect_new_key = 1;
    1.71              }
    1.72          }
     2.1 --- a/test/blacklist_accept_new_key_test.cc	Thu Jan 05 13:07:31 2017 +0100
     2.2 +++ b/test/blacklist_accept_new_key_test.cc	Tue Dec 20 22:51:41 2016 +0100
     2.3 @@ -89,10 +89,10 @@
     2.4      PEP_STATUS status13 = blacklist_delete(session, bl_fpr_1);
     2.5      PEP_STATUS status14 = update_identity(session, blacklisted_identity);
     2.6  
     2.7 +    status = delete_keypair(session, new_key);
     2.8 +    update_identity(session, blacklisted_identity);
     2.9      status = delete_keypair(session, bl_fpr_1);
    2.10      update_identity(session, blacklisted_identity);
    2.11 -    status = delete_keypair(session, new_key);
    2.12 -    update_identity(session, blacklisted_identity);
    2.13      
    2.14      free_message(msg_ptr);
    2.15      free_message(dest_msg);