...
authorvb
Mon, 01 Sep 2014 20:56:05 +0200
changeset 287fc9fc3e680c
parent 27 096ad5873ef3
child 29 31881fe94d3c
...
src/cryptotech.c
src/cryptotech.h
src/pEpEngine.c
src/pEp_internal.h
src/pgp_gpg_internal.h
src/transport.c
src/transport.h
     1.1 --- a/src/cryptotech.c	Mon Sep 01 19:30:30 2014 +0200
     1.2 +++ b/src/cryptotech.c	Mon Sep 01 20:56:05 2014 +0200
     1.3 @@ -1,4 +1,4 @@
     1.4 -#include "cryptotech.h"
     1.5 +#include "pEp_internal.h"
     1.6  
     1.7  #ifdef NO_GPG
     1.8  #include "pgp_netpgp.h"
     1.9 @@ -10,29 +10,45 @@
    1.10  #include <memory.h>
    1.11  #include <assert.h>
    1.12  
    1.13 -PEP_STATUS init_cryptotech(PEP_cryptotech_t *cryptotech)
    1.14 +PEP_STATUS init_cryptotech(PEP_SESSION session)
    1.15  {
    1.16 +    pEpSession *_session = (pEpSession *) session;
    1.17 +    PEP_cryptotech_t *cryptotech = _session->cryptotech;
    1.18 +    PEP_STATUS _status;
    1.19 +
    1.20      assert(PEP_crypt__count == 2);
    1.21      memset(cryptotech, 0, sizeof(PEP_cryptotech_t) * PEP_crypt__count);
    1.22  
    1.23 -    cryptotech[0].id = PEP_crypt_none;
    1.24 -    cryptotech[0].unconfirmed_comm_type = PEP_ct_no_encryption;
    1.25 -    cryptotech[0].confirmed_comm_type = PEP_ct_no_encryption;
    1.26 +    cryptotech[PEP_crypt_none].id = PEP_crypt_none;
    1.27 +    cryptotech[PEP_crypt_none].unconfirmed_comm_type = PEP_ct_no_encryption;
    1.28 +    cryptotech[PEP_crypt_none].confirmed_comm_type = PEP_ct_no_encryption;
    1.29  
    1.30 -    cryptotech[1].id = PEP_crypt_OpenPGP;
    1.31 -    cryptotech[1].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
    1.32 -    cryptotech[1].confirmed_comm_type = PEP_ct_OpenPGP;
    1.33 -    cryptotech[1].decrypt_and_verify = pgp_decrypt_and_verify;
    1.34 -    cryptotech[1].encrypt_and_sign = pgp_encrypt_and_sign;
    1.35 -    cryptotech[1].verify_text = pgp_verify_text;
    1.36 -    cryptotech[1].delete_keypair = pgp_delete_keypair;
    1.37 -    cryptotech[1].export_key = pgp_export_key;
    1.38 -    cryptotech[1].find_keys = pgp_find_keys;
    1.39 -    cryptotech[1].generate_keypair = pgp_generate_keypair;
    1.40 -    cryptotech[1].get_key_rating = pgp_get_key_rating;
    1.41 -    cryptotech[1].import_key = pgp_import_key;
    1.42 -    cryptotech[1].recv_key = pgp_recv_key;
    1.43 -    cryptotech[1].send_key = pgp_send_key;
    1.44 +    _status = pgp_init(_session);
    1.45 +    assert(_status == PEP_STATUS_OK);
    1.46 +    if (_status != PEP_STATUS_OK) {
    1.47 +        free(_session);
    1.48 +        return _status;
    1.49 +    }
    1.50 +
    1.51 +    cryptotech[PEP_crypt_OpenPGP].id = PEP_crypt_OpenPGP;
    1.52 +    cryptotech[PEP_crypt_OpenPGP].unconfirmed_comm_type = PEP_ct_OpenPGP_unconfirmed;
    1.53 +    cryptotech[PEP_crypt_OpenPGP].confirmed_comm_type = PEP_ct_OpenPGP;
    1.54 +    cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify = pgp_decrypt_and_verify;
    1.55 +    cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign = pgp_encrypt_and_sign;
    1.56 +    cryptotech[PEP_crypt_OpenPGP].verify_text = pgp_verify_text;
    1.57 +    cryptotech[PEP_crypt_OpenPGP].delete_keypair = pgp_delete_keypair;
    1.58 +    cryptotech[PEP_crypt_OpenPGP].export_key = pgp_export_key;
    1.59 +    cryptotech[PEP_crypt_OpenPGP].find_keys = pgp_find_keys;
    1.60 +    cryptotech[PEP_crypt_OpenPGP].generate_keypair = pgp_generate_keypair;
    1.61 +    cryptotech[PEP_crypt_OpenPGP].get_key_rating = pgp_get_key_rating;
    1.62 +    cryptotech[PEP_crypt_OpenPGP].import_key = pgp_import_key;
    1.63 +    cryptotech[PEP_crypt_OpenPGP].recv_key = pgp_recv_key;
    1.64 +    cryptotech[PEP_crypt_OpenPGP].send_key = pgp_send_key;
    1.65  
    1.66      return PEP_STATUS_OK;
    1.67  }
    1.68 +
    1.69 +void release_cryptotech(PEP_SESSION session)
    1.70 +{
    1.71 +    pgp_release(session);
    1.72 +}
     2.1 --- a/src/cryptotech.h	Mon Sep 01 19:30:30 2014 +0200
     2.2 +++ b/src/cryptotech.h	Mon Sep 01 20:56:05 2014 +0200
     2.3 @@ -72,3 +72,6 @@
     2.4  } PEP_cryptotech_t;
     2.5  
     2.6  typedef uint64_t cryptotech_mask;
     2.7 +
     2.8 +PEP_STATUS init_cryptotech(PEP_SESSION session);
     2.9 +void release_cryptotech(PEP_SESSION session);
     3.1 --- a/src/pEpEngine.c	Mon Sep 01 19:30:30 2014 +0200
     3.2 +++ b/src/pEpEngine.c	Mon Sep 01 20:56:05 2014 +0200
     3.3 @@ -1,13 +1,9 @@
     3.4  #include "pEp_internal.h"
     3.5 -#ifndef NO_GPG
     3.6 -#include "pgp_gpg.h"
     3.7 -#else
     3.8 -#include "pgp_netpgp.h"
     3.9 -#endif
    3.10 +#include "cryptotech.h"
    3.11 +#include "transport.h"
    3.12  
    3.13  DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
    3.14  {
    3.15 -    PEP_STATUS status_result;
    3.16  	int int_result;
    3.17  	const char *sql_log;
    3.18  	const char *sql_safeword;
    3.19 @@ -32,16 +28,12 @@
    3.20  	
    3.21  	_session->version = PEP_ENGINE_VERSION;
    3.22  
    3.23 -    status_result = pgp_init(_session);
    3.24 -    assert(status_result == PEP_STATUS_OK);
    3.25 -    if (status_result != PEP_STATUS_OK) {
    3.26 -        free(_session);
    3.27 -        return status_result;
    3.28 -    }
    3.29 +    init_cryptotech(_session);
    3.30 +    init_transport_system(_session->transports);
    3.31  
    3.32      assert(LOCAL_DB);
    3.33      if (LOCAL_DB == NULL) {
    3.34 -        pgp_release(session);
    3.35 +        release_cryptotech(_session);
    3.36          free(_session);
    3.37          return PEP_INIT_CANNOT_OPEN_DB;
    3.38      }
    3.39 @@ -58,7 +50,7 @@
    3.40  
    3.41  	if (int_result != SQLITE_OK) {
    3.42  		sqlite3_close_v2(_session->db);
    3.43 -        pgp_release(session);
    3.44 +        release_cryptotech(_session);
    3.45          free(_session);
    3.46  		return PEP_INIT_CANNOT_OPEN_DB;
    3.47  	}
    3.48 @@ -68,7 +60,7 @@
    3.49      assert(SYSTEM_DB);
    3.50      if (SYSTEM_DB == NULL) {
    3.51  		sqlite3_close_v2(_session->db);
    3.52 -        pgp_release(session);
    3.53 +        release_cryptotech(_session);
    3.54          free(_session);
    3.55  		return PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
    3.56      }
    3.57 @@ -84,7 +76,7 @@
    3.58  	if (int_result != SQLITE_OK) {
    3.59  		sqlite3_close_v2(_session->system_db);
    3.60  		sqlite3_close_v2(_session->db);
    3.61 -        pgp_release(session);
    3.62 +        release_cryptotech(_session);
    3.63          free(_session);
    3.64  		return PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
    3.65  	}
    3.66 @@ -252,7 +244,9 @@
    3.67  			sqlite3_close_v2(_session->db);
    3.68  			sqlite3_close_v2(_session->system_db);
    3.69  		}
    3.70 -        pgp_release(session);
    3.71 +
    3.72 +        release_cryptotech(_session);
    3.73 +        release_transport_system(_session);
    3.74      }
    3.75  	free(_session);
    3.76  }
    3.77 @@ -280,7 +274,6 @@
    3.78  
    3.79      if (stringlist->next != NULL)
    3.80          return stringlist_add(stringlist->next, value);
    3.81 -
    3.82      if (stringlist->value == NULL) {
    3.83          stringlist->value = strdup(value);
    3.84          assert(stringlist->value);
    3.85 @@ -731,7 +724,8 @@
    3.86      char **ptext, size_t *psize, stringlist_t **keylist
    3.87      )
    3.88  {
    3.89 -    return pgp_decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
    3.90 +    pEpSession *_session = (pEpSession *) session;
    3.91 +    return _session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
    3.92  }
    3.93  
    3.94  DYNAMIC_API PEP_STATUS encrypt_and_sign(
    3.95 @@ -739,7 +733,8 @@
    3.96      size_t psize, char **ctext, size_t *csize
    3.97      )
    3.98  {
    3.99 -    return pgp_encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
   3.100 +    pEpSession *_session = (pEpSession *) session;
   3.101 +    return _session->cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
   3.102  }
   3.103  
   3.104  DYNAMIC_API PEP_STATUS verify_text(
   3.105 @@ -747,33 +742,38 @@
   3.106      const char *signature, size_t sig_size, stringlist_t **keylist
   3.107      )
   3.108  {
   3.109 -    return pgp_verify_text(session, text, size, signature, sig_size, keylist);
   3.110 +    pEpSession *_session = (pEpSession *) session;
   3.111 +    return _session->cryptotech[PEP_crypt_OpenPGP].verify_text(session, text, size, signature, sig_size, keylist);
   3.112  }
   3.113  
   3.114  DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
   3.115  {
   3.116 -    return pgp_delete_keypair(session, fpr);
   3.117 +    pEpSession *_session = (pEpSession *) session;
   3.118 +    return _session->cryptotech[PEP_crypt_OpenPGP].delete_keypair(session, fpr);
   3.119  }
   3.120  
   3.121  DYNAMIC_API PEP_STATUS export_key(
   3.122      PEP_SESSION session, const char *fpr, char **key_data, size_t *size
   3.123      )
   3.124  {
   3.125 -    return pgp_export_key(session, fpr, key_data, size);
   3.126 +    pEpSession *_session = (pEpSession *) session;
   3.127 +    return _session->cryptotech[PEP_crypt_OpenPGP].export_key(session, fpr, key_data, size);
   3.128  }
   3.129  
   3.130  DYNAMIC_API PEP_STATUS find_keys(
   3.131      PEP_SESSION session, const char *pattern, stringlist_t **keylist
   3.132      )
   3.133  {
   3.134 -    return pgp_find_keys(session, pattern, keylist);
   3.135 +    pEpSession *_session = (pEpSession *) session;
   3.136 +    return _session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
   3.137  }
   3.138  
   3.139  DYNAMIC_API PEP_STATUS generate_keypair(
   3.140      PEP_SESSION session, pEp_identity *identity
   3.141      )
   3.142  {
   3.143 -    return pgp_generate_keypair(session, identity);
   3.144 +    pEpSession *_session = (pEpSession *) session;
   3.145 +    return _session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session, identity);
   3.146  }
   3.147  
   3.148  DYNAMIC_API PEP_STATUS get_key_rating(
   3.149 @@ -782,20 +782,24 @@
   3.150      PEP_comm_type *comm_type
   3.151      )
   3.152  {
   3.153 -    return pgp_get_key_rating(session, fpr, comm_type);
   3.154 +    pEpSession *_session = (pEpSession *) session;
   3.155 +    return _session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr, comm_type);
   3.156  }
   3.157  
   3.158  DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size)
   3.159  {
   3.160 -    return pgp_import_key(session, key_data, size);
   3.161 +    pEpSession *_session = (pEpSession *) session;
   3.162 +    return _session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size);
   3.163  }
   3.164  
   3.165  DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
   3.166  {
   3.167 -    return pgp_recv_key(session, pattern);
   3.168 +    pEpSession *_session = (pEpSession *) session;
   3.169 +    return _session->cryptotech[PEP_crypt_OpenPGP].recv_key(session, pattern);
   3.170  }
   3.171  
   3.172  DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern)
   3.173  {
   3.174 -    return pgp_send_key(session, pattern);
   3.175 +    pEpSession *_session = (pEpSession *) session;
   3.176 +    return _session->cryptotech[PEP_crypt_OpenPGP].send_key(session, pattern);
   3.177  }
     4.1 --- a/src/pEp_internal.h	Mon Sep 01 19:30:30 2014 +0200
     4.2 +++ b/src/pEp_internal.h	Mon Sep 01 20:56:05 2014 +0200
     4.3 @@ -55,6 +55,9 @@
     4.4  #include "pgp_gpg_internal.h"
     4.5  #endif
     4.6  
     4.7 +#include "cryptotech.h"
     4.8 +#include "transport.h"
     4.9 +
    4.10  #define NOT_IMPLEMENTED assert(0)
    4.11  
    4.12  typedef struct {
    4.13 @@ -66,6 +69,9 @@
    4.14      gpgme_ctx_t ctx;
    4.15  #endif
    4.16  
    4.17 +    PEP_cryptotech_t cryptotech[PEP_crypt__count];
    4.18 +    PEP_transport_t transports[PEP_trans__count];
    4.19 +
    4.20      sqlite3 *db;
    4.21      sqlite3 *system_db;
    4.22  
     5.1 --- a/src/pgp_gpg_internal.h	Mon Sep 01 19:30:30 2014 +0200
     5.2 +++ b/src/pgp_gpg_internal.h	Mon Sep 01 20:56:05 2014 +0200
     5.3 @@ -1,3 +1,5 @@
     5.4 +#pragma once
     5.5 +
     5.6  #include <gpgme.h>
     5.7  
     5.8  // init
     6.1 --- a/src/transport.c	Mon Sep 01 19:30:30 2014 +0200
     6.2 +++ b/src/transport.c	Mon Sep 01 20:56:05 2014 +0200
     6.3 @@ -1,11 +1,14 @@
     6.4 -#include "transport.h"
     6.5 +#include "pEp_internal.h"
     6.6  
     6.7  #include <stdlib.h>
     6.8  #include <memory.h>
     6.9  #include <assert.h>
    6.10  
    6.11 -PEP_STATUS init_transport_system(PEP_transport_t* transports)
    6.12 +PEP_STATUS init_transport_system(PEP_SESSION session)
    6.13  {
    6.14 +    pEpSession *_session = (pEpSession *) session;
    6.15 +    PEP_transport_t* transports = _session->transports;
    6.16 +
    6.17      assert(PEP_trans__count == 1);
    6.18      memset(transports, 0, sizeof(PEP_transport_t) * PEP_trans__count);
    6.19  
    6.20 @@ -13,3 +16,8 @@
    6.21  
    6.22      return PEP_STATUS_OK;
    6.23  }
    6.24 +
    6.25 +void release_transport_system(PEP_SESSION session)
    6.26 +{
    6.27 +    // nothing yet
    6.28 +}
     7.1 --- a/src/transport.h	Mon Sep 01 19:30:30 2014 +0200
     7.2 +++ b/src/transport.h	Mon Sep 01 20:56:05 2014 +0200
     7.3 @@ -4,8 +4,8 @@
     7.4  
     7.5  typedef enum _PEP_transports {
     7.6      PEP_trans_auto = 0,
     7.7 -//    PEP_trans_email = 1,
     7.8 -//    PEP_trans_whatsapp = 2,
     7.9 +//    PEP_trans_email,
    7.10 +//    PEP_trans_whatsapp,
    7.11  
    7.12      PEP_trans__count
    7.13  } PEP_transports;
    7.14 @@ -22,3 +22,6 @@
    7.15  };
    7.16  
    7.17  typedef uint64_t transports_mask;
    7.18 +
    7.19 +PEP_STATUS init_transport_system(PEP_SESSION session);
    7.20 +void release_transport_system(PEP_SESSION session);