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