netpgp: fixes in delete_keypair and import_keydata
authorEdouard Tisserant
Tue, 05 May 2015 17:23:38 +0200
changeset 24436abc78b7de5
parent 243 c38813173fc7
child 245 43b4cf6fe548
netpgp: fixes in delete_keypair and import_keydata
src/pgp_netpgp.c
     1.1 --- a/src/pgp_netpgp.c	Mon May 04 16:08:27 2015 +0200
     1.2 +++ b/src/pgp_netpgp.c	Tue May 05 17:23:38 2015 +0200
     1.3 @@ -697,23 +697,21 @@
     1.4      netpgp = &session->ctx;
     1.5      
     1.6      if (str_to_fpr(fprstr, fpr, &length)) {
     1.7 -        if (!pgp_deletekeybyfpr(netpgp->io,
     1.8 +        unsigned insec = pgp_deletekeybyfpr(netpgp->io,
     1.9                                  (pgp_keyring_t *)netpgp->secring, 
    1.10 -                                (const uint8_t *)fpr, length)) {
    1.11 -            return PEP_KEY_NOT_FOUND;
    1.12 +                                (const uint8_t *)fpr, length);
    1.13 +        unsigned inpub = pgp_deletekeybyfpr(netpgp->io,
    1.14 +                                (pgp_keyring_t *)netpgp->pubring, 
    1.15 +                                (const uint8_t *)fpr, length);
    1.16 +        if(!insec && !inpub){
    1.17 +            result = PEP_KEY_NOT_FOUND;
    1.18 +        } else {
    1.19 +            result = PEP_STATUS_OK;
    1.20          }
    1.21      }else{
    1.22          return PEP_OUT_OF_MEMORY;
    1.23      }
    1.24  
    1.25 -    /* pair was found in secring delete also corresponding pubkey 
    1.26 -     * in pubring if it exists */
    1.27 -    if(res) {
    1.28 -        pgp_deletekeybyfpr(netpgp->io,
    1.29 -                           (pgp_keyring_t *)netpgp->pubring, 
    1.30 -                           (const uint8_t *)fpr, length);
    1.31 -    }
    1.32 -
    1.33      // save rings (key ownership transfered)
    1.34      if (netpgp_save_pubring(netpgp) && 
    1.35          netpgp_save_secring(netpgp))
    1.36 @@ -750,6 +748,8 @@
    1.37      }
    1.38      pgp_memory_add(mem, (const uint8_t*)key_data, size);
    1.39  
    1.40 +    bzero(&tmpring, sizeof(tmpring));
    1.41 +
    1.42      if (pgp_keyring_read_from_mem(netpgp->io, &tmpring, 
    1.43                                    _armoured(key_data, size, ARMOR_KEY_HEAD),
    1.44                                    mem) == 0){
    1.45 @@ -765,7 +765,9 @@
    1.46      
    1.47      pgp_memory_free(mem);
    1.48  
    1.49 -    if (result != PEP_STATUS_OK){
    1.50 +    if (result == PEP_STATUS_OK){
    1.51 +        pgp_keyring_free(&tmpring);
    1.52 +    }else{
    1.53          pgp_keyring_purge(&tmpring);
    1.54      }
    1.55