src/pEp_internal.h
author Roker <roker@pep-project.org>
Tue, 20 Sep 2016 15:54:57 +0200
branchroker-linux
changeset 1168 4d4e3ecbaf8b
parent 932 d35b292fe141
child 955 060272dfaaeb
permissions -rw-r--r--
merge "default" into my branch
     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_pgp_keypair;
    99     sqlite3_stmt *set_identity;
   100     sqlite3_stmt *set_identity_flags;
   101     sqlite3_stmt *set_trust;
   102     sqlite3_stmt *get_trust;
   103     sqlite3_stmt *least_trust;
   104     sqlite3_stmt *mark_compromized;
   105     sqlite3_stmt *reset_trust;
   106     sqlite3_stmt *crashdump;
   107     sqlite3_stmt *languagelist;
   108     sqlite3_stmt *i18n_token;
   109 
   110     // blacklist
   111     sqlite3_stmt *blacklist_add;
   112     sqlite3_stmt *blacklist_delete;
   113     sqlite3_stmt *blacklist_is_listed;
   114     sqlite3_stmt *blacklist_retrieve;
   115     
   116     // Own keys
   117     sqlite3_stmt *own_key_is_listed;
   118     sqlite3_stmt *own_key_retrieve;
   119 
   120     // sequence value
   121     sqlite3_stmt *sequence_value1;
   122     sqlite3_stmt *sequence_value2;
   123 
   124     // sequence value
   125     sqlite3_stmt *set_revoked;
   126     sqlite3_stmt *get_revoked;
   127 
   128     // callbacks
   129     examine_identity_t examine_identity;
   130     void *examine_management;
   131     void *sync_obj;
   132     messageToSend_t messageToSend;
   133     showHandshake_t showHandshake;
   134 
   135     // state machines
   136     DeviceState_state sync_state;
   137 
   138     // runtime config
   139 
   140     bool passive_mode;
   141     bool unencrypted_subject;
   142     bool use_only_own_private_keys;
   143     
   144 } pEpSession;
   145 
   146 PEP_STATUS init_transport_system(PEP_SESSION session, bool in_first);
   147 void release_transport_system(PEP_SESSION session, bool out_last);
   148 
   149 #ifdef NDEBUG
   150 #define DEBUG_LOG(TITLE, ENTITY, DESC)
   151 #else
   152 #define DEBUG_LOG(TITLE, ENTITY, DESC) \
   153     log_event(session, (TITLE), (ENTITY), (DESC), "debug");
   154 #endif
   155