netpgp : build, link, init, release.
authorEdouard Tisserant
Thu, 02 Apr 2015 16:03:54 +0200
changeset 17559c8eabab690
parent 174 9c3d0eaa8ea1
child 176 c4a5d7381459
netpgp : build, link, init, release.
src/pEpEngine.h
src/pgp_gpg.c
src/pgp_netpgp.c
src/platform_unix.h
     1.1 --- a/src/pEpEngine.h	Wed Apr 01 16:38:20 2015 +0200
     1.2 +++ b/src/pEpEngine.h	Thu Apr 02 16:03:54 2015 +0200
     1.3 @@ -28,6 +28,8 @@
     1.4  
     1.5  	PEP_INIT_CANNOT_LOAD_GPGME						= 0x0110,
     1.6  	PEP_INIT_GPGME_INIT_FAILED						= 0x0111,
     1.7 +	PEP_INIT_NO_GPG_HOME							= 0x0112,
     1.8 +	PEP_INIT_NETPGP_INIT_FAILED						= 0x0113,
     1.9  
    1.10  	PEP_INIT_SQLITE3_WITHOUT_MUTEX					= 0x0120,
    1.11  	PEP_INIT_CANNOT_OPEN_DB							= 0x0121,
     2.1 --- a/src/pgp_gpg.c	Wed Apr 01 16:38:20 2015 +0200
     2.2 +++ b/src/pgp_gpg.c	Thu Apr 02 16:03:54 2015 +0200
     2.3 @@ -107,11 +107,17 @@
     2.4          stringlist_add(conf_values, "SHA512 SHA384 SHA256 SHA224");
     2.5          
     2.6          bResult = ensure_config_values(conf_keys, conf_values);
     2.7 -        assert(bResult);
     2.8  
     2.9          free_stringlist(conf_keys);
    2.10          free_stringlist(conf_values);
    2.11  
    2.12 +        assert(bResult);
    2.13 +        if(!bResult){
    2.14 +            status = PEP_INIT_NO_GPG_HOME;
    2.15 +            goto pep_error;
    2.16 +        }
    2.17 +
    2.18 +
    2.19          gpgme = dlopen(LIBGPGME, RTLD_LAZY);
    2.20          if (gpgme == NULL) {
    2.21              status = PEP_INIT_CANNOT_LOAD_GPGME;
     3.1 --- a/src/pgp_netpgp.c	Wed Apr 01 16:38:20 2015 +0200
     3.2 +++ b/src/pgp_netpgp.c	Thu Apr 02 16:03:54 2015 +0200
     3.3 @@ -9,51 +9,35 @@
     3.4  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
     3.5  {
     3.6      PEP_STATUS status = PEP_STATUS_OK;
     3.7 +    const char *home = NULL;
     3.8     
     3.9      if (in_first) {
    3.10 -        /* TODO something maybe */
    3.11 +        if (strcmp(setlocale(LC_ALL, NULL), "C") == 0)
    3.12 +            setlocale(LC_ALL, "");
    3.13      }
    3.14  
    3.15 -        // TODO ensure minimal config
    3.16 -          
    3.17 -        // "keyserver"
    3.18 -        // "hkp://keys.gnupg.net"
    3.19 -
    3.20 -        // "cert-digest-algo"
    3.21 -        // "SHA256"
    3.22 -
    3.23 -        // "no-emit-version"
    3.24 -        // ""
    3.25 -
    3.26 -        // "no-comments"
    3.27 -        // ""
    3.28 +	memset(&session->ctx, 0x0, sizeof(session->ctx));
    3.29  
    3.30 -        // "personal-cipher-preferences"
    3.31 -        // "AES AES256 AES192 CAST5"
    3.32 -
    3.33 -        // "personal-digest-preferences"
    3.34 -        // "SHA512 SHA384 SHA256 SHA224"
    3.35 -        
    3.36 -        if (strcmp(setlocale(LC_ALL, NULL), "C") == 0)
    3.37 -            setlocale(LC_ALL, "");
    3.38 -
    3.39 -        // TODO unsset netpgp locale if any
    3.40 -        // LC_CTYPE
    3.41 -#ifdef LC_MESSAGES // Windoze
    3.42 -        // LC_MESSAGES
    3.43 -#endif
    3.44 +    // NetPGP shares home with GPG
    3.45 +    home = gpg_home();
    3.46 +    if(home){
    3.47 +        netpgp_set_homedir(&session->ctx,(char*)home, NULL, 0);
    3.48 +    }else{
    3.49 +        status = PEP_INIT_NO_GPG_HOME;
    3.50 +        goto pep_error;
    3.51      }
    3.52  
    3.53 -    // TODO Create netpgp handle
    3.54 -    // session->ctx = ...
    3.55 -    if (/* create error */) {
    3.56 -        status = PEP_INIT_GPGME_INIT_FAILED;
    3.57 +    // pair with gpg's cert-digest-algo
    3.58 +	netpgp_setvar(&session->ctx, "hash", "SHA256");
    3.59 +
    3.60 +    // subset of gpg's personal-cipher-preferences
    3.61 +    // here only one cipher can be selected
    3.62 +    netpgp_setvar(&session->ctx, "cipher", "AES256");
    3.63 +
    3.64 +	if (!netpgp_init(&session->ctx)) {
    3.65 +        status = PEP_INIT_NETPGP_INIT_FAILED;
    3.66          goto pep_error;
    3.67      }
    3.68 -    assert(session->ctx);
    3.69 -
    3.70 -    // TODO set protocol to OpenPGP
    3.71 -    // TODO set to use armoring
    3.72  
    3.73      return PEP_STATUS_OK;
    3.74  
    3.75 @@ -64,15 +48,10 @@
    3.76  
    3.77  void pgp_release(PEP_SESSION session, bool out_last)
    3.78  {
    3.79 -    if (session->ctx) {
    3.80 -        // TODO : release session->ctx
    3.81 -        session->ctx = NULL;
    3.82 -    }
    3.83 +	netpgp_end(&session->ctx);
    3.84 +	memset(&session->ctx, 0x0, sizeof(session->ctx));
    3.85  
    3.86 -    if (out_last){
    3.87 -        // TODO anything ?
    3.88 -    }
    3.89 -
    3.90 +    // out_last unused here
    3.91  }
    3.92  
    3.93  PEP_STATUS pgp_decrypt_and_verify(
    3.94 @@ -130,8 +109,6 @@
    3.95      )
    3.96  {
    3.97      PEP_STATUS result;
    3.98 -    gpgme_error_t gpgme_error;
    3.99 -    gpgme_data_t d_text, d_sig;
   3.100      stringlist_t *_keylist;
   3.101  
   3.102      assert(session);
   3.103 @@ -196,26 +173,25 @@
   3.104      }
   3.105  
   3.106      /* Do encrypt and sign */ 
   3.107 -        char *_buffer = NULL;
   3.108 -        size_t length = /* TODO length*/ 0;
   3.109 -        assert(length != -1);
   3.110 +    char *_buffer = NULL;
   3.111 +    size_t length = /* TODO length*/ 0;
   3.112 +    assert(length != -1);
   3.113  
   3.114 -        /* Allocate transferable buffer */
   3.115 -        _buffer = malloc(length + 1);
   3.116 -        assert(_buffer);
   3.117 -        if (_buffer == NULL) {
   3.118 -            /* TODO clean */
   3.119 -            return PEP_OUT_OF_MEMORY;
   3.120 -        }
   3.121 -
   3.122 -        *ctext = _buffer;
   3.123 -        *csize = length;
   3.124 -        (*ctext)[*csize] = 0; // safeguard for naive users
   3.125 -        result = PEP_STATUS_OK;
   3.126 +    /* Allocate transferable buffer */
   3.127 +    _buffer = malloc(length + 1);
   3.128 +    assert(_buffer);
   3.129 +    if (_buffer == NULL) {
   3.130 +        /* TODO clean */
   3.131 +        return PEP_OUT_OF_MEMORY;
   3.132      }
   3.133  
   3.134 +    *ctext = _buffer;
   3.135 +    *csize = length;
   3.136 +    (*ctext)[*csize] = 0; // safeguard for naive users
   3.137 +    result = PEP_STATUS_OK;
   3.138 +
   3.139      
   3.140 -        result = PEP_UNKNOWN_ERROR;
   3.141 +    result = PEP_UNKNOWN_ERROR;
   3.142      return result;
   3.143  }
   3.144  
   3.145 @@ -336,6 +312,8 @@
   3.146      return PEP_STATUS_OK;
   3.147  }
   3.148  
   3.149 +// "keyserver"
   3.150 +// "hkp://keys.gnupg.net"
   3.151  PEP_STATUS pgp_recv_key(PEP_SESSION session, const char *pattern)
   3.152  {
   3.153      assert(session);
   3.154 @@ -453,7 +431,7 @@
   3.155                  *comm_type = PEP_ct_key_expired;
   3.156                  break;
   3.157              }
   3.158 -            if (/* TODO revoked*/) {
   3.159 +            if (/* TODO revoked*/ 1) {
   3.160                  *comm_type = PEP_ct_key_revoked;
   3.161                  break;
   3.162              }
     4.1 --- a/src/platform_unix.h	Wed Apr 01 16:38:20 2015 +0200
     4.2 +++ b/src/platform_unix.h	Thu Apr 02 16:03:54 2015 +0200
     4.3 @@ -10,6 +10,7 @@
     4.4  
     4.5  const char *unix_local_db(void);
     4.6  const char *gpg_conf(void);
     4.7 +const char *gpg_home(void);
     4.8  
     4.9  #ifdef __cplusplus
    4.10  }