src/pEp_internal.h
author Edouard Tisserant <edouard@pep-project.org>
Fri, 30 Sep 2016 16:10:26 +0200
branchkeysync
changeset 1234 c03758736a0b
parent 1110 d37d730fa8e5
child 1235 cfc9214a60a5
permissions -rw-r--r--
sync : added set_device_group sql stuff
     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 extern char sync_uuid[37];
    81 
    82 typedef struct _pEpSession {
    83     const char *version;
    84 #ifdef USE_GPG
    85     gpgme_ctx_t ctx;
    86 #elif defined(USE_NETPGP)
    87     pEpNetPGPSession ctx;
    88 #endif
    89 
    90     PEP_cryptotech_t *cryptotech;
    91     PEP_transport_t *transports;
    92 
    93     sqlite3 *db;
    94     sqlite3 *system_db;
    95 
    96     sqlite3_stmt *log;
    97     sqlite3_stmt *trustword;
    98     sqlite3_stmt *get_identity;
    99     sqlite3_stmt *set_person;
   100     sqlite3_stmt *set_device_group;
   101     sqlite3_stmt *set_pgp_keypair;
   102     sqlite3_stmt *set_identity;
   103     sqlite3_stmt *set_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 
   123     // sequence value
   124     sqlite3_stmt *sequence_value1;
   125     sqlite3_stmt *sequence_value2;
   126     sqlite3_stmt *sequence_value3;
   127 
   128     // sequence value
   129     sqlite3_stmt *set_revoked;
   130     sqlite3_stmt *get_revoked;
   131 
   132     // callbacks
   133     examine_identity_t examine_identity;
   134     void *examine_management;
   135     void *sync_obj;
   136     messageToSend_t messageToSend;
   137     showHandshake_t showHandshake;
   138     inject_sync_msg_t inject_sync_msg;
   139     retrieve_next_sync_msg_t retrieve_next_sync_msg;
   140 
   141     // state machines
   142     DeviceState_state sync_state;
   143 
   144     // runtime config
   145 
   146     bool passive_mode;
   147     bool unencrypted_subject;
   148     bool use_only_own_private_keys;
   149     bool keep_sync_msg;
   150     
   151 } pEpSession;
   152 
   153 PEP_STATUS init_transport_system(PEP_SESSION session, bool in_first);
   154 void release_transport_system(PEP_SESSION session, bool out_last);
   155 
   156 #ifdef NDEBUG
   157 #define DEBUG_LOG(TITLE, ENTITY, DESC)
   158 #else
   159 #define DEBUG_LOG(TITLE, ENTITY, DESC) \
   160     log_event(session, (TITLE), (ENTITY), (DESC), "debug");
   161 #endif
   162