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