src/keymanagement.h
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:19 +0200
branchENGINE-254
changeset 2723 7194b9c8599d
parent 2129 fd3108a623c5
child 2219 99b05a2f117e
child 2461 85c8e5aad3bc
permissions -rw-r--r--
close branch
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@2129
   128
// key_mistrusted() - mark key as being compromised
vb@215
   129
//
vb@215
   130
//  parameters:
vb@215
   131
//      session (in)        session to use
krista@2129
   132
//      ident (in)          person and key which was compromised
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
krista@2129
   139
// undo_last_mistrust() - reset identity and trust status for the last
krista@2129
   140
//                        identity in this session marked as mistrusted
krista@2129
   141
//                        to their cached values from the time of mistrust
krista@2129
   142
//  parameters:
krista@2129
   143
//      session (in)        session to use
krista@2129
   144
//
krista@2129
   145
//  return value:
krista@2129
   146
//      PEP_STATUS_OK if identity and trust were successfully restored.
krista@2129
   147
//      Otherwise, error status from attempts to set.
krista@2129
   148
//
krista@2129
   149
//  caveat:
krista@2129
   150
//      only works for this session, and only once. cache is invalidated
krista@2129
   151
//      upon use.
krista@2129
   152
//
krista@2129
   153
//      WILL NOT WORK ON MISTRUSTED OWN KEY
krista@2129
   154
krista@2129
   155
DYNAMIC_API PEP_STATUS undo_last_mistrust(PEP_SESSION session);
krista@2129
   156
vb@215
   157
vb@354
   158
// trust_personal_key() - mark a key as trusted with a person
vb@354
   159
//
vb@354
   160
//  parameters:
vb@354
   161
//      session (in)        session to use
vb@354
   162
//      ident (in)          person and key to trust in
vb@354
   163
//
vb@354
   164
//  caveat:
vb@354
   165
//      the fields user_id, address and fpr must be supplied
vb@354
   166
vb@354
   167
DYNAMIC_API PEP_STATUS trust_personal_key(
vb@354
   168
        PEP_SESSION session,
vb@354
   169
        pEp_identity *ident
vb@354
   170
    );
vb@354
   171
vb@354
   172
krista@1213
   173
// key_reset_trust() - undo trust_personal_key and key_mistrusted() for keys
vb@421
   174
//                     we don't own
Edouard@410
   175
//
Edouard@410
   176
//  parameters:
Edouard@410
   177
//      session (in)        session to use
Edouard@410
   178
//      ident (in)          person and key which was compromized
Edouard@410
   179
Edouard@410
   180
DYNAMIC_API PEP_STATUS key_reset_trust(
Edouard@410
   181
        PEP_SESSION session,
Edouard@410
   182
        pEp_identity *ident
Edouard@410
   183
    );
Edouard@410
   184
Edouard@584
   185
// own_key_is_listed() - returns true id key is listed as own key
Edouard@584
   186
//
Edouard@584
   187
//  parameters:
Edouard@584
   188
//      session (in)        session to use
Edouard@584
   189
//      fpr (in)            fingerprint of key to test
roker@2060
   190
//      listed (out)        flags if key is own
Edouard@584
   191
Edouard@584
   192
DYNAMIC_API PEP_STATUS own_key_is_listed(
Edouard@584
   193
        PEP_SESSION session,
Edouard@584
   194
        const char *fpr,
Edouard@584
   195
        bool *listed
Edouard@584
   196
    );
Edouard@584
   197
Edouard@584
   198
edouard@1412
   199
// _own_identities_retrieve() - retrieve all own identities
edouard@1412
   200
//
edouard@1412
   201
//  parameters:
edouard@1412
   202
//      session (in)            session to use
edouard@1412
   203
//      own_identities (out)    list of own identities
edouard@1412
   204
//      excluded_flags (int)    flags to exclude from results
edouard@1412
   205
//
edouard@1412
   206
//  caveat:
edouard@1412
   207
//      the ownership of the copy of own_identities goes to the caller
edouard@1412
   208
edouard@1412
   209
DYNAMIC_API PEP_STATUS _own_identities_retrieve(
edouard@1412
   210
        PEP_SESSION session,
edouard@1412
   211
        identity_list **own_identities,
edouard@1412
   212
        identity_flags_t excluded_flags
edouard@1412
   213
    );
edouard@1412
   214
vb@955
   215
// own_identities_retrieve() - retrieve all own identities
Edouard@584
   216
//
Edouard@584
   217
//  parameters:
vb@955
   218
//      session (in)            session to use
vb@955
   219
//      own_identities (out)    list of own identities
Edouard@584
   220
//
Edouard@584
   221
//  caveat:
vb@1133
   222
//      the ownership of the copy of own_identities goes to the caller
Edouard@584
   223
vb@955
   224
DYNAMIC_API PEP_STATUS own_identities_retrieve(
Edouard@584
   225
        PEP_SESSION session,
vb@955
   226
        identity_list **own_identities
Edouard@584
   227
    );
Edouard@410
   228
krista@1357
   229
PEP_STATUS contains_priv_key(PEP_SESSION session, const char *fpr,
krista@1357
   230
                             bool *has_private);
krista@1357
   231
edouard@1412
   232
// _own_keys_retrieve() - retrieve all flagged keypair fingerprints 
edouard@1412
   233
//
edouard@1412
   234
//  parameters:
edouard@1412
   235
//      session (in)            session to use
edouard@1412
   236
//      keylist (out)           list of fingerprints
edouard@1412
   237
//      excluded_flags (int)    flags to exclude from results
edouard@1412
   238
//
edouard@1412
   239
//  caveat:
edouard@1412
   240
//      the ownership of the list goes to the caller
edouard@1412
   241
DYNAMIC_API PEP_STATUS _own_keys_retrieve(
edouard@1412
   242
        PEP_SESSION session,
edouard@1412
   243
        stringlist_t **keylist,
edouard@1412
   244
        identity_flags_t excluded_flags
edouard@1412
   245
      );
edouard@1412
   246
edouard@1394
   247
// own_keys_retrieve() - retrieve all flagged keypair fingerprints 
edouard@1370
   248
//
edouard@1370
   249
//  parameters:
edouard@1370
   250
//      session (in)            session to use
edouard@1370
   251
//      keylist (out)           list of fingerprints
edouard@1370
   252
//
edouard@1370
   253
//  caveat:
edouard@1370
   254
//      the ownership of the list goes to the caller
edouard@1394
   255
DYNAMIC_API PEP_STATUS own_keys_retrieve(
edouard@1370
   256
        PEP_SESSION session,
edouard@1370
   257
        stringlist_t **keylist
edouard@1370
   258
      );
edouard@1370
   259
edouard@1752
   260
DYNAMIC_API PEP_STATUS set_own_key(
edouard@1752
   261
       PEP_SESSION session,
edouard@1752
   262
       const char *address,
edouard@1752
   263
       const char *fpr
edouard@1752
   264
    );
edouard@1752
   265
vb@0
   266
#ifdef __cplusplus
vb@0
   267
}
vb@0
   268
#endif