src/keymanagement.h
author Edouard Tisserant <edouard@pep-project.org>
Tue, 15 Nov 2016 15:56:18 +0100
branchENGINE-140-reloaded
changeset 1394 8659157b681f
parent 1387 cc339b22d690
child 1406 8d8ae9657388
permissions -rw-r--r--
ENGINE-140 #comment Added own_keys table, linking pgp_keypair to identity in case user_id = PEP_OWN_USERID.
Added related set_own_key and own_keys_retieve.
Updated set_identity, set_identity_flags and added unset_identity_flags, all doing bitwise logic to untouched keep flags accross calls.
Removed keys_retrieve_by_flag and PEP_kpf_own_key, now replaced by own_keys table.
Removed duplicated code seting _DDL_USER_VERSION in manageent DB.
Removed exists_empty_fpr_entry update_fprless_identity, and corresponding logic in set_identity()

Builds, but doesn't pass test - DO NOT USE
vb@39
     1
#pragma once
vb@39
     2
vb@217
     3
#include "pEpEngine.h"
vb@217
     4
vb@0
     5
#ifdef __cplusplus
vb@0
     6
extern "C" {
vb@0
     7
#endif
vb@0
     8
vb@0
     9
// update_identity() - update identity information
vb@0
    10
//
vb@0
    11
//  parameters:
vb@0
    12
//      session (in)        session to use
vb@0
    13
//      identity (inout)    identity information of communication partner
krista@1220
    14
//                          (identity->fpr is OUT ONLY)
vb@0
    15
//  caveat:
vb@10
    16
//      if this function returns PEP_ct_unknown or PEP_ct_key_expired in
vb@10
    17
//      identity->comm_type, the caller must insert the identity into the
vb@10
    18
//      asynchronous management implementation, so retrieve_next_identity()
vb@10
    19
//      will return this identity later
vb@21
    20
//      at least identity->address must be a non-empty UTF-8 string as input
vb@932
    21
//      update_identity() never writes flags; use set_identity_flags() for
vb@932
    22
//      writing
krista@1220
    23
//      this function NEVER reads the incoming fpr, only writes to it.
vb@0
    24
vb@1387
    25
DYNAMIC_API PEP_STATUS update_identity(
vb@0
    26
        PEP_SESSION session, pEp_identity * identity
vb@0
    27
    );
vb@0
    28
vb@0
    29
vb@0
    30
// myself() - ensures that the own identity is being complete
vb@0
    31
//
vb@0
    32
//  parameters:
vb@0
    33
//      session (in)        session to use
vb@0
    34
//      identity (inout)    identity of local user
vb@0
    35
//                          at least .address, .username, .user_id must be set
vb@0
    36
//
vb@0
    37
//  return value:
vb@0
    38
//      PEP_STATUS_OK if identity could be completed or was already complete,
vb@0
    39
//      any other value on error
vb@0
    40
//
vb@0
    41
//  caveat:
vb@0
    42
//      this function generates a keypair on demand; because it's synchronous
vb@0
    43
//      it can need a decent amount of time to return
vb@0
    44
//      if you need to do this asynchronous, you need to return an identity
vb@0
    45
//      with retrieve_next_identity() where pEp_identity.me is true
vb@932
    46
//      myself() never writes flags; use set_identity_flags() for writing
vb@0
    47
vb@0
    48
DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity);
vb@0
    49
edouard@1385
    50
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen);
edouard@1385
    51
vb@0
    52
vb@0
    53
// retrieve_next_identity() - callback being called by do_keymanagement()
vb@0
    54
//
vb@0
    55
//  parameters:
vb@0
    56
//      management (in)     data structure to deliver (implementation defined)
vb@0
    57
//
vb@0
    58
//  return value:
vb@0
    59
//      identity to check or NULL to terminate do_keymanagement()
vb@0
    60
//      if given identity must be created with new_identity()
vb@0
    61
//      the identity struct is going to the ownership of this library
vb@0
    62
//      it must not be freed by the callee
vb@0
    63
//
vb@0
    64
//  caveat:
vb@0
    65
//      this callback has to block until an identity or NULL can be returned
vb@0
    66
//      an implementation is not provided by this library; instead it has to be
vb@0
    67
//      implemented by the user of this library
vb@0
    68
vb@0
    69
typedef pEp_identity *(*retrieve_next_identity_t)(void *management);
vb@0
    70
vb@0
    71
vb@292
    72
// examine_identity() - callback for appending to queue
vb@292
    73
//
vb@292
    74
//  parameters:
vb@292
    75
//      ident (in)          identity to examine
vb@292
    76
//      management (in)     data structure to deliver (implementation defined)
vb@292
    77
//
vb@292
    78
//  return value:
vb@292
    79
//      0 if identity was added successfully to queue or nonzero otherwise
vb@292
    80
vb@296
    81
typedef int (*examine_identity_t)(pEp_identity *ident, void *management);
vb@292
    82
vb@292
    83
vb@292
    84
// register_examine_function() - register examine_identity() callback
vb@292
    85
//
vb@292
    86
//  parameters:
vb@292
    87
//      session (in)            session to use
vb@292
    88
//      examine_identity (in)   examine_identity() function to register
vb@292
    89
//      management (in)     data structure to deliver (implementation defined)
vb@292
    90
vb@296
    91
DYNAMIC_API PEP_STATUS register_examine_function(
vb@292
    92
        PEP_SESSION session, 
vb@292
    93
        examine_identity_t examine_identity,
vb@292
    94
        void *management
vb@292
    95
    );
vb@292
    96
vb@292
    97
vb@0
    98
// do_keymanagement() - function to be run on an extra thread
vb@0
    99
//
vb@0
   100
//  parameters:
vb@0
   101
//      retrieve_next_identity  pointer to retrieve_next_identity() callback
vb@0
   102
//                              which returns at least a valid address field in
vb@0
   103
//                              the identity struct
vb@0
   104
//      management              management data to give to keymanagement
vb@0
   105
//                              (implementation defined)
vb@0
   106
//
vb@0
   107
//  return value:
vb@0
   108
//      PEP_STATUS_OK if thread has to terminate successfully or any other
vb@0
   109
//      value on failure
vb@0
   110
//
vb@0
   111
//  caveat:
vb@0
   112
//      to ensure proper working of this library, a thread has to be started
vb@0
   113
//      with this function immediately after initialization
vb@0
   114
//      do_keymanagement() calls retrieve_next_identity(management)
vb@0
   115
vb@0
   116
DYNAMIC_API PEP_STATUS do_keymanagement(
vb@0
   117
        retrieve_next_identity_t retrieve_next_identity,
vb@0
   118
        void *management
vb@0
   119
    );
vb@0
   120
vb@215
   121
krista@1213
   122
// key_mistrusted() - mark key as being compromized
vb@215
   123
//
vb@215
   124
//  parameters:
vb@215
   125
//      session (in)        session to use
vb@357
   126
//      ident (in)          person and key which was compromized
vb@215
   127
krista@1213
   128
DYNAMIC_API PEP_STATUS key_mistrusted(
vb@357
   129
        PEP_SESSION session,
vb@357
   130
        pEp_identity *ident
vb@357
   131
    );
vb@215
   132
vb@215
   133
vb@354
   134
// trust_personal_key() - mark a key as trusted with a person
vb@354
   135
//
vb@354
   136
//  parameters:
vb@354
   137
//      session (in)        session to use
vb@354
   138
//      ident (in)          person and key to trust in
vb@354
   139
//
vb@354
   140
//  caveat:
vb@354
   141
//      the fields user_id, address and fpr must be supplied
vb@354
   142
vb@354
   143
DYNAMIC_API PEP_STATUS trust_personal_key(
vb@354
   144
        PEP_SESSION session,
vb@354
   145
        pEp_identity *ident
vb@354
   146
    );
vb@354
   147
vb@354
   148
krista@1213
   149
// key_reset_trust() - undo trust_personal_key and key_mistrusted() for keys
vb@421
   150
//                     we don't own
Edouard@410
   151
//
Edouard@410
   152
//  parameters:
Edouard@410
   153
//      session (in)        session to use
Edouard@410
   154
//      ident (in)          person and key which was compromized
Edouard@410
   155
Edouard@410
   156
DYNAMIC_API PEP_STATUS key_reset_trust(
Edouard@410
   157
        PEP_SESSION session,
Edouard@410
   158
        pEp_identity *ident
Edouard@410
   159
    );
Edouard@410
   160
Edouard@584
   161
Edouard@584
   162
// own_key_is_listed() - returns true id key is listed as own key
Edouard@584
   163
//
Edouard@584
   164
//  parameters:
Edouard@584
   165
//      session (in)        session to use
Edouard@584
   166
//      fpr (in)            fingerprint of key to test
Edouard@584
   167
//      bool (out)          flags if key is own
Edouard@584
   168
Edouard@584
   169
DYNAMIC_API PEP_STATUS own_key_is_listed(
Edouard@584
   170
        PEP_SESSION session,
Edouard@584
   171
        const char *fpr,
Edouard@584
   172
        bool *listed
Edouard@584
   173
    );
Edouard@584
   174
Edouard@584
   175
vb@955
   176
// own_identities_retrieve() - retrieve all own identities
Edouard@584
   177
//
Edouard@584
   178
//  parameters:
vb@955
   179
//      session (in)            session to use
vb@955
   180
//      own_identities (out)    list of own identities
Edouard@584
   181
//
Edouard@584
   182
//  caveat:
vb@1133
   183
//      the ownership of the copy of own_identities goes to the caller
Edouard@584
   184
vb@955
   185
DYNAMIC_API PEP_STATUS own_identities_retrieve(
Edouard@584
   186
        PEP_SESSION session,
vb@955
   187
        identity_list **own_identities
Edouard@584
   188
    );
Edouard@410
   189
krista@1357
   190
PEP_STATUS contains_priv_key(PEP_SESSION session, const char *fpr,
krista@1357
   191
                             bool *has_private);
krista@1357
   192
edouard@1394
   193
// own_keys_retrieve() - retrieve all flagged keypair fingerprints 
edouard@1370
   194
//
edouard@1370
   195
//  parameters:
edouard@1370
   196
//      session (in)            session to use
edouard@1370
   197
//      keylist (out)           list of fingerprints
edouard@1370
   198
//
edouard@1370
   199
//  caveat:
edouard@1370
   200
//      the ownership of the list goes to the caller
edouard@1394
   201
DYNAMIC_API PEP_STATUS own_keys_retrieve(
edouard@1370
   202
        PEP_SESSION session,
edouard@1370
   203
        stringlist_t **keylist
edouard@1370
   204
      );
edouard@1370
   205
vb@0
   206
#ifdef __cplusplus
vb@0
   207
}
vb@0
   208
#endif
vb@0
   209