stowing changes to check against default ENGINE-74
authorKrista Grothoff <krista@pep-project.org>
Thu, 17 Nov 2016 13:10:26 +0100
branchENGINE-74
changeset 14267a1d5065841b
parent 1399 b77bc137c471
child 1427 72c2539b14e7
stowing changes to check against default
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Tue Nov 15 21:52:46 2016 +0100
     1.2 +++ b/src/pgp_gpg.c	Thu Nov 17 13:10:26 2016 +0100
     1.3 @@ -39,10 +39,10 @@
     1.4                length <= sizeof(unsigned int) * CHAR_BIT)) {
     1.5              r = Fclose(f);
     1.6              assert(r == 0);
     1.7 -        
     1.8 +
     1.9              return false;
    1.10          }
    1.11 -        
    1.12 +
    1.13          do {
    1.14              char * s;
    1.15  
    1.16 @@ -98,7 +98,7 @@
    1.17      PEP_STATUS status = PEP_STATUS_OK;
    1.18      gpgme_error_t gpgme_error;
    1.19      bool bResult;
    1.20 -    
    1.21 +
    1.22      if (in_first) {
    1.23          stringlist_t *conf_keys   = new_stringlist("keyserver");
    1.24          stringlist_t *conf_values = new_stringlist("hkp://keys.gnupg.net");
    1.25 @@ -338,7 +338,7 @@
    1.26          assert(gpg.gpgme_io_write);
    1.27  
    1.28          gpg.version = gpg.gpgme_check(NULL);
    1.29 -        
    1.30 +
    1.31          const char * const cLocal = setlocale(LC_ALL, NULL);
    1.32          if (!cLocal || (strcmp(cLocal, "C") == 0))
    1.33              setlocale(LC_ALL, "");
    1.34 @@ -349,6 +349,7 @@
    1.35  #endif
    1.36      }
    1.37  
    1.38 +    gpg.gpgme_check(NULL);
    1.39      gpgme_error = gpg.gpgme_new(&session->ctx);
    1.40      gpgme_error = _GPGERR(gpgme_error);
    1.41      if (gpgme_error != GPG_ERR_NO_ERROR) {
    1.42 @@ -432,8 +433,14 @@
    1.43      switch (dt) {
    1.44      case GPGME_DATA_TYPE_PGP_SIGNED:
    1.45      case GPGME_DATA_TYPE_PGP_OTHER:
    1.46 -        gpgme_error = gpg.gpgme_op_decrypt_verify(session->ctx, cipher,
    1.47 -            plain);
    1.48 + //   case GPGME_DATA_TYPE_PGP_ENCRYPTED:
    1.49 +        if (dsigtext) {
    1.50 +            gpgme_error = gpg.gpgme_op_decrypt(session->ctx, cipher, plain);
    1.51 +        }
    1.52 +        else {
    1.53 +            gpgme_error = gpg.gpgme_op_decrypt_verify(session->ctx, cipher,
    1.54 +                plain);
    1.55 +        }
    1.56          gpgme_error = _GPGERR(gpgme_error);
    1.57          assert(gpgme_error != GPG_ERR_INV_VALUE);
    1.58          assert(gpgme_error != GPG_ERR_NO_DATA);
    1.59 @@ -441,6 +448,12 @@
    1.60          switch (gpgme_error) {
    1.61              case GPG_ERR_NO_ERROR:
    1.62              {
    1.63 +                if (dsigtext) {
    1.64 +                    gpgme_data_t sigdata;
    1.65 +                    gpg.gpgme_data_new_from_mem(&sigdata, dsigtext,
    1.66 +                                                dsigsize, 0);
    1.67 +                    gpgme_op_verify(session->ctx, sigdata, plain, NULL);
    1.68 +                }
    1.69                  gpgme_verify_result_t gpgme_verify_result;
    1.70                  char *_buffer = NULL;
    1.71                  size_t reading;
    1.72 @@ -471,23 +484,23 @@
    1.73  //                                                 dsigsize, 0);
    1.74  //                     gpgme_op_verify(session->ctx, sigdata, plain, NULL);
    1.75  //                 }
    1.76 -                
    1.77 +
    1.78                  gpgme_verify_result =
    1.79                      gpg.gpgme_op_verify_result(session->ctx);
    1.80                  assert(gpgme_verify_result);
    1.81                  gpgme_signature = gpgme_verify_result->signatures;
    1.82  
    1.83 -                if (!gpgme_signature && dsigtext) {
    1.84 -                    gpgme_data_t sigdata;
    1.85 -                    gpg.gpgme_data_new_from_mem(&sigdata, dsigtext,
    1.86 -                                                dsigsize, 0);
    1.87 -                    gpgme_op_verify(session->ctx, sigdata, plain, NULL);
    1.88 -                    gpgme_verify_result =
    1.89 -                        gpg.gpgme_op_verify_result(session->ctx);
    1.90 -                    assert(gpgme_verify_result);
    1.91 -                    gpgme_signature = gpgme_verify_result->signatures;
    1.92 -                }
    1.93 -                
    1.94 +//                 if (!gpgme_signature && dsigtext) {
    1.95 +//                     gpgme_data_t sigdata;
    1.96 +//                     gpg.gpgme_data_new_from_mem(&sigdata, dsigtext,
    1.97 +//                                                 dsigsize, 0);
    1.98 +//                     gpgme_op_verify(session->ctx, sigdata, plain, NULL);
    1.99 +//                     gpgme_verify_result =
   1.100 +//                         gpg.gpgme_op_verify_result(session->ctx);
   1.101 +//                     assert(gpgme_verify_result);
   1.102 +//                     gpgme_signature = gpgme_verify_result->signatures;
   1.103 +//                 }
   1.104 +
   1.105                  if (gpgme_signature) {
   1.106                      stringlist_t *k;
   1.107                      _keylist = new_stringlist(NULL);
   1.108 @@ -505,10 +518,10 @@
   1.109                          switch (_GPGERR(gpgme_signature->status)) {
   1.110                          case GPG_ERR_NO_ERROR:
   1.111                          {
   1.112 -                            // Some versions of gpg returns signer's 
   1.113 +                            // Some versions of gpg returns signer's
   1.114                              // signing subkey fingerprint instead of
   1.115                              // signer's primary key fingerprint.
   1.116 -                            // This is meant to get signer's primary 
   1.117 +                            // This is meant to get signer's primary
   1.118                              // key fingerprint, using subkey's.
   1.119  
   1.120                              gpgme_key_t key = NULL;
   1.121 @@ -525,8 +538,8 @@
   1.122                                  return PEP_OUT_OF_MEMORY;
   1.123                              }
   1.124                              // Primary key is given as the first subkey
   1.125 -                            if (gpgme_error == GPG_ERR_NO_ERROR &&  
   1.126 -                                key && key->subkeys && key->subkeys->fpr 
   1.127 +                            if (gpgme_error == GPG_ERR_NO_ERROR &&
   1.128 +                                key && key->subkeys && key->subkeys->fpr
   1.129                                  && key->subkeys->fpr[0])
   1.130                              {
   1.131                                  k = stringlist_add(k, key->subkeys->fpr);
   1.132 @@ -541,7 +554,7 @@
   1.133                                      return PEP_OUT_OF_MEMORY;
   1.134                                  }
   1.135                              }
   1.136 -                            else 
   1.137 +                            else
   1.138                              {
   1.139                                  result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
   1.140                                  break;
   1.141 @@ -709,7 +722,7 @@
   1.142                  gpgme_key_t key;
   1.143                  memset(&key,0,sizeof(key));
   1.144  
   1.145 -                // GPGME may give subkey's fpr instead of primary key's fpr. 
   1.146 +                // GPGME may give subkey's fpr instead of primary key's fpr.
   1.147                  // Therefore we ask for the primary fingerprint instead
   1.148                  // we assume that gpgme_get_key can find key by subkey's fpr
   1.149                  gpgme_error = gpg.gpgme_get_key(session->ctx,
   1.150 @@ -723,8 +736,8 @@
   1.151                      return PEP_OUT_OF_MEMORY;
   1.152                  }
   1.153                  // Primary key is given as the first subkey
   1.154 -                if (gpgme_error == GPG_ERR_NO_ERROR &&  
   1.155 -                    key && key->subkeys && key->subkeys->fpr 
   1.156 +                if (gpgme_error == GPG_ERR_NO_ERROR &&
   1.157 +                    key && key->subkeys && key->subkeys->fpr
   1.158                      && key->subkeys->fpr[0])
   1.159                  {
   1.160                      k = stringlist_add(k, key->subkeys->fpr);
   1.161 @@ -1075,8 +1088,8 @@
   1.162  
   1.163      assert(session);
   1.164      assert(key_data);
   1.165 -   
   1.166 -    if(private_idents) 
   1.167 +
   1.168 +    if(private_idents)
   1.169          *private_idents = NULL;
   1.170  
   1.171      gpgme_error = gpg.gpgme_data_new_from_mem(&dh, key_data, size, 0);
   1.172 @@ -1101,7 +1114,7 @@
   1.173      gpgme_error = _GPGERR(gpgme_error);
   1.174      switch (gpgme_error) {
   1.175      case GPG_ERR_NO_ERROR:
   1.176 -        if(private_idents) 
   1.177 +        if(private_idents)
   1.178          {
   1.179              gpgme_import_result =
   1.180                  gpg.gpgme_op_import_result(session->ctx);
   1.181 @@ -1112,8 +1125,8 @@
   1.182              }
   1.183  
   1.184              gpgme_import_status_t import;
   1.185 -            for (import = gpgme_import_result->imports; 
   1.186 -                 import; 
   1.187 +            for (import = gpgme_import_result->imports;
   1.188 +                 import;
   1.189                   import = import->next)
   1.190               {
   1.191                  if (import &&
   1.192 @@ -1130,9 +1143,9 @@
   1.193                          gpg.gpgme_data_release(dh);
   1.194                          return PEP_OUT_OF_MEMORY;
   1.195                      }
   1.196 -                    
   1.197 -                    if (gpgme_error == GPG_ERR_NO_ERROR &&  
   1.198 -                        key && key->uids && 
   1.199 +
   1.200 +                    if (gpgme_error == GPG_ERR_NO_ERROR &&
   1.201 +                        key && key->uids &&
   1.202                          key->uids->email && key->uids->name)
   1.203                      {
   1.204                          pEp_identity *ident = new_identity(
   1.205 @@ -1152,7 +1165,7 @@
   1.206                              return PEP_OUT_OF_MEMORY;
   1.207                          }
   1.208                      }
   1.209 -                    else 
   1.210 +                    else
   1.211                      {
   1.212                          gpg.gpgme_key_unref(key);
   1.213                          gpg.gpgme_data_release(dh);
   1.214 @@ -1258,21 +1271,21 @@
   1.215      return PEP_STATUS_OK;
   1.216  }
   1.217  
   1.218 -PEP_STATUS pgp_list_keyinfo(PEP_SESSION session, const char* pattern, 
   1.219 +PEP_STATUS pgp_list_keyinfo(PEP_SESSION session, const char* pattern,
   1.220                              stringpair_list_t** keyinfo_list)
   1.221 -{    
   1.222 +{
   1.223      gpgme_error_t gpgme_error;
   1.224      assert(session);
   1.225      assert(keyinfo_list);
   1.226 -    
   1.227 +
   1.228      if (!session || !keyinfo_list)
   1.229          return PEP_ILLEGAL_VALUE;
   1.230 -    
   1.231 +
   1.232      *keyinfo_list = NULL;
   1.233 -    
   1.234 +
   1.235      gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, pattern, 0);
   1.236      gpgme_error = _GPGERR(gpgme_error);
   1.237 -    
   1.238 +
   1.239      switch(gpgme_error) {
   1.240          case GPG_ERR_NO_ERROR:
   1.241              break;
   1.242 @@ -1281,18 +1294,18 @@
   1.243              return PEP_UNKNOWN_ERROR;
   1.244          default:
   1.245              gpg.gpgme_op_keylist_end(session->ctx);
   1.246 -            return PEP_GET_KEY_FAILED;        
   1.247 +            return PEP_GET_KEY_FAILED;
   1.248      };
   1.249 -    
   1.250 +
   1.251      gpgme_key_t key;
   1.252      stringpair_list_t* _keyinfo_list = new_stringpair_list(NULL);
   1.253      stringpair_list_t* list_curr = _keyinfo_list;
   1.254      stringpair_t* pair = NULL;
   1.255 -        
   1.256 -    do { 
   1.257 +
   1.258 +    do {
   1.259          gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
   1.260          gpgme_error = _GPGERR(gpgme_error);
   1.261 -      
   1.262 +
   1.263          switch(gpgme_error) {
   1.264              case GPG_ERR_EOF:
   1.265                  break;
   1.266 @@ -1310,18 +1323,18 @@
   1.267                  assert(uid);
   1.268                  if (!fpr)
   1.269                      return PEP_GET_KEY_FAILED;
   1.270 -                
   1.271 +
   1.272                  if (key->subkeys->revoked)
   1.273                      continue;
   1.274 -                
   1.275 +
   1.276                  pair = new_stringpair(fpr, uid);
   1.277  
   1.278                  assert(pair);
   1.279 -                
   1.280 +
   1.281                  if (pair) {
   1.282                      list_curr = stringpair_list_add(list_curr, pair);
   1.283                      pair = NULL;
   1.284 -                    
   1.285 +
   1.286                      assert(list_curr);
   1.287                      if (list_curr != NULL)
   1.288                          break;
   1.289 @@ -1338,14 +1351,14 @@
   1.290                  return PEP_UNKNOWN_ERROR;
   1.291          }
   1.292      } while (gpgme_error != GPG_ERR_EOF);
   1.293 -    
   1.294 +
   1.295      if (_keyinfo_list->value == NULL) {
   1.296          free_stringpair_list(_keyinfo_list);
   1.297          _keyinfo_list = NULL;
   1.298      }
   1.299 -    
   1.300 +
   1.301      *keyinfo_list = _keyinfo_list;
   1.302 -    
   1.303 +
   1.304      return PEP_STATUS_OK;
   1.305  }
   1.306  
   1.307 @@ -1440,13 +1453,13 @@
   1.308                              int private_only) {
   1.309      gpgme_error_t gpgme_error;
   1.310      gpgme_key_t key;
   1.311 -    
   1.312 +
   1.313      assert(session);
   1.314      assert(pattern);
   1.315      assert(keylist);
   1.316 -    
   1.317 +
   1.318      *keylist = NULL;
   1.319 -    
   1.320 +
   1.321      gpgme_error = gpg.gpgme_op_keylist_start(session->ctx, pattern, private_only);
   1.322      gpgme_error = _GPGERR(gpgme_error);
   1.323      switch (gpgme_error) {
   1.324 @@ -1459,10 +1472,10 @@
   1.325              gpg.gpgme_op_keylist_end(session->ctx);
   1.326              return PEP_GET_KEY_FAILED;
   1.327      };
   1.328 -    
   1.329 +
   1.330      stringlist_t *_keylist = new_stringlist(NULL);
   1.331      stringlist_t *_k = _keylist;
   1.332 -    
   1.333 +
   1.334      do {
   1.335          gpgme_error = gpg.gpgme_op_keylist_next(session->ctx, &key);
   1.336          gpgme_error = _GPGERR(gpgme_error);
   1.337 @@ -1488,7 +1501,7 @@
   1.338                  return PEP_UNKNOWN_ERROR;
   1.339          };
   1.340      } while (gpgme_error != GPG_ERR_EOF);
   1.341 -    
   1.342 +
   1.343      gpg.gpgme_op_keylist_end(session->ctx);
   1.344      if (_keylist->value == NULL) {
   1.345          free_stringlist(_keylist);
   1.346 @@ -1503,7 +1516,7 @@
   1.347      )
   1.348  {
   1.349      return _pgp_search_keys(session, pattern, keylist, 0);
   1.350 -}    
   1.351 +}
   1.352  
   1.353  PEP_STATUS pgp_find_private_keys(
   1.354      PEP_SESSION session, const char *pattern, stringlist_t **keylist
   1.355 @@ -2182,4 +2195,3 @@
   1.356      }
   1.357      return status;
   1.358  }
   1.359 -