pgp_..port_key -> pgp_..port_keydata to avoid conflict with netpgp
authorEdouard Tisserant
Fri, 03 Apr 2015 15:41:59 +0200
changeset 179112fadcf74b9
parent 178 77d056daf06d
parent 170 de3f8287972e
child 180 6008e35e7735
pgp_..port_key -> pgp_..port_keydata to avoid conflict with netpgp
src/pgp_gpg.c
src/pgp_netpgp.c
src/pgp_netpgp.h
     1.1 --- a/src/cryptotech.c	Thu Apr 02 16:19:23 2015 +0200
     1.2 +++ b/src/cryptotech.c	Fri Apr 03 15:41:59 2015 +0200
     1.3 @@ -31,11 +31,11 @@
     1.4          cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
     1.5          cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
     1.6          cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
     1.7 -        cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_key;
     1.8 +        cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_keydata;
     1.9          cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
    1.10          cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
    1.11          cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
    1.12 -        cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_key;
    1.13 +        cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_keydata;
    1.14          cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
    1.15          cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
    1.16      }
     2.1 --- a/src/pgp_gpg.c	Thu Apr 02 16:19:23 2015 +0200
     2.2 +++ b/src/pgp_gpg.c	Fri Apr 03 15:41:59 2015 +0200
     2.3 @@ -909,7 +909,7 @@
     2.4      return PEP_STATUS_OK;
     2.5  }
     2.6  
     2.7 -PEP_STATUS pgp_import_key(PEP_SESSION session, const char *key_data, size_t size)
     2.8 +PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data, size_t size)
     2.9  {
    2.10      gpgme_error_t gpgme_error;
    2.11      gpgme_data_t dh;
    2.12 @@ -955,7 +955,7 @@
    2.13      return PEP_STATUS_OK;
    2.14  }
    2.15  
    2.16 -PEP_STATUS pgp_export_key(
    2.17 +PEP_STATUS pgp_export_keydata(
    2.18      PEP_SESSION session, const char *fpr, char **key_data, size_t *size
    2.19      )
    2.20  {
     3.1 --- a/src/pgp_gpg.h	Thu Apr 02 16:19:23 2015 +0200
     3.2 +++ b/src/pgp_gpg.h	Fri Apr 03 15:41:59 2015 +0200
     3.3 @@ -22,7 +22,7 @@
     3.4  
     3.5  PEP_STATUS pgp_delete_keypair(PEP_SESSION session, const char *fpr);
     3.6  
     3.7 -PEP_STATUS pgp_export_key(
     3.8 +PEP_STATUS pgp_export_keydata(
     3.9          PEP_SESSION session, const char *fpr, char **key_data, size_t *size
    3.10      );
    3.11  
    3.12 @@ -40,7 +40,7 @@
    3.13          PEP_comm_type *comm_type
    3.14      );
    3.15  
    3.16 -PEP_STATUS pgp_import_key(PEP_SESSION session, const char *key_data,
    3.17 +PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
    3.18          size_t size);
    3.19  
    3.20  PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern);
     4.1 --- a/src/pgp_netpgp.c	Thu Apr 02 16:19:23 2015 +0200
     4.2 +++ b/src/pgp_netpgp.c	Fri Apr 03 15:41:59 2015 +0200
     4.3 @@ -6,35 +6,45 @@
     4.4  #include "wrappers.h"
     4.5  
     4.6  #include <netpgp.h>
     4.7 +#include <netpgp/config.h>
     4.8 +#include <netpgp/memory.h>
     4.9 +#include <netpgp/crypto.h>
    4.10 +
    4.11  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
    4.12  {
    4.13 +    netpgp_t *netpgp;
    4.14      PEP_STATUS status = PEP_STATUS_OK;
    4.15      const char *home = NULL;
    4.16 +
    4.17 +    assert(session);
    4.18 +    if(!session) return PEP_UNKNOWN_ERROR;
    4.19 +
    4.20 +    netpgp = &session->ctx;
    4.21     
    4.22      if (in_first) {
    4.23          if (strcmp(setlocale(LC_ALL, NULL), "C") == 0)
    4.24              setlocale(LC_ALL, "");
    4.25      }
    4.26  
    4.27 -	memset(&session->ctx, 0x0, sizeof(session->ctx));
    4.28 +	memset(netpgp, 0x0, sizeof(session->ctx));
    4.29  
    4.30      // NetPGP shares home with GPG
    4.31      home = gpg_home();
    4.32      if(home){
    4.33 -        netpgp_set_homedir(&session->ctx,(char*)home, NULL, 0);
    4.34 +        netpgp_set_homedir(netpgp,(char*)home, NULL, 0);
    4.35      }else{
    4.36          status = PEP_INIT_NO_GPG_HOME;
    4.37          goto pep_error;
    4.38      }
    4.39  
    4.40      // pair with gpg's cert-digest-algo
    4.41 -	netpgp_setvar(&session->ctx, "hash", "SHA256");
    4.42 +	netpgp_setvar(netpgp, "hash", "SHA256");
    4.43  
    4.44      // subset of gpg's personal-cipher-preferences
    4.45      // here only one cipher can be selected
    4.46 -    netpgp_setvar(&session->ctx, "cipher", "AES256");
    4.47 +    netpgp_setvar(netpgp, "cipher", "AES256");
    4.48  
    4.49 -	if (!netpgp_init(&session->ctx)) {
    4.50 +	if (!netpgp_init(netpgp)) {
    4.51          status = PEP_INIT_NETPGP_INIT_FAILED;
    4.52          goto pep_error;
    4.53      }
    4.54 @@ -48,8 +58,15 @@
    4.55  
    4.56  void pgp_release(PEP_SESSION session, bool out_last)
    4.57  {
    4.58 -	netpgp_end(&session->ctx);
    4.59 -	memset(&session->ctx, 0x0, sizeof(session->ctx));
    4.60 +    netpgp_t *netpgp;
    4.61 +
    4.62 +    assert(session);
    4.63 +    if(!session) return;
    4.64 +
    4.65 +    netpgp = &session->ctx;
    4.66 +
    4.67 +	netpgp_end(netpgp);
    4.68 +	memset(netpgp, 0x0, sizeof(session->ctx));
    4.69  
    4.70      // out_last unused here
    4.71  }
    4.72 @@ -59,8 +76,11 @@
    4.73      char **ptext, size_t *psize, stringlist_t **keylist
    4.74      )
    4.75  {
    4.76 +    netpgp_t *netpgp;
    4.77 +	pgp_memory_t *mem;
    4.78 +	pgp_io_t *io;
    4.79 +
    4.80      PEP_STATUS result;
    4.81 -
    4.82      stringlist_t *_keylist = NULL;
    4.83      int i_key = 0;
    4.84  
    4.85 @@ -71,11 +91,34 @@
    4.86      assert(psize);
    4.87      assert(keylist);
    4.88  
    4.89 +    if(!session || !ctext || !csize || !ptext || !psize || !keylist) 
    4.90 +        return PEP_UNKNOWN_ERROR;
    4.91 +
    4.92 +    netpgp = &session->ctx;
    4.93 +	io = netpgp->io;
    4.94 +
    4.95      *ptext = NULL;
    4.96      *psize = 0;
    4.97      *keylist = NULL;
    4.98  
    4.99 -    /* TODO identify cipher text */
   4.100 +    mem = pgp_decrypt_buf(netpgp->io, ctext, csize,
   4.101 +                netpgp->secring, netpgp->pubring,
   4.102 +                1 /* armoured */,
   4.103 +                0 /* sshkeys */,
   4.104 +                NULL, 0, NULL /* pass fp,attempts,cb */);
   4.105 +    if (mem == NULL) {
   4.106 +        return PEP_OUT_OF_MEMORY;
   4.107 +    }
   4.108 +
   4.109 +	*psize = pgp_mem_len(mem);
   4.110 +	if ((ptext = calloc(1, *psize)) == NULL) {
   4.111 +        return PEP_OUT_OF_MEMORY;
   4.112 +	}
   4.113 +	memcpy(*ptext, pgp_mem_data(mem), *psize);
   4.114 +	pgp_memory_free(mem);
   4.115 +
   4.116 +    result = PEP_DECRYPTED;
   4.117 +
   4.118      /* if recognized */
   4.119      /* decrypt */
   4.120      /* if OK, verify */
   4.121 @@ -87,18 +130,18 @@
   4.122      result = PEP_DECRYPT_NO_KEY;
   4.123      return PEP_OUT_OF_MEMORY;
   4.124      */
   4.125 -    result = PEP_UNKNOWN_ERROR;
   4.126 -                stringlist_t *k;
   4.127 -                _keylist = new_stringlist(NULL);
   4.128 -                assert(_keylist);
   4.129 -                if (_keylist == NULL) {
   4.130 -                    /* TODO */
   4.131 -                    return PEP_OUT_OF_MEMORY;
   4.132 -                }
   4.133 -                k = _keylist;
   4.134 -                do {
   4.135 -                        k = stringlist_add(k, "SIGNATURE FPR"/*TODO*/);
   4.136 -                } while (0 /* TODO sign next*/);
   4.137 +    //result = PEP_UNKNOWN_ERROR;
   4.138 +    //            stringlist_t *k;
   4.139 +    //            _keylist = new_stringlist(NULL);
   4.140 +    //            assert(_keylist);
   4.141 +    //            if (_keylist == NULL) {
   4.142 +    //                /* TODO */
   4.143 +    //                return PEP_OUT_OF_MEMORY;
   4.144 +    //            }
   4.145 +    //            k = _keylist;
   4.146 +    //            do {
   4.147 +    //                    k = stringlist_add(k, "SIGNATURE FPR"/*TODO*/);
   4.148 +    //            } while (0 /* TODO sign next*/);
   4.149  
   4.150      return result;
   4.151  }
   4.152 @@ -262,7 +305,7 @@
   4.153      return PEP_STATUS_OK;
   4.154  }
   4.155  
   4.156 -PEP_STATUS pgp_import_key(PEP_SESSION session, const char *key_data, size_t size)
   4.157 +PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data, size_t size)
   4.158  {
   4.159      assert(session);
   4.160      assert(key_data);
   4.161 @@ -274,7 +317,7 @@
   4.162      return PEP_STATUS_OK;
   4.163  }
   4.164  
   4.165 -PEP_STATUS pgp_export_key(
   4.166 +PEP_STATUS pgp_export_keydata(
   4.167      PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   4.168      )
   4.169  {
     5.1 --- a/src/pgp_netpgp.h	Thu Apr 02 16:19:23 2015 +0200
     5.2 +++ b/src/pgp_netpgp.h	Fri Apr 03 15:41:59 2015 +0200
     5.3 @@ -22,7 +22,7 @@
     5.4  
     5.5  PEP_STATUS pgp_delete_keypair(PEP_SESSION session, const char *fpr);
     5.6  
     5.7 -PEP_STATUS pgp_export_key(
     5.8 +PEP_STATUS pgp_export_keydata(
     5.9          PEP_SESSION session, const char *fpr, char **key_data, size_t *size
    5.10      );
    5.11  
    5.12 @@ -40,7 +40,7 @@
    5.13          PEP_comm_type *comm_type
    5.14      );
    5.15  
    5.16 -PEP_STATUS pgp_import_key(PEP_SESSION session, const char *key_data,
    5.17 +PEP_STATUS pgp_import_keydata(PEP_SESSION session, const char *key_data,
    5.18          size_t size);
    5.19  
    5.20  PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern);