p≡p engine fork for my own dirty testing of stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1604 lines
58 KiB

8 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
4 years ago
4 years ago
4 years ago
3 years ago
8 years ago
4 years ago
4 years ago
8 years ago
8 years ago
4 years ago
8 years ago
4 years ago
8 years ago
4 years ago
4 years ago
8 years ago
8 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
3 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
3 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
7 years ago
7 years ago
8 years ago
8 years ago
6 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
8 years ago
  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. #pragma once
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <stddef.h>
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include "dynamic_api.h"
  11. #include "stringlist.h"
  12. #include "stringpair.h"
  13. #include "labeled_int_list.h"
  14. #include "timestamp.h"
  15. #define PEP_VERSION "2.1" // pEp *protocol* version
  16. // RELEASE version this targets
  17. // (string: major.minor.patch)
  18. #define PEP_ENGINE_VERSION "2.1.0"
  19. #define PEP_ENGINE_VERSION_MAJOR 2
  20. #define PEP_ENGINE_VERSION_MINOR 1
  21. #define PEP_ENGINE_VERSION_PATCH 0
  22. #define PEP_ENGINE_VERSION_RC 16
  23. #define PEP_OWN_USERID "pEp_own_userId"
  24. // pEp Engine API
  25. // caveat:
  26. // Unicode data has to be normalized to NFC before calling
  27. // UTF-8 strings are UTF-8 encoded C strings (zero terminated)
  28. struct _pEpSession;
  29. typedef struct _pEpSession * PEP_SESSION;
  30. typedef enum {
  31. PEP_STATUS_OK = 0,
  32. PEP_INIT_CANNOT_LOAD_CRYPTO_LIB = 0x0110,
  33. PEP_INIT_CRYPTO_LIB_INIT_FAILED = 0x0111,
  34. PEP_INIT_NO_CRYPTO_HOME = 0x0112,
  35. // PEP_INIT_NETPGP_INIT_FAILED = 0x0113,
  36. PEP_INIT_CANNOT_DETERMINE_CRYPTO_VERSION = 0x0114,
  37. PEP_INIT_UNSUPPORTED_CRYPTO_VERSION = 0x0115,
  38. PEP_INIT_CANNOT_CONFIG_CRYPTO_AGENT = 0x0116,
  39. PEP_INIT_SQLITE3_WITHOUT_MUTEX = 0x0120,
  40. PEP_INIT_CANNOT_OPEN_DB = 0x0121,
  41. PEP_INIT_CANNOT_OPEN_SYSTEM_DB = 0x0122,
  42. PEP_INIT_DB_DOWNGRADE_VIOLATION = 0x0123,
  43. PEP_UNKNOWN_DB_ERROR = 0x01ff,
  44. PEP_KEY_NOT_FOUND = 0x0201,
  45. PEP_KEY_HAS_AMBIG_NAME = 0x0202,
  46. PEP_GET_KEY_FAILED = 0x0203,
  47. PEP_CANNOT_EXPORT_KEY = 0x0204,
  48. PEP_CANNOT_EDIT_KEY = 0x0205,
  49. PEP_KEY_UNSUITABLE = 0x0206,
  50. PEP_MALFORMED_KEY_RESET_MSG = 0x0210,
  51. PEP_KEY_NOT_RESET = 0x0211,
  52. PEP_CANNOT_DELETE_KEY = 0x0212,
  53. PEP_KEY_IMPORTED = 0x0220,
  54. PEP_NO_KEY_IMPORTED = 0x0221,
  55. PEP_KEY_IMPORT_STATUS_UNKNOWN = 0x0222,
  56. PEP_SOME_KEYS_IMPORTED = 0x0223,
  57. PEP_CANNOT_FIND_IDENTITY = 0x0301,
  58. PEP_CANNOT_SET_PERSON = 0x0381,
  59. PEP_CANNOT_SET_PGP_KEYPAIR = 0x0382,
  60. PEP_CANNOT_SET_IDENTITY = 0x0383,
  61. PEP_CANNOT_SET_TRUST = 0x0384,
  62. PEP_KEY_BLACKLISTED = 0x0385,
  63. PEP_CANNOT_FIND_PERSON = 0x0386,
  64. PEP_CANNOT_SET_PEP_VERSION = 0X0387,
  65. PEP_CANNOT_FIND_ALIAS = 0x0391,
  66. PEP_CANNOT_SET_ALIAS = 0x0392,
  67. PEP_UNENCRYPTED = 0x0400,
  68. PEP_VERIFIED = 0x0401,
  69. PEP_DECRYPTED = 0x0402,
  70. PEP_DECRYPTED_AND_VERIFIED = 0x0403,
  71. PEP_DECRYPT_WRONG_FORMAT = 0x0404,
  72. PEP_DECRYPT_NO_KEY = 0x0405,
  73. PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH = 0x0406,
  74. PEP_VERIFY_NO_KEY = 0x0407,
  75. PEP_VERIFIED_AND_TRUSTED = 0x0408,
  76. PEP_CANNOT_REENCRYPT = 0x0409,
  77. PEP_VERIFY_SIGNER_KEY_REVOKED = 0x040a,
  78. PEP_CANNOT_DECRYPT_UNKNOWN = 0x04ff,
  79. PEP_TRUSTWORD_NOT_FOUND = 0x0501,
  80. PEP_TRUSTWORDS_FPR_WRONG_LENGTH = 0x0502,
  81. PEP_TRUSTWORDS_DUPLICATE_FPR = 0x0503,
  82. PEP_CANNOT_CREATE_KEY = 0x0601,
  83. PEP_CANNOT_SEND_KEY = 0x0602,
  84. PEP_PHRASE_NOT_FOUND = 0x0701,
  85. PEP_SEND_FUNCTION_NOT_REGISTERED = 0x0801,
  86. PEP_CONTRAINTS_VIOLATED = 0x0802,
  87. PEP_CANNOT_ENCODE = 0x0803,
  88. PEP_SYNC_NO_NOTIFY_CALLBACK = 0x0901,
  89. PEP_SYNC_ILLEGAL_MESSAGE = 0x0902,
  90. PEP_SYNC_NO_INJECT_CALLBACK = 0x0903,
  91. PEP_SYNC_NO_CHANNEL = 0x0904,
  92. PEP_SYNC_CANNOT_ENCRYPT = 0x0905,
  93. PEP_SYNC_NO_MESSAGE_SEND_CALLBACK = 0x0906,
  94. PEP_SYNC_CANNOT_START = 0x0907,
  95. PEP_CANNOT_INCREASE_SEQUENCE = 0x0971,
  96. PEP_STATEMACHINE_ERROR = 0x0980,
  97. PEP_NO_TRUST = 0x0981,
  98. PEP_STATEMACHINE_INVALID_STATE = 0x0982,
  99. PEP_STATEMACHINE_INVALID_EVENT = 0x0983,
  100. PEP_STATEMACHINE_INVALID_CONDITION = 0x0984,
  101. PEP_STATEMACHINE_INVALID_ACTION = 0x0985,
  102. PEP_STATEMACHINE_INHIBITED_EVENT = 0x0986,
  103. PEP_STATEMACHINE_CANNOT_SEND = 0x0987,
  104. PEP_PASSPHRASE_REQUIRED = 0x0a00,
  105. PEP_WRONG_PASSPHRASE = 0x0a01,
  106. PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED = 0x0a02,
  107. PEP_DISTRIBUTION_ILLEGAL_MESSAGE = 0x1002,
  108. PEP_COMMIT_FAILED = 0xff01,
  109. PEP_MESSAGE_CONSUME = 0xff02,
  110. PEP_MESSAGE_IGNORE = 0xff03,
  111. PEP_CANNOT_CONFIG = 0xff04,
  112. PEP_RECORD_NOT_FOUND = -6,
  113. PEP_CANNOT_CREATE_TEMP_FILE = -5,
  114. PEP_ILLEGAL_VALUE = -4,
  115. PEP_BUFFER_TOO_SMALL = -3,
  116. PEP_OUT_OF_MEMORY = -2,
  117. PEP_UNKNOWN_ERROR = -1,
  118. PEP_VERSION_MISMATCH = -7,
  119. } PEP_STATUS;
  120. typedef enum _PEP_enc_format {
  121. PEP_enc_none = 0, // message is not encrypted
  122. PEP_enc_pieces = 1, // inline PGP + PGP extensions, was removed
  123. PEP_enc_inline = 1, // still there
  124. PEP_enc_S_MIME, // RFC5751
  125. PEP_enc_PGP_MIME, // RFC3156
  126. PEP_enc_PEP, // pEp encryption format
  127. PEP_enc_PGP_MIME_Outlook1, // Message B0rken by Outlook type 1
  128. PEP_enc_inline_EA,
  129. PEP_enc_auto = 255 // figure out automatically where possible
  130. } PEP_enc_format;
  131. // messageToSend() - a message needs to be delivered by application
  132. //
  133. // parameters:
  134. // msg (in) message struct with message to send
  135. //
  136. // return value:
  137. // PEP_STATUS_OK or any other value on error
  138. //
  139. // caveat:
  140. // the ownership of msg goes to the callee
  141. struct _message;
  142. typedef PEP_STATUS (*messageToSend_t)(struct _message *msg);
  143. struct Sync_event;
  144. typedef struct Sync_event *SYNC_EVENT;
  145. // free_Sync_event() - free memory occupied by sync protocol message
  146. //
  147. // parameters:
  148. // ev (in) event to free
  149. DYNAMIC_API void free_Sync_event(SYNC_EVENT ev);
  150. // inject_sync_event - inject sync protocol message
  151. //
  152. // parameters:
  153. // ev (in) event to inject
  154. // management (in) application defined; usually a locked queue
  155. //
  156. // return value:
  157. // 0 if event could be stored successfully or nonzero otherwise
  158. //
  159. // caveat:
  160. // if ev is SHUTDOWN then the implementation has to be synchronous
  161. // and the shutdown must be immediate
  162. typedef int (*inject_sync_event_t)(SYNC_EVENT ev, void *management);
  163. // INIT_STATUS init() - initialize pEpEngine for a thread
  164. //
  165. // parameters:
  166. // session (out) init() allocates session memory and
  167. // returns a pointer as a handle
  168. // messageToSend (in) callback for sending message by the
  169. // application
  170. // inject_sync_event (in) callback for injecting a sync event
  171. //
  172. // return value:
  173. // PEP_STATUS_OK = 0 if init() succeeds
  174. // PEP_INIT_SQLITE3_WITHOUT_MUTEX if SQLite3 was compiled with
  175. // SQLITE_THREADSAFE 0
  176. // PEP_INIT_CANNOT_LOAD_CRYPTO_LIB if crypto lin cannot be found
  177. // PEP_INIT_CRYPTO_LIB_INIT_FAILED if CRYPTO_LIB init fails
  178. // PEP_INIT_CANNOT_OPEN_DB if user's management db cannot be
  179. // opened
  180. // PEP_INIT_CANNOT_OPEN_SYSTEM_DB if system's management db cannot be
  181. // opened
  182. //
  183. // caveat:
  184. // THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. release()
  185. // should be similarly guarded.
  186. //
  187. // the pointer is valid only if the return value is PEP_STATUS_OK
  188. // in other case a NULL pointer will be returned; a valid handle must
  189. // be released using release() when it's no longer needed
  190. //
  191. // the caller has to guarantee that the first call to this function
  192. // will succeed before further calls can be done
  193. //
  194. // messageToSend can only be null if no transport is application based
  195. // if transport system is not used it must not be NULL
  196. DYNAMIC_API PEP_STATUS init(
  197. PEP_SESSION *session,
  198. messageToSend_t messageToSend,
  199. inject_sync_event_t inject_sync_event
  200. );
  201. // void release() - release thread session handle
  202. //
  203. // parameters:
  204. // session (in) session handle to release
  205. //
  206. // caveat:
  207. // THE CALLER MUST GUARD THIS CALL EXTERNALLY WITH A MUTEX. init() should
  208. // be similarly guarded.
  209. //
  210. // the last release() can be called only when all other release() calls
  211. // are done
  212. DYNAMIC_API void release(PEP_SESSION session);
  213. // const stringlist_t* get_errorstack(PEP_SESSION) - get the error stack for that session, if any
  214. //
  215. // parameters:
  216. // session (in) session handle
  217. //
  218. // caveat:
  219. // To get a useful error stack you have to compile with -DDEBUG_ERRORSTACK
  220. // The error stack belongs to the session. Do no not change it!
  221. DYNAMIC_API const stringlist_t* get_errorstack(PEP_SESSION session);
  222. // void clear_errorstack(PEP_SESSION) - clear the error stack for that session, if any
  223. //
  224. // parameters:
  225. // session (in) session handle
  226. //
  227. DYNAMIC_API void clear_errorstack(PEP_SESSION session);
  228. // config_passive_mode() - enable passive mode
  229. //
  230. // parameters:
  231. // session (in) session handle
  232. // enable (in) flag if enabled or disabled
  233. DYNAMIC_API void config_passive_mode(PEP_SESSION session, bool enable);
  234. // config_unencrypted_subject() - disable subject encryption
  235. //
  236. // parameters:
  237. // session (in) session handle
  238. // enable (in) flag if enabled or disabled
  239. DYNAMIC_API void config_unencrypted_subject(PEP_SESSION session, bool enable);
  240. // config_use_only_own_private_keys() - enable passive mode
  241. //
  242. // parameters:
  243. // session (in) session handle
  244. // enable (in) flag if enabled or disabled
  245. DYNAMIC_API void config_use_only_own_private_keys(PEP_SESSION session, bool enable);
  246. // config_service_log() - log more for service purposes
  247. //
  248. // session (in) session handle
  249. // enable (in) flag if enabled or disabled
  250. DYNAMIC_API void config_service_log(PEP_SESSION session, bool enable);
  251. typedef enum {
  252. PEP_CIPHER_SUITE_DEFAULT = 0,
  253. PEP_CIPHER_SUITE_CV25519 = 1,
  254. PEP_CIPHER_SUITE_P256 = 2,
  255. PEP_CIPHER_SUITE_P384 = 3,
  256. PEP_CIPHER_SUITE_P521 = 4,
  257. PEP_CIPHER_SUITE_RSA2K = 5,
  258. PEP_CIPHER_SUITE_RSA3K = 6,
  259. PEP_CIPHER_SUITE_RSA4K = 7,
  260. PEP_CIPHER_SUITE_RSA8K = 8
  261. } PEP_CIPHER_SUITE;
  262. // config_cipher_suite() - cipher suite being used when encrypting
  263. //
  264. // parameters:
  265. // session (in) session handle
  266. // cipher_suite (in) cipher suite to use
  267. //
  268. // return value:
  269. // PEP_STATUS_OK cipher suite configured
  270. // PEP_CANNOT_CONFIG configuration failed; falling back to default
  271. //
  272. // caveat: the default ciphersuite for a crypt tech implementation is
  273. // implementation defined
  274. DYNAMIC_API PEP_STATUS config_cipher_suite(PEP_SESSION session,
  275. PEP_CIPHER_SUITE suite);
  276. // decrypt_and_verify() - decrypt and/or verify a message
  277. //
  278. // parameters:
  279. // session (in) session handle
  280. // ctext (in) cipher text to decrypt and/or verify
  281. // csize (in) size of cipher text
  282. // dsigtext (in) if extant, *detached* signature text for this
  283. // message (or NULL if not)
  284. // dsize (in) size of *detached* signature text for this
  285. // message (0, if no detached sig exists)
  286. // ptext (out) pointer to internal buffer with plain text
  287. // psize (out) size of plain text
  288. // keylist (out) list of key ids which where used to encrypt
  289. // filename_ptr (out) mails produced by certain PGP implementations
  290. // may return a decrypted filename here for attachments.
  291. // Externally, this can generally be NULL, and is an optional
  292. // parameter.
  293. //
  294. // return value:
  295. // PEP_UNENCRYPTED message was unencrypted and not signed
  296. // PEP_VERIFIED message was unencrypted, signature matches
  297. // PEP_DECRYPTED message is decrypted now, no signature
  298. // PEP_DECRYPTED_AND_VERIFIED message is decrypted now and verified
  299. // PEP_DECRYPT_WRONG_FORMAT message has wrong format to handle
  300. // PEP_DECRYPT_NO_KEY key not available to decrypt and/or verify
  301. // PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH wrong signature
  302. //
  303. // caveat:
  304. // the ownerships of ptext as well as keylist are going to the caller
  305. // the caller must use free() (or an Windoze pEp_free()) and
  306. // free_stringlist() to free them
  307. //
  308. // if this function failes an error message may be the first element of
  309. // keylist and the other elements may be the keys used for encryption
  310. DYNAMIC_API PEP_STATUS decrypt_and_verify(
  311. PEP_SESSION session, const char *ctext, size_t csize,
  312. const char *dsigtext, size_t dsigsize,
  313. char **ptext, size_t *psize, stringlist_t **keylist,
  314. char ** filename_ptr
  315. );
  316. // verify_text() - verfy plain text with a digital signature
  317. //
  318. // parameters:
  319. // session (in) session handle
  320. // text (in) text to verify
  321. // size (in) size of text
  322. // signature (in) signature text
  323. // sig_size (in) size of signature
  324. // keylist (out) list of key ids which where used to encrypt or NULL on
  325. // error
  326. //
  327. // return value:
  328. // PEP_VERIFIED message was unencrypted, signature matches
  329. // PEP_DECRYPT_NO_KEY key not available to decrypt and/or verify
  330. // PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH wrong signature
  331. DYNAMIC_API PEP_STATUS verify_text(
  332. PEP_SESSION session, const char *text, size_t size,
  333. const char *signature, size_t sig_size, stringlist_t **keylist
  334. );
  335. // encrypt_and_sign() - encrypt and sign a message
  336. //
  337. // parameters:
  338. // session (in) session handle
  339. // keylist (in) list of key ids to encrypt with as C strings
  340. // ptext (in) plain text to decrypt and/or verify
  341. // psize (in) size of plain text
  342. // ctext (out) pointer to internal buffer with cipher text
  343. // csize (out) size of cipher text
  344. //
  345. // return value:
  346. // PEP_STATUS_OK = 0 encryption and signing succeeded
  347. // PEP_KEY_NOT_FOUND at least one of the recipient keys
  348. // could not be found
  349. // PEP_KEY_HAS_AMBIG_NAME at least one of the recipient keys has
  350. // an ambiguous name
  351. // PEP_GET_KEY_FAILED cannot retrieve key
  352. //
  353. // caveat:
  354. // the ownership of ctext is going to the caller
  355. // the caller is responsible to free() it (on Windoze use pEp_free())
  356. // the first key in keylist is being used to sign the message
  357. // this implies there has to be a private key for that keypair
  358. DYNAMIC_API PEP_STATUS encrypt_and_sign(
  359. PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
  360. size_t psize, char **ctext, size_t *csize
  361. );
  362. DYNAMIC_API void set_debug_color(PEP_SESSION session, int ansi_color);
  363. // log_event() - log a user defined event defined by UTF-8 encoded strings into
  364. // management log
  365. //
  366. // parameters:
  367. // session (in) session handle
  368. // title (in) C string with event name
  369. // entity (in) C string with name of entity which is logging
  370. // description (in) C string with long description for event or NULL if
  371. // omitted
  372. // comment (in) C string with user defined comment or NULL if
  373. // omitted
  374. //
  375. // return value:
  376. // PEP_STATUS_OK log entry created
  377. DYNAMIC_API PEP_STATUS log_event(
  378. PEP_SESSION session,
  379. const char *title,
  380. const char *entity,
  381. const char *description,
  382. const char *comment
  383. );
  384. DYNAMIC_API PEP_STATUS log_service(PEP_SESSION session, const char *title,
  385. const char *entity, const char *description, const char *comment);
  386. #define _STR_(x) #x
  387. #define _D_STR_(x) _STR_(x)
  388. #define S_LINE _D_STR_(__LINE__)
  389. #define SERVICE_LOG(session, title, entity, desc) \
  390. log_service((session), (title), (entity), (desc), "service " __FILE__ ":" S_LINE)
  391. DYNAMIC_API void _service_error_log(PEP_SESSION session, const char *entity,
  392. PEP_STATUS status, const char *where);
  393. #define SERVICE_ERROR_LOG(session, entity, status) \
  394. _service_error_log((session), (entity), (status), __FILE__ ":" S_LINE)
  395. // trustword() - get the corresponding trustword for a 16 bit value
  396. //
  397. // parameters:
  398. // session (in) session handle
  399. // value (in) value to find a trustword for
  400. // lang (in) C string with ISO 639-1 language code
  401. // word (out) pointer to C string with trustword UTF-8 encoded
  402. // NULL if language is not supported or trustword
  403. // wordlist is damaged or unavailable
  404. // wsize (out) length of trustword
  405. //
  406. // return value:
  407. // PEP_STATUS_OK trustword retrieved
  408. // PEP_TRUSTWORD_NOT_FOUND trustword not found
  409. //
  410. // caveat:
  411. // the word pointer goes to the ownership of the caller
  412. // the caller is responsible to free() it (on Windoze use pEp_free())
  413. DYNAMIC_API PEP_STATUS trustword(
  414. PEP_SESSION session, uint16_t value, const char *lang,
  415. char **word, size_t *wsize
  416. );
  417. // trustwords() - get trustwords for a string of hex values of a fingerprint
  418. //
  419. // parameters:
  420. // session (in) session handle
  421. // fingerprint (in) C string with hex values to find trustwords for
  422. // lang (in) C string with ISO 639-1 language code
  423. // words (out) pointer to C string with trustwords UTF-8 encoded,
  424. // separated by a blank each
  425. // NULL if language is not supported or trustword
  426. // wordlist is damaged or unavailable
  427. // wsize (out) length of trustwords string
  428. // max_words (in) only generate a string with max_words;
  429. // if max_words == 0 there is no such limit
  430. //
  431. // return value:
  432. // PEP_STATUS_OK trustwords retrieved
  433. // PEP_OUT_OF_MEMORY out of memory
  434. // PEP_TRUSTWORD_NOT_FOUND at least one trustword not found
  435. //
  436. // caveat:
  437. // the word pointer goes to the ownership of the caller
  438. // the caller is responsible to free() it (on Windoze use pEp_free())
  439. //
  440. // DON'T USE THIS FUNCTION FROM HIGH LEVEL LANGUAGES!
  441. //
  442. // Better implement a simple one in the adapter yourself using trustword(), and
  443. // return a list of trustwords.
  444. // This function is provided for being used by C and C++ programs only.
  445. DYNAMIC_API PEP_STATUS trustwords(
  446. PEP_SESSION session, const char *fingerprint, const char *lang,
  447. char **words, size_t *wsize, int max_words
  448. );
  449. // TODO: increase versions in pEp.asn1 if rating changes
  450. typedef enum _PEP_comm_type {
  451. PEP_ct_unknown = 0,
  452. // range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
  453. PEP_ct_no_encryption = 0x01, // generic
  454. PEP_ct_no_encrypted_channel = 0x02,
  455. PEP_ct_key_not_found = 0x03,
  456. PEP_ct_key_expired = 0x04,
  457. PEP_ct_key_revoked = 0x05,
  458. PEP_ct_key_b0rken = 0x06,
  459. PEP_ct_key_expired_but_confirmed = 0x07, // NOT with confirmed bit. Just retaining info here in case of renewal.
  460. PEP_ct_my_key_not_included = 0x09,
  461. PEP_ct_security_by_obscurity = 0x0a,
  462. PEP_ct_b0rken_crypto = 0x0b,
  463. PEP_ct_key_too_short = 0x0c,
  464. PEP_ct_compromised = 0x0e, // known compromised connection
  465. PEP_ct_compromized = 0x0e, // deprecated misspelling
  466. PEP_ct_mistrusted = 0x0f, // known mistrusted key
  467. // range 0x10 to 0x3f: unconfirmed encryption
  468. PEP_ct_unconfirmed_encryption = 0x10, // generic
  469. PEP_ct_OpenPGP_weak_unconfirmed = 0x11, // RSA 1024 is weak
  470. PEP_ct_to_be_checked = 0x20, // generic
  471. PEP_ct_SMIME_unconfirmed = 0x21,
  472. PEP_ct_CMS_unconfirmed = 0x22,
  473. PEP_ct_strong_but_unconfirmed = 0x30, // generic
  474. PEP_ct_OpenPGP_unconfirmed = 0x38, // key at least 2048 bit RSA or EC
  475. PEP_ct_OTR_unconfirmed = 0x3a,
  476. // range 0x40 to 0x7f: unconfirmed encryption and anonymization
  477. PEP_ct_unconfirmed_enc_anon = 0x40, // generic
  478. PEP_ct_pEp_unconfirmed = 0x7f,
  479. PEP_ct_confirmed = 0x80, // this bit decides if trust is confirmed
  480. // range 0x81 to 0x8f: reserved
  481. // range 0x90 to 0xbf: confirmed encryption
  482. PEP_ct_confirmed_encryption = 0x90, // generic
  483. PEP_ct_OpenPGP_weak = 0x91, // RSA 1024 is weak (unused)
  484. PEP_ct_to_be_checked_confirmed = 0xa0, // generic
  485. PEP_ct_SMIME = 0xa1,
  486. PEP_ct_CMS = 0xa2,
  487. PEP_ct_strong_encryption = 0xb0, // generic
  488. PEP_ct_OpenPGP = 0xb8, // key at least 2048 bit RSA or EC
  489. PEP_ct_OTR = 0xba,
  490. // range 0xc0 to 0xff: confirmed encryption and anonymization
  491. PEP_ct_confirmed_enc_anon = 0xc0, // generic
  492. PEP_ct_pEp = 0xff
  493. } PEP_comm_type;
  494. typedef enum _identity_flags {
  495. // the first octet flags are app defined settings
  496. PEP_idf_not_for_sync = 0x0001, // don't use this identity for sync
  497. PEP_idf_list = 0x0002, // identity of list of persons
  498. // the second octet flags are calculated
  499. PEP_idf_devicegroup = 0x0100 // identity of a device group member
  500. } identity_flags;
  501. typedef unsigned int identity_flags_t;
  502. // typedef enum _keypair_flags {
  503. // } keypair_flags;
  504. typedef unsigned int keypair_flags_t;
  505. typedef struct _pEp_identity {
  506. char *address; // C string with address UTF-8 encoded
  507. char *fpr; // C string with fingerprint UTF-8 encoded
  508. char *user_id; // C string with user ID UTF-8 encoded
  509. // user_id MIGHT be set to "pEp_own_userId"
  510. // (use PEP_OWN_USERID preprocessor define)
  511. // if this is own user's identity.
  512. // But it is not REQUIRED to be.
  513. char *username; // C string with user name UTF-8 encoded
  514. PEP_comm_type comm_type; // type of communication with this ID
  515. char lang[3]; // language of conversation
  516. // ISO 639-1 ALPHA-2, last byte is 0
  517. bool me; // if this is the local user herself/himself
  518. unsigned int major_ver; // highest version of pEp message received, if any
  519. unsigned int minor_ver; // highest version of pEp message received, if any
  520. PEP_enc_format enc_format; // Last specified format we encrypted to for this identity
  521. identity_flags_t flags; // identity_flag1 | identity_flag2 | ...
  522. } pEp_identity;
  523. typedef struct _identity_list {
  524. pEp_identity *ident;
  525. struct _identity_list *next;
  526. } identity_list;
  527. // new_identity() - allocate memory and set the string and size fields
  528. //
  529. // parameters:
  530. // address (in) UTF-8 string or NULL
  531. // fpr (in) UTF-8 string or NULL
  532. // user_id (in) UTF-8 string or NULL
  533. // username (in) UTF-8 string or NULL
  534. //
  535. // return value:
  536. // pEp_identity struct or NULL if out of memory
  537. //
  538. // caveat:
  539. // the strings are copied; the original strings are still being owned by
  540. // the caller
  541. DYNAMIC_API pEp_identity *new_identity(
  542. const char *address, const char *fpr, const char *user_id,
  543. const char *username
  544. );
  545. // identity_dup() - allocate memory and duplicate
  546. //
  547. // parameters:
  548. // src (in) identity to duplicate
  549. //
  550. // return value:
  551. // pEp_identity struct or NULL if out of memory
  552. //
  553. // caveat:
  554. // the strings are copied; the original strings are still being owned by
  555. // the caller
  556. DYNAMIC_API pEp_identity *identity_dup(const pEp_identity *src);
  557. // free_identity() - free all memory being occupied by a pEp_identity struct
  558. //
  559. // parameters:
  560. // identity (in) struct to release
  561. //
  562. // caveat:
  563. // not only the struct but also all string memory referenced by the
  564. // struct is being freed; all pointers inside are invalid afterwards
  565. DYNAMIC_API void free_identity(pEp_identity *identity);
  566. // get_identity() - get identity information
  567. //
  568. // parameters:
  569. // session (in) session handle
  570. // address (in) C string with communication address, UTF-8 encoded
  571. // user_id (in) unique C string to identify person that identity
  572. // is refering to
  573. // identity (out) pointer to pEp_identity structure with results or
  574. // NULL if failure
  575. //
  576. // caveat:
  577. // address and user_id are being copied; the original strings remains in
  578. // the ownership of the caller
  579. // the resulting pEp_identity structure goes to the ownership of the
  580. // caller and has to be freed with free_identity() when not in use any
  581. // more
  582. DYNAMIC_API PEP_STATUS get_identity(
  583. PEP_SESSION session,
  584. const char *address,
  585. const char *user_id,
  586. pEp_identity **identity
  587. );
  588. PEP_STATUS replace_identities_fpr(PEP_SESSION session,
  589. const char* old_fpr,
  590. const char* new_fpr);
  591. // set_identity() - set identity information
  592. //
  593. // parameters:
  594. // session (in) session handle
  595. // identity (in) pointer to pEp_identity structure
  596. //
  597. // return value:
  598. // PEP_STATUS_OK = 0 encryption and signing succeeded
  599. // PEP_CANNOT_SET_PERSON writing to table person failed
  600. // PEP_CANNOT_SET_PGP_KEYPAIR writing to table pgp_keypair failed
  601. // PEP_CANNOT_SET_IDENTITY writing to table identity failed
  602. // PEP_COMMIT_FAILED SQL commit failed
  603. //
  604. // caveat:
  605. // address, fpr, user_id and username must be given
  606. DYNAMIC_API PEP_STATUS set_identity(
  607. PEP_SESSION session, const pEp_identity *identity
  608. );
  609. // get_default own_userid() - get the user_id of the own user
  610. //
  611. // parameters:
  612. // session (in) session handle
  613. // userid (out) own user id (if it exists)
  614. //
  615. // return value:
  616. // PEP_STATUS_OK = 0 userid was found
  617. // PEP_CANNOT_FIND_IDENTITY no own_user found in the DB
  618. // PEP_UNKNOWN_ERROR results were returned, but no ID
  619. // found (no reason this should ever occur)
  620. // caveat:
  621. // userid will be NULL if not found; otherwise, returned string
  622. // belongs to the caller.
  623. DYNAMIC_API PEP_STATUS get_default_own_userid(
  624. PEP_SESSION session,
  625. char** userid
  626. );
  627. // get_userid_alias_default() - get the default user_id which corresponds
  628. // to an alias
  629. // parameters:
  630. // session (in) session handle
  631. // alias_id (in) the user_id which may be an alias for a default id
  632. // default_id (out) the default id for this alias, if the alias
  633. // is in the DB as an alias, else NULL
  634. // return value:
  635. // PEP_STATUS_OK = 0 userid was found
  636. // PEP_CANNOT_FIND_ALIAS this userid is not listed as an
  637. // alias in the DB
  638. // PEP_UNKNOWN_ERROR results were returned, but no ID
  639. // found (no reason this should ever occur)
  640. // caveat:
  641. // default_id will be NULL if not found; otherwise, returned string
  642. // belongs to the caller.
  643. // also, current implementation does NOT check to see if this userid
  644. // IS a default.
  645. DYNAMIC_API PEP_STATUS get_userid_alias_default(
  646. PEP_SESSION session,
  647. const char* alias_id,
  648. char** default_id);
  649. // set_userid_alias() - set an alias to correspond to a default id
  650. // parameters:
  651. // session (in) session handle
  652. // default_id (in) the default id for this alias. This must
  653. // correspond to the default user_id for an
  654. // entry in the person (user) table.
  655. // alias_id (in) the alias to be set for this default id
  656. // return value:
  657. // PEP_STATUS_OK = 0 userid was found
  658. // PEP_CANNOT_SET_ALIAS there was an error setting this
  659. DYNAMIC_API PEP_STATUS set_userid_alias (
  660. PEP_SESSION session,
  661. const char* default_id,
  662. const char* alias_id);
  663. // set_identity_flags() - update identity flags on existing identity
  664. //
  665. // parameters:
  666. // session (in) session handle
  667. // identity (in,out) pointer to pEp_identity structure
  668. // flags (in) new value for flags
  669. //
  670. // return value:
  671. // PEP_STATUS_OK = 0 encryption and signing succeeded
  672. // PEP_CANNOT_SET_IDENTITY update of identity failed
  673. //
  674. // caveat:
  675. // address and user_id must be given in identity
  676. DYNAMIC_API PEP_STATUS set_identity_flags(
  677. PEP_SESSION session,
  678. pEp_identity *identity,
  679. identity_flags_t flags
  680. );
  681. // unset_identity_flags() - update identity flags on existing identity
  682. //
  683. // parameters:
  684. // session (in) session handle
  685. // identity (in,out) pointer to pEp_identity structure
  686. // flags (in) new value for flags
  687. //
  688. // return value:
  689. // PEP_STATUS_OK = 0 encryption and signing succeeded
  690. // PEP_CANNOT_SET_IDENTITY update of identity failed
  691. //
  692. // caveat:
  693. // address and user_id must be given in identity
  694. DYNAMIC_API PEP_STATUS unset_identity_flags(
  695. PEP_SESSION session,
  696. pEp_identity *identity,
  697. identity_flags_t flags
  698. );
  699. // mark_as_compromised() - mark key in trust db as compromised
  700. //
  701. // parameters:
  702. // session (in) session handle
  703. // fpr (in) fingerprint of key to mark
  704. DYNAMIC_API PEP_STATUS mark_as_compromised(
  705. PEP_SESSION session,
  706. const char *fpr
  707. );
  708. // mark_as_compromized() - deprecated to fix misspelling. Please move to
  709. // mark_as_compromised();
  710. DYNAMIC_API PEP_STATUS mark_as_compromized(
  711. PEP_SESSION session,
  712. const char *fpr
  713. );
  714. // generate_keypair() - generate a new key pair and add it to the key ring
  715. //
  716. // parameters:
  717. // session (in) session handle
  718. // identity (inout) pointer to pEp_identity structure
  719. //
  720. // return value:
  721. // PEP_STATUS_OK = 0 encryption and signing succeeded
  722. // PEP_ILLEGAL_VALUE illegal values for identity fields given
  723. // PEP_CANNOT_CREATE_KEY key engine is on strike
  724. //
  725. // caveat:
  726. // address must be set to UTF-8 string
  727. // the fpr field must be set to NULL
  728. // username field must either be NULL or be a UTF8-string conforming
  729. // to RFC4880 for PGP uid usernames
  730. //
  731. // this function allocates a string and sets set fpr field of identity
  732. // the caller is responsible to call free() for that string or use
  733. // free_identity() on the struct
  734. DYNAMIC_API PEP_STATUS generate_keypair(
  735. PEP_SESSION session, pEp_identity *identity
  736. );
  737. // delete_keypair() - delete a public key or a key pair from the key ring
  738. //
  739. // parameters:
  740. // session (in) session handle
  741. // fpr (in) C string with key id or fingerprint of the
  742. // public key
  743. //
  744. // return value:
  745. // PEP_STATUS_OK = 0 key was successfully deleted
  746. // PEP_KEY_NOT_FOUND key not found
  747. // PEP_ILLEGAL_VALUE not a valid key id or fingerprint
  748. // PEP_KEY_HAS_AMBIG_NAME fpr does not uniquely identify a key
  749. // PEP_OUT_OF_MEMORY out of memory
  750. DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr);
  751. // import_key() - import key from data
  752. //
  753. // parameters:
  754. // session (in) session handle
  755. // key_data (in) key data, i.e. ASCII armored OpenPGP key
  756. // size (in) amount of data to handle
  757. // private_keys (out) list of identities containing the
  758. // private keys that have been imported
  759. //
  760. // return value:
  761. // PEP_STATUS_OK = 0 key was successfully imported
  762. // PEP_OUT_OF_MEMORY out of memory
  763. // PEP_ILLEGAL_VALUE there is no key data to import
  764. //
  765. // caveat:
  766. // private_keys goes to the ownership of the caller
  767. // private_keys can be left NULL, it is then ignored
  768. DYNAMIC_API PEP_STATUS import_key(
  769. PEP_SESSION session,
  770. const char *key_data,
  771. size_t size,
  772. identity_list **private_keys
  773. );
  774. // _import_key_with_fpr_return() -
  775. // INTERNAL FUNCTION - import keys from data, return optional list
  776. // of fprs imported
  777. //
  778. // parameters:
  779. // session (in) session handle
  780. // key_data (in) key data, i.e. ASCII armored OpenPGP key
  781. // size (in) amount of data to handle
  782. // private_keys (out) list of identities containing the
  783. // private keys that have been imported
  784. // imported_keys (out) if non-NULL, list of actual keys imported
  785. // changed_public_keys (out) if non-NULL AND imported_keys is non-NULL:
  786. // bitvector - corresponds to the first 64 keys
  787. // imported. If nth bit is set, import changed a
  788. // key corresponding to the nth element in
  789. // imported keys (i.e. key was in DB and was
  790. // changed by import)
  791. //
  792. // return value:
  793. // PEP_STATUS_OK = 0 key was successfully imported
  794. // PEP_OUT_OF_MEMORY out of memory
  795. // PEP_ILLEGAL_VALUE there is no key data to import, or imported keys was NULL and
  796. // changed_public_keys was not
  797. //
  798. // caveat:
  799. // private_keys and imported_keys goes to the ownership of the caller
  800. // private_keys and imported_keys can be left NULL, it is then ignored
  801. // *** THIS IS THE ACTUAL FUNCTION IMPLEMENTED BY CRYPTOTECH "import_key" ***
  802. PEP_STATUS _import_key_with_fpr_return(
  803. PEP_SESSION session,
  804. const char *key_data,
  805. size_t size,
  806. identity_list** private_keys,
  807. stringlist_t** imported_keys,
  808. uint64_t* changed_public_keys // use as bit field for the first 64 changed keys
  809. );
  810. // export_key() - export ascii armored key
  811. //
  812. // parameters:
  813. // session (in) session handle
  814. // fpr (in) key id or fingerprint of key
  815. // key_data (out) ASCII armored OpenPGP key
  816. // size (out) amount of data to handle
  817. //
  818. // return value:
  819. // PEP_STATUS_OK = 0 key was successfully exported
  820. // PEP_OUT_OF_MEMORY out of memory
  821. // PEP_KEY_NOT_FOUND key not found
  822. //
  823. // caveat:
  824. // the key_data goes to the ownership of the caller
  825. // the caller is responsible to free() it (on Windoze use pEp_free())
  826. DYNAMIC_API PEP_STATUS export_key(
  827. PEP_SESSION session, const char *fpr, char **key_data, size_t *size
  828. );
  829. // export_secret_key() - export secret key ascii armored
  830. //
  831. // parameters:
  832. // session (in) session handle
  833. // fpr (in) fingerprint of key, at least 16 hex digits
  834. // key_data (out) ASCII armored OpenPGP secret key
  835. // size (out) amount of data to handle
  836. //
  837. // return value:
  838. // PEP_STATUS_OK = 0 key was successfully exported
  839. // PEP_OUT_OF_MEMORY out of memory
  840. // PEP_KEY_NOT_FOUND key not found
  841. // PEP_CANNOT_EXPORT_KEY cannot export secret key (i.e. it's on an HKS)
  842. //
  843. // caveat:
  844. // the key_data goes to the ownership of the caller
  845. // the caller is responsible to free() it (on Windoze use pEp_free())
  846. // beware of leaking secret key data - overwrite it in memory after use
  847. DYNAMIC_API PEP_STATUS export_secret_key(
  848. PEP_SESSION session, const char *fpr, char **key_data, size_t *size
  849. );
  850. // export_secrect_key() - deprecated misspelled function. Please replace with
  851. // export_secret_key
  852. DYNAMIC_API PEP_STATUS export_secrect_key(
  853. PEP_SESSION session, const char *fpr, char **key_data, size_t *size
  854. );
  855. // recv_key() - update key(s) from keyserver
  856. //
  857. // parameters:
  858. // session (in) session handle
  859. // pattern (in) key id, user id or address to search for as
  860. // UTF-8 string
  861. DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern);
  862. // find_keys() - find keys in keyring
  863. //
  864. // parameters:
  865. // session (in) session handle
  866. // pattern (in) key id, user id or address to search for as
  867. // UTF-8 string
  868. // keylist (out) list of fingerprints found or NULL on error
  869. //
  870. // caveat:
  871. // the ownerships of keylist isgoing to the caller
  872. // the caller must use free_stringlist() to free it
  873. DYNAMIC_API PEP_STATUS find_keys(
  874. PEP_SESSION session, const char *pattern, stringlist_t **keylist
  875. );
  876. // send_key() - send key(s) to keyserver
  877. //
  878. // parameters:
  879. // session (in) session handle
  880. // pattern (in) key id, user id or address to search for as
  881. // UTF-8 string
  882. DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern);
  883. // pEp_free() - free memory allocated by pEp engine
  884. //
  885. // parameters:
  886. // p (in) pointer to free
  887. //
  888. // The reason for this function is that heap management can be a pretty
  889. // complex task with Windoze. This free() version calls the free()
  890. // implementation of the C runtime library which was used to build pEp engine,
  891. // so you're using the correct heap. For more information, see:
  892. // <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
  893. DYNAMIC_API void pEp_free(void *p);
  894. // pEp_realloc() - reallocate memory allocated by pEp engine
  895. //
  896. // parameters:
  897. // p (in) pointer to free
  898. // size (in) new memory size
  899. //
  900. // returns:
  901. // pointer to allocated memory
  902. //
  903. // The reason for this function is that heap management can be a pretty
  904. // complex task with Windoze. This realloc() version calls the realloc()
  905. // implementation of the C runtime library which was used to build pEp engine,
  906. // so you're using the correct heap. For more information, see:
  907. // <http://msdn.microsoft.com/en-us/library/windows/desktop/aa366711(v=vs.85).aspx>
  908. DYNAMIC_API void *pEp_realloc(void *p, size_t size);
  909. // get_trust() - get the trust level a key has for a person
  910. //
  911. // parameters:
  912. // session (in) session handle
  913. // identity (inout) user_id and fpr to check as UTF-8 strings (in)
  914. // comm_type as result (out)
  915. //
  916. // this function modifies the given identity struct; the struct remains in
  917. // the ownership of the caller
  918. // if the trust level cannot be determined identity->comm_type is set
  919. // to PEP_ct_unknown
  920. DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity);
  921. PEP_STATUS set_trust(PEP_SESSION session,
  922. pEp_identity* identity);
  923. PEP_STATUS update_trust_for_fpr(PEP_SESSION session,
  924. const char* fpr,
  925. PEP_comm_type comm_type);
  926. // least_trust() - get the least known trust level for a key in the database
  927. //
  928. // parameters:
  929. // session (in) session handle
  930. // fpr (in) fingerprint of key to check
  931. // comm_type (out) least comm_type as result (out)
  932. //
  933. // if the trust level cannot be determined comm_type is set to PEP_ct_unknown
  934. DYNAMIC_API PEP_STATUS least_trust(
  935. PEP_SESSION session,
  936. const char *fpr,
  937. PEP_comm_type *comm_type
  938. );
  939. // get_key_rating() - get the rating a bare key has
  940. //
  941. // parameters:
  942. // session (in) session handle
  943. // fpr (in) unique identifyer for key as UTF-8 string
  944. // comm_type (out) key rating
  945. //
  946. // if an error occurs, *comm_type is set to PEP_ct_unknown and an error
  947. // is returned
  948. DYNAMIC_API PEP_STATUS get_key_rating(
  949. PEP_SESSION session,
  950. const char *fpr,
  951. PEP_comm_type *comm_type
  952. );
  953. // renew_key() - renew an expired key
  954. //
  955. // parameters:
  956. // session (in) session handle
  957. // fpr (in) ID of key to renew as UTF-8 string
  958. // ts (in) timestamp when key should expire or NULL for
  959. // default
  960. DYNAMIC_API PEP_STATUS renew_key(
  961. PEP_SESSION session,
  962. const char *fpr,
  963. const timestamp *ts
  964. );
  965. // revoke_key() - revoke a key
  966. //
  967. // parameters:
  968. // session (in) session handle
  969. // fpr (in) ID of key to revoke as UTF-8 string
  970. // reason (in) text with reason for revoke as UTF-8 string
  971. // or NULL if reason unknown
  972. //
  973. // caveat:
  974. // reason text must not include empty lines
  975. // this function is meant for internal use only; better use
  976. // key_mistrusted() of keymanagement API
  977. DYNAMIC_API PEP_STATUS revoke_key(
  978. PEP_SESSION session,
  979. const char *fpr,
  980. const char *reason
  981. );
  982. // key_expired() - flags if a key is already expired
  983. //
  984. // parameters:
  985. // session (in) session handle
  986. // fpr (in) ID of key to check as UTF-8 string
  987. // when (in) UTC time of when should expiry be considered
  988. // expired (out) flag if key expired
  989. DYNAMIC_API PEP_STATUS key_expired(
  990. PEP_SESSION session,
  991. const char *fpr,
  992. const time_t when,
  993. bool *expired
  994. );
  995. // key_revoked() - flags if a key is already revoked
  996. //
  997. // parameters:
  998. // session (in) session handle
  999. // fpr (in) ID of key to check as UTF-8 string
  1000. // revoked (out) flag if key revoked
  1001. DYNAMIC_API PEP_STATUS key_revoked(
  1002. PEP_SESSION session,
  1003. const char *fpr,
  1004. bool *revoked
  1005. );
  1006. PEP_STATUS get_key_userids(
  1007. PEP_SESSION session,
  1008. const char* fpr,
  1009. stringlist_t** keylist
  1010. );
  1011. // get_crashdump_log() - get the last log messages out
  1012. //
  1013. // parameters:
  1014. // session (in) session handle
  1015. // maxlines (in) maximum number of lines (0 for default)
  1016. // logdata (out) logdata as string in double quoted CSV format
  1017. // column1 is title
  1018. // column2 is entity
  1019. // column3 is description
  1020. // column4 is comment
  1021. //
  1022. // caveat:
  1023. // the ownership of logdata goes to the caller
  1024. DYNAMIC_API PEP_STATUS get_crashdump_log(
  1025. PEP_SESSION session,
  1026. int maxlines,
  1027. char **logdata
  1028. );
  1029. // get_languagelist() - get the list of languages
  1030. //
  1031. // parameters:
  1032. // session (in) session handle
  1033. // languages (out) languages as string in double quoted CSV format
  1034. // column 1 is the ISO 639-1 language code
  1035. // column 2 is the name of the language
  1036. //
  1037. // caveat:
  1038. // the ownership of languages goes to the caller
  1039. DYNAMIC_API PEP_STATUS get_languagelist(
  1040. PEP_SESSION session,
  1041. char **languages
  1042. );
  1043. // get_phrase() - get phrase in a dedicated language through i18n
  1044. //
  1045. // parameters:
  1046. // session (in) session handle
  1047. // lang (in) C string with ISO 639-1 language code
  1048. // phrase_id (in) id of phrase in i18n
  1049. // phrase (out) phrase as UTF-8 string
  1050. //
  1051. // caveat:
  1052. // the ownership of phrase goes to the caller
  1053. DYNAMIC_API PEP_STATUS get_phrase(
  1054. PEP_SESSION session,
  1055. const char *lang,
  1056. int phrase_id,
  1057. char **phrase
  1058. );
  1059. // sequence_value() - raise the value of a named sequence and retrieve it
  1060. //
  1061. // parameters:
  1062. // session (in) session handle
  1063. // name (in) name of sequence
  1064. // value (out) value of sequence
  1065. //
  1066. // returns:
  1067. // PEP_STATUS_OK no error, not own sequence
  1068. // PEP_SEQUENCE_VIOLATED if sequence violated
  1069. // PEP_CANNOT_INCREASE_SEQUENCE if sequence cannot be increased
  1070. // PEP_OWN_SEQUENCE if own sequence
  1071. DYNAMIC_API PEP_STATUS sequence_value(
  1072. PEP_SESSION session,
  1073. const char *name,
  1074. int32_t *value
  1075. );
  1076. // set_revoked() - records relation between a revoked key and its replacement
  1077. //
  1078. // parameters:
  1079. // session (in) session handle
  1080. // revoked_fpr (in) revoked fingerprint
  1081. // replacement_fpr (in) replacement key fingerprint
  1082. // revocation_date (in) revocation date
  1083. DYNAMIC_API PEP_STATUS set_revoked(
  1084. PEP_SESSION session,
  1085. const char *revoked_fpr,
  1086. const char *replacement_fpr,
  1087. const uint64_t revocation_date
  1088. );
  1089. // get_revoked() - find revoked key that may have been replaced by given key, if any
  1090. //
  1091. // parameters:
  1092. // session (in) session handle
  1093. // fpr (in) given fingerprint
  1094. // revoked_fpr (out) revoked fingerprint
  1095. // revocation_date (out) revocation date
  1096. DYNAMIC_API PEP_STATUS get_revoked(
  1097. PEP_SESSION session,
  1098. const char *fpr,
  1099. char **revoked_fpr,
  1100. uint64_t *revocation_date
  1101. );
  1102. // key_created() - get creation date of a key
  1103. //
  1104. // parameters:
  1105. // session (in) session handle
  1106. // fpr (in) fingerprint of key
  1107. // created (out) date of creation
  1108. PEP_STATUS key_created(
  1109. PEP_SESSION session,
  1110. const char *fpr,
  1111. time_t *created
  1112. );
  1113. // find_private_keys() - find keys in keyring
  1114. //
  1115. // parameters:
  1116. // session (in) session handle
  1117. // pattern (in) key id, user id or address to search for as
  1118. // UTF-8 string
  1119. // keylist (out) list of fingerprints found or NULL on error
  1120. //
  1121. // caveat:
  1122. // the ownerships of keylist isgoing to the caller
  1123. // the caller must use free_stringlist() to free it
  1124. PEP_STATUS find_private_keys(PEP_SESSION session, const char* pattern,
  1125. stringlist_t **keylist);
  1126. // get_engine_version() - returns the current version of pEpEngine (this is different
  1127. // from the pEp protocol version!)
  1128. //
  1129. // parameters: none
  1130. //
  1131. // return_value: const char* to the engine version string constant
  1132. //
  1133. DYNAMIC_API const char* get_engine_version();
  1134. // get_protocol_version() - returns the pEp protocol version
  1135. DYNAMIC_API const char *get_protocol_version();
  1136. // is_pEp_user() - returns true if the USER corresponding to this identity
  1137. // has been listed in the *person* table as a pEp user.
  1138. //
  1139. // parameters:
  1140. // identity (in) - identity containing the user_id to check (this is
  1141. // the only part of the struct we require to be set)
  1142. // is_pEp (out) - boolean pointer - will return true or false by
  1143. // reference with respect to whether or not user is
  1144. // a known pEp user
  1145. //
  1146. // return_value: PEP_STATUS_OK if user found in person table
  1147. // PEP_ILLEGAL_VALUE if no user_id in input
  1148. // PEP_CANNOT_FIND_PERSON if user_id doesn't exist
  1149. //
  1150. // caveat: This *does not check comm_type*
  1151. //
  1152. DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session,
  1153. pEp_identity *identity,
  1154. bool* is_pEp);
  1155. // per_user_directory() - returns the directory for pEp management db
  1156. //
  1157. // return_value:
  1158. // path to actual per user directory or NULL on failure
  1159. DYNAMIC_API const char *per_user_directory(void);
  1160. // per_machine_directory() - returns the directory for pEp system db
  1161. //
  1162. // return value:
  1163. // path to actual per user directory or NULL on failure
  1164. DYNAMIC_API const char *per_machine_directory(void);
  1165. // FIXME: replace in canonical style
  1166. //
  1167. // config_passphrase() - configure a key passphrase for the current session.
  1168. //
  1169. // A passphrase can be configured into a p≡p session. Then it is used whenever a
  1170. // secret key is used which requires a passphrase.
  1171. //
  1172. // A passphrase is a string between 1 and 1024 bytes and is only ever present in
  1173. // memory. Because strings in the p≡p engine are UTF-8 NFC, the string is
  1174. // restricted to 250 code points in UI.
  1175. //
  1176. // This function copies the passphrase into the session. It may return
  1177. // PEP_OUT_OF_MEMORY. The behaviour of all functions which use secret keys may
  1178. // change after this is configured. Error behaviour
  1179. //
  1180. // For any function which may trigger the use of a secret key, if an attempt
  1181. // to use a secret key which requires a passphrase occurs and no passphrase
  1182. // is configured for the current session, PEP_PASSPHRASE_REQUIRED is
  1183. // returned by this function (and thus, all functions which could trigger
  1184. // such a usage must be prepared to return this value). For any function
  1185. // which may trigger the use of a secret key, if a passphrase is configured
  1186. // and the configured passphrase is the wrong passphrase for the use of a
  1187. // given passphrase-protected secret key, PEP_WRONG_PASSPHRASE is returned
  1188. // by this function (and thus, all functions which could trigger such a
  1189. // usage must be prepared to return this value).
  1190. DYNAMIC_API PEP_STATUS config_passphrase(PEP_SESSION session, const char *passphrase);
  1191. // FIXME: replace in canonical style
  1192. //
  1193. // Passphrase enablement for newly-generated secret keys
  1194. //
  1195. // If it is desired that new p≡p keys are passphrase-protected, the following
  1196. // API call is used to enable the addition of passphrases to new keys during key
  1197. // generation.
  1198. //
  1199. // If enabled and a passphrase for new keys has been configured
  1200. // through this function (NOT the one above - this is a separate passphrase!),
  1201. // then anytime a secret key is generated while enabled, the configured
  1202. // passphrase will be used as the passphrase for any newly-generated secret key.
  1203. //
  1204. // If enabled and a passphrase for new keys has not been configured, then any
  1205. // function which can attempt to generate a secret key will return
  1206. // PEP_PASSPHRASE_FOR_NEW_KEYS_REQUIRED.
  1207. //
  1208. // If disabled (i.e. not enabled) and a passphrase for new keys has been
  1209. // configured, no passphrases will be used for newly-generated keys.
  1210. //
  1211. // This function copies the passphrase for new keys into a special field that is
  1212. // specifically for key generation into the session. It may return
  1213. // PEP_OUT_OF_MEMORY. The behaviour of all functions which use secret keys may
  1214. // change after this is configured.
  1215. //
  1216. DYNAMIC_API PEP_STATUS config_passphrase_for_new_keys(PEP_SESSION session,
  1217. bool enable,
  1218. const char *passphrase);
  1219. // set_ident_enc_format() - set the default encryption format for this identity
  1220. // (value only MIGHT be used, and only in the case where the
  1221. // message enc_format is PEP_enc_auto. It will be used
  1222. // opportunistically in the case on a first-come, first-serve
  1223. // basis in the order of to_list, cc_list, and bcc_list. We take
  1224. // the first set value we come to)
  1225. //
  1226. // parameters:
  1227. // session (in) session handle
  1228. // identity (in) identity->user_id and identity->address must NOT be NULL
  1229. // format (in) the desired default encryption format
  1230. //
  1231. DYNAMIC_API PEP_STATUS set_ident_enc_format(PEP_SESSION session,
  1232. pEp_identity *identity,
  1233. PEP_enc_format format);
  1234. PEP_STATUS _generate_keypair(PEP_SESSION session,
  1235. pEp_identity *identity,
  1236. bool suppress_event);
  1237. DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session);
  1238. // This is used internally when there is a temporary identity to be retrieved
  1239. // that may not yet have an FPR attached. See get_identity() for functionality,
  1240. // params and caveats.
  1241. PEP_STATUS get_identity_without_trust_check(
  1242. PEP_SESSION session,
  1243. const char *address,
  1244. const char *user_id,
  1245. pEp_identity **identity
  1246. );
  1247. PEP_STATUS get_identities_by_address(
  1248. PEP_SESSION session,
  1249. const char *address,
  1250. identity_list** id_list
  1251. );
  1252. PEP_STATUS get_identities_by_userid(
  1253. PEP_SESSION session,
  1254. const char *user_id,
  1255. identity_list **identities
  1256. );
  1257. PEP_STATUS is_own_address(PEP_SESSION session,
  1258. const char* address,
  1259. bool* is_own_addr);
  1260. PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
  1261. const char* new_uid);
  1262. PEP_STATUS remove_key(PEP_SESSION session, const char* fpr);
  1263. PEP_STATUS remove_fpr_as_default(PEP_SESSION session,
  1264. const char* fpr);
  1265. PEP_STATUS get_main_user_fpr(PEP_SESSION session,
  1266. const char* user_id,
  1267. char** main_fpr);
  1268. PEP_STATUS replace_main_user_fpr(PEP_SESSION session, const char* user_id,
  1269. const char* new_fpr);
  1270. PEP_STATUS replace_main_user_fpr_if_equal(PEP_SESSION session, const char* user_id,
  1271. const char* new_fpr, const char* compare_fpr);
  1272. DYNAMIC_API PEP_STATUS get_replacement_fpr(
  1273. PEP_SESSION session,
  1274. const char *fpr,
  1275. char **revoked_fpr,
  1276. uint64_t *revocation_date
  1277. );
  1278. PEP_STATUS refresh_userid_default_key(PEP_SESSION session, const char* user_id);
  1279. // This ONLY sets the *user* flag, and creates a shell identity if necessary.
  1280. DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user);
  1281. // returns true (by reference) if a person with this user_id exists;
  1282. // Also replaces aliased user_ids by defaults in identity.
  1283. PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity, bool* exists);
  1284. PEP_STATUS set_pgp_keypair(PEP_SESSION session, const char* fpr);
  1285. PEP_STATUS set_pEp_version(PEP_SESSION session, pEp_identity* ident, unsigned int new_ver_major, unsigned int new_ver_minor);
  1286. PEP_STATUS clear_trust_info(PEP_SESSION session,
  1287. const char* user_id,
  1288. const char* fpr);
  1289. // Generally ONLY called by set_as_pEp_user, and ONLY from < 2.0 to 2.0.
  1290. PEP_STATUS upgrade_pEp_version_by_user_id(PEP_SESSION session,
  1291. pEp_identity* ident,
  1292. unsigned int new_ver_major,
  1293. unsigned int new_ver_minor
  1294. );
  1295. // exposed for testing
  1296. PEP_STATUS set_person(PEP_SESSION session, pEp_identity* identity,
  1297. bool guard_transaction);
  1298. PEP_STATUS bind_own_ident_with_contact_ident(PEP_SESSION session,
  1299. pEp_identity* own_ident,
  1300. pEp_identity* contact_ident);
  1301. PEP_STATUS get_last_contacted(
  1302. PEP_SESSION session,
  1303. identity_list** id_list
  1304. );
  1305. PEP_STATUS get_own_ident_for_contact_id(PEP_SESSION session,
  1306. const pEp_identity* contact,
  1307. pEp_identity** own_ident);
  1308. PEP_STATUS exists_trust_entry(PEP_SESSION session, pEp_identity* identity,
  1309. bool* exists);
  1310. PEP_STATUS is_own_key(PEP_SESSION session, const char* fpr, bool* own_key);
  1311. PEP_STATUS get_identities_by_main_key_id(
  1312. PEP_SESSION session,
  1313. const char *fpr,
  1314. identity_list **identities);
  1315. PEP_STATUS sign_only(PEP_SESSION session,
  1316. const char *data,
  1317. size_t data_size,
  1318. const char *fpr,
  1319. char **sign,
  1320. size_t *sign_size);
  1321. PEP_STATUS set_all_userids_to_own(PEP_SESSION session,
  1322. identity_list* id_list);
  1323. PEP_STATUS has_partner_contacted_address(PEP_SESSION session, const char* partner_id,
  1324. const char* own_address, bool* was_contacted);
  1325. #ifdef __cplusplus
  1326. }
  1327. #endif