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