src/keymanagement.c
changeset 1506 fc7d96185247
parent 1502 ab5de5449d7d
child 1508 ab010a3b7894
child 1533 ca90b6245a51
     1.1 --- a/src/keymanagement.c	Tue Dec 20 17:50:56 2016 +0100
     1.2 +++ b/src/keymanagement.c	Tue Dec 20 22:51:41 2016 +0100
     1.3 @@ -148,37 +148,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          }