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