src/pEp_internal.h
author Edouard Tisserant <edouard@pep-project.org>
Thu, 01 Dec 2016 17:56:05 +0100
branchENGINE-133
changeset 1459 ab329d7db8d7
parent 1394 8659157b681f
child 1460 66ceb5a7f718
permissions -rw-r--r--
ENGINE-133 added more feedback for the app in case of handshake success or failure, because of timeout
     1 #define PEP_ENGINE_VERSION "0.8.0"
     2 
     3 // maximum attachment size to import as key 1MB, maximum of 20 attachments
     4 
     5 #define MAX_KEY_SIZE (1024 * 1024)
     6 #define MAX_KEYS_TO_IMPORT  20
     7 
     8 // this is 20 trustwords with 79 chars max
     9 #define MAX_TRUSTWORDS_SPACE (20 * 80)
    10 
    11 // XML parameters string
    12 #define PARMS_MAX 32768
    13 
    14 // maximum busy wait time in ms
    15 #define BUSY_WAIT_TIME 5000
    16 
    17 // maximum line length for reading gpg.conf
    18 #define MAX_LINELENGTH 1024
    19 
    20 // default keyserver
    21 #ifndef DEFAULT_KEYSERVER
    22 #define DEFAULT_KEYSERVER "hkp://keys.gnupg.net"
    23 #endif
    24 
    25 // crashdump constants
    26 #ifndef CRASHDUMP_DEFAULT_LINES
    27 #define CRASHDUMP_DEFAULT_LINES 100
    28 #endif
    29 #define CRASHDUMP_MAX_LINES 32767
    30 
    31 #include "platform.h"
    32 
    33 #ifdef WIN32
    34 #define LOCAL_DB windoze_local_db()
    35 #define SYSTEM_DB windoze_system_db()
    36 #define LIBGPGME "libgpgme-11.dll"
    37 #else // UNIX
    38 #define _POSIX_C_SOURCE 200809L
    39 #include <dlfcn.h>
    40 #define LOCAL_DB unix_local_db()
    41 #ifndef SYSTEM_DB
    42 #define SYSTEM_DB "/usr/share/pEp/system.db"
    43 #endif
    44 #ifndef LIBGPGME
    45 #define LIBGPGME "libgpgme-pthread.so"
    46 #endif
    47 #endif
    48 
    49 #include <locale.h>
    50 #include <stdlib.h>
    51 #include <string.h>
    52 #include <assert.h>
    53 #include <stdio.h>
    54 
    55 #include "sqlite3.h"
    56 
    57 #define _EXPORT_PEP_ENGINE_DLL
    58 #include "pEpEngine.h"
    59 
    60 // If not specified, build for GPG
    61 #ifndef USE_NETPGP
    62 #ifndef USE_GPG
    63 #define USE_GPG
    64 #endif
    65 #endif
    66 
    67 #ifdef USE_GPG
    68 #include "pgp_gpg_internal.h"
    69 #elif defined(USE_NETPGP)
    70 #include "pgp_netpgp_internal.h"
    71 #endif
    72 
    73 #include "keymanagement.h"
    74 #include "cryptotech.h"
    75 #include "transport.h"
    76 #include "sync.h"
    77 
    78 #define NOT_IMPLEMENTED assert(0); return PEP_UNKNOWN_ERROR;
    79 
    80 typedef struct _pEpSession {
    81     const char *version;
    82 #ifdef USE_GPG
    83     gpgme_ctx_t ctx;
    84 #elif defined(USE_NETPGP)
    85     pEpNetPGPSession ctx;
    86 #endif
    87 
    88     PEP_cryptotech_t *cryptotech;
    89     PEP_transport_t *transports;
    90 
    91     sqlite3 *db;
    92     sqlite3 *system_db;
    93 
    94     sqlite3_stmt *log;
    95     sqlite3_stmt *trustword;
    96     sqlite3_stmt *get_identity;
    97     sqlite3_stmt *set_person;
    98     sqlite3_stmt *set_device_group;
    99     sqlite3_stmt *get_device_group;
   100     sqlite3_stmt *set_pgp_keypair;
   101     sqlite3_stmt *set_identity;
   102     sqlite3_stmt *set_identity_flags;
   103     sqlite3_stmt *unset_identity_flags;
   104     sqlite3_stmt *set_trust;
   105     sqlite3_stmt *get_trust;
   106     sqlite3_stmt *least_trust;
   107     sqlite3_stmt *mark_compromized;
   108     sqlite3_stmt *reset_trust;
   109     sqlite3_stmt *crashdump;
   110     sqlite3_stmt *languagelist;
   111     sqlite3_stmt *i18n_token;
   112 
   113     // blacklist
   114     sqlite3_stmt *blacklist_add;
   115     sqlite3_stmt *blacklist_delete;
   116     sqlite3_stmt *blacklist_is_listed;
   117     sqlite3_stmt *blacklist_retrieve;
   118     
   119     // Own keys
   120     sqlite3_stmt *own_key_is_listed;
   121     sqlite3_stmt *own_identities_retrieve;
   122     sqlite3_stmt *own_keys_retrieve;
   123     sqlite3_stmt *set_own_key;
   124 
   125     // sequence value
   126     sqlite3_stmt *sequence_value1;
   127     sqlite3_stmt *sequence_value2;
   128     sqlite3_stmt *sequence_value3;
   129 
   130     // revoked keys
   131     sqlite3_stmt *set_revoked;
   132     sqlite3_stmt *get_revoked;
   133 
   134     // callbacks
   135     examine_identity_t examine_identity;
   136     void *examine_management;
   137     void *sync_obj;
   138     messageToSend_t messageToSend;
   139     notifyHandshake_t notifyHandshake;
   140     inject_sync_msg_t inject_sync_msg;
   141     retrieve_next_sync_msg_t retrieve_next_sync_msg;
   142 
   143     // key sync
   144     DeviceState_state sync_state;
   145     char sync_uuid[37];
   146     time_t LastCannotDecrypt;
   147     time_t LastUpdateRequest;
   148 
   149     // runtime config
   150 
   151     bool passive_mode;
   152     bool unencrypted_subject;
   153     bool use_only_own_private_keys;
   154     bool keep_sync_msg;
   155     
   156 } pEpSession;
   157 
   158 PEP_STATUS init_transport_system(PEP_SESSION session, bool in_first);
   159 void release_transport_system(PEP_SESSION session, bool out_last);
   160 
   161 #ifdef NDEBUG
   162 #define DEBUG_LOG(TITLE, ENTITY, DESC)
   163 #else
   164 #define DEBUG_LOG(TITLE, ENTITY, DESC) \
   165     log_event(session, (TITLE), (ENTITY), (DESC), "debug");
   166 #endif
   167