merge
authorVolker Birk <vb@pep-project.org>
Tue, 05 May 2015 17:38:11 +0200
changeset 24712e852387299
parent 246 1546f1595882
parent 245 43b4cf6fe548
child 249 053050183172
child 253 162d1a585cf8
merge
     1.1 --- a/src/pgp_netpgp.c	Tue May 05 17:37:49 2015 +0200
     1.2 +++ b/src/pgp_netpgp.c	Tue May 05 17:38:11 2015 +0200
     1.3 @@ -523,10 +523,10 @@
     1.4      if(*str == NULL)
     1.5          return 0;
     1.6  
     1.7 -    for (n = 0, i = 0 ; i < length - 1; i += 2) {
     1.8 -    	n += snprintf(&((*str)[n]), 6, "%02x%02x ", *fpr++, *fpr++);
     1.9 +    for (n = 0, i = 0 ; i < length - 2; i += 2) {
    1.10 +    	n += snprintf(&((*str)[n]), 6, "%02x%02x ", fpr[i], fpr[i+1]);
    1.11      }
    1.12 -    snprintf(&((*str)[n]), 5, "%02x%02x", *fpr++, *fpr++);
    1.13 +    snprintf(&((*str)[n]), 5, "%02x%02x", fpr[i], fpr[i+1]);
    1.14  
    1.15      return 1;
    1.16  }
    1.17 @@ -542,9 +542,10 @@
    1.18          while (*str == ' ') str++;
    1.19          for (j = 0; j < 2; j++) {
    1.20              uint8_t *byte = &fpr[*length];
    1.21 +            *byte = 0;
    1.22              for (i = 0; i < 2; i++) {
    1.23                  if (i > 0)
    1.24 -                    *byte *= 16;
    1.25 +                    *byte = *byte << 4;
    1.26                  if (*str >= 'a' && *str <= 'f')
    1.27                      *byte += 10 + *str - 'a';
    1.28                  else if (*str >= 'A' && *str <= 'F')
    1.29 @@ -555,7 +556,7 @@
    1.30                      return 0;
    1.31                  str++;
    1.32              }
    1.33 -            *length++;
    1.34 +            (*length)++;
    1.35          }
    1.36      }
    1.37      return 1;
    1.38 @@ -565,11 +566,13 @@
    1.39      pgp_key_t	pubkey;
    1.40      unsigned public;
    1.41      PEP_STATUS result;
    1.42 +    
    1.43  
    1.44      if ((public = (newkey->type == PGP_PTAG_CT_PUBLIC_KEY))){
    1.45          pubkey = *newkey;
    1.46      } else {
    1.47          // Duplicate key as public only
    1.48 +        bzero(&pubkey, sizeof(pubkey));
    1.49          if (!pgp_keydata_dup(&pubkey, newkey, 1 /* make_public */)){
    1.50              return PEP_OUT_OF_MEMORY;
    1.51          }
    1.52 @@ -613,7 +616,6 @@
    1.53  {
    1.54      netpgp_t *netpgp;
    1.55      pgp_key_t	newkey;
    1.56 -    pgp_key_t	pubkey;
    1.57  
    1.58      PEP_STATUS result;
    1.59      char newid[1024];
    1.60 @@ -642,7 +644,6 @@
    1.61      cipher = netpgp_getvar(netpgp, "cipher");
    1.62  
    1.63      bzero(&newkey, sizeof(newkey));
    1.64 -    bzero(&pubkey, sizeof(pubkey));
    1.65  
    1.66      // Generate the key
    1.67      if (!pgp_rsa_generate_keypair(&newkey, 4096, 65537UL, hashalg, cipher,
    1.68 @@ -696,23 +697,21 @@
    1.69      netpgp = &session->ctx;
    1.70      
    1.71      if (str_to_fpr(fprstr, fpr, &length)) {
    1.72 -        if (!pgp_deletekeybyfpr(netpgp->io,
    1.73 +        unsigned insec = pgp_deletekeybyfpr(netpgp->io,
    1.74                                  (pgp_keyring_t *)netpgp->secring, 
    1.75 -                                (const uint8_t *)fpr, length)) {
    1.76 -            return PEP_KEY_NOT_FOUND;
    1.77 +                                (const uint8_t *)fpr, length);
    1.78 +        unsigned inpub = pgp_deletekeybyfpr(netpgp->io,
    1.79 +                                (pgp_keyring_t *)netpgp->pubring, 
    1.80 +                                (const uint8_t *)fpr, length);
    1.81 +        if(!insec && !inpub){
    1.82 +            result = PEP_KEY_NOT_FOUND;
    1.83 +        } else {
    1.84 +            result = PEP_STATUS_OK;
    1.85          }
    1.86      }else{
    1.87          return PEP_OUT_OF_MEMORY;
    1.88      }
    1.89  
    1.90 -    /* pair was found in secring delete also corresponding pubkey 
    1.91 -     * in pubring if it exists */
    1.92 -    if(res) {
    1.93 -        pgp_deletekeybyfpr(netpgp->io,
    1.94 -                           (pgp_keyring_t *)netpgp->pubring, 
    1.95 -                           (const uint8_t *)fpr, length);
    1.96 -    }
    1.97 -
    1.98      // save rings (key ownership transfered)
    1.99      if (netpgp_save_pubring(netpgp) && 
   1.100          netpgp_save_secring(netpgp))
   1.101 @@ -749,6 +748,8 @@
   1.102      }
   1.103      pgp_memory_add(mem, (const uint8_t*)key_data, size);
   1.104  
   1.105 +    bzero(&tmpring, sizeof(tmpring));
   1.106 +
   1.107      if (pgp_keyring_read_from_mem(netpgp->io, &tmpring, 
   1.108                                    _armoured(key_data, size, ARMOR_KEY_HEAD),
   1.109                                    mem) == 0){
   1.110 @@ -764,7 +765,9 @@
   1.111      
   1.112      pgp_memory_free(mem);
   1.113  
   1.114 -    if (result != PEP_STATUS_OK){
   1.115 +    if (result == PEP_STATUS_OK){
   1.116 +        pgp_keyring_free(&tmpring);
   1.117 +    }else{
   1.118          pgp_keyring_purge(&tmpring);
   1.119      }
   1.120  
   1.121 @@ -787,13 +790,13 @@
   1.122      size_t buflen;
   1.123  
   1.124      assert(session);
   1.125 -    assert(fpr);
   1.126 +    assert(fprstr);
   1.127      assert(key_data);
   1.128      assert(size);
   1.129  
   1.130      netpgp = &session->ctx;
   1.131  
   1.132 -    if (!session || !fpr || !key_data || !size)
   1.133 +    if (!session || !fprstr || !key_data || !size)
   1.134          return PEP_UNKNOWN_ERROR;
   1.135  
   1.136      if (str_to_fpr(fprstr, fpr, &fprlen)) {
     2.1 --- a/test/pEpEngineTest.cc	Tue May 05 17:37:49 2015 +0200
     2.2 +++ b/test/pEpEngineTest.cc	Tue May 05 17:38:11 2015 +0200
     2.3 @@ -202,6 +202,7 @@
     2.4  
     2.5      cout << "export_key()\n\n";
     2.6      PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
     2.7 +    cout << "export_key() exits with " << export_status << "\n";
     2.8      assert(export_status == PEP_STATUS_OK);
     2.9      cout << key_data << "\n\n";
    2.10