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.

281 lines
7.5 KiB

6 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
7 years ago
7 years ago
6 years ago
8 years ago
8 years ago
7 years ago
8 years ago
  1. /**
  2. * @file cryptotech.h
  3. * @brief cryptotech function typedefs and structures for crypto drivers
  4. * to implement and interface with engine
  5. * @license GNU General Public License 3.0 - see LICENSE.txt
  6. */
  7. #pragma once
  8. #include "pEpEngine.h"
  9. #include "bloblist.h"
  10. /**
  11. * @enum PEP_cryptotech
  12. *
  13. * @brief TODO
  14. *
  15. */
  16. typedef enum _PEP_cryptotech {
  17. PEP_crypt_none = 0,
  18. PEP_crypt_OpenPGP,
  19. // PEP_ctypt_PEP,
  20. // PEP_crypt_SMIME,
  21. // PEP_crypt_CMS,
  22. PEP_crypt__count
  23. } PEP_cryptotech;
  24. /**
  25. * @copydoc decrypt_and_verify()
  26. * Signature for crypto drivers to implement for decrypt_and_verify()
  27. * @see decrypt_and_verify()
  28. */
  29. typedef PEP_STATUS (*decrypt_and_verify_t)(
  30. PEP_SESSION session, const char *ctext, size_t csize,
  31. const char *dsigtext, size_t dsigsize,
  32. char **ptext, size_t *psize, stringlist_t **keylist,
  33. char **filename_ptr
  34. );
  35. /**
  36. * @copydoc verify_text()
  37. * Signature for crypto drivers to implement for verify_text()
  38. * @see verify_text()
  39. */
  40. typedef PEP_STATUS (*verify_text_t)(
  41. PEP_SESSION session, const char *text, size_t size,
  42. const char *signature, size_t sig_size, stringlist_t **keylist
  43. );
  44. /**
  45. * @copydoc encrypt_and_sign()
  46. * Signature for crypto drivers to implement for encrypt_and_sign()
  47. * @see encrypt_and_sign()
  48. */
  49. typedef PEP_STATUS (*encrypt_and_sign_t)(
  50. PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
  51. size_t psize, char **ctext, size_t *csize
  52. );
  53. /**
  54. * @copydoc encrypt_only()
  55. * Signature for crypto drivers to implement for encrypt_only()
  56. * @see encrypt_only()
  57. */
  58. typedef PEP_STATUS (*encrypt_only_t)(
  59. PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
  60. size_t psize, char **ctext, size_t *csize
  61. );
  62. /**
  63. * @copydoc sign_only()
  64. * Signature for crypto drivers to implement for sign_only()
  65. * @see sign_only
  66. */
  67. typedef PEP_STATUS (*sign_only_t)(
  68. PEP_SESSION session, const char* fpr, const char *ptext,
  69. size_t psize, char **stext, size_t *ssize
  70. );
  71. /**
  72. * @copydoc delete_keypair()
  73. * Signature for crypto drivers to implement for delete_keypair()
  74. * @see delete_keypair()
  75. */
  76. typedef PEP_STATUS (*delete_keypair_t)(PEP_SESSION session, const char *fpr);
  77. /**
  78. * @copydoc export_key()
  79. * Signature for crypto drivers to implement for export_key()
  80. * @see export_key()
  81. */
  82. typedef PEP_STATUS (*export_key_t)(
  83. PEP_SESSION session, const char *fpr, char **key_data, size_t *size,
  84. bool secret
  85. );
  86. /**
  87. * @copydoc find_keys()
  88. * Signature for crypto drivers to implement for find_keys()
  89. * @see find_keys()
  90. */
  91. typedef PEP_STATUS (*find_keys_t)(
  92. PEP_SESSION session, const char *pattern, stringlist_t **keylist
  93. );
  94. /**
  95. * @copydoc generate_keypair()
  96. * Signature for crypto drivers to implement for generate_keypair()
  97. * @see generate_keypair()
  98. */
  99. typedef PEP_STATUS (*generate_keypair_t)(
  100. PEP_SESSION session, pEp_identity *identity
  101. );
  102. /**
  103. * @copydoc get_key_rating()
  104. * Signature for crypto drivers to implement for get_key_rating()
  105. * @see get_key_rating()
  106. */
  107. typedef PEP_STATUS (*get_key_rating_t)(
  108. PEP_SESSION session,
  109. const char *fpr,
  110. PEP_comm_type *comm_type
  111. );
  112. /**
  113. * @copydoc import_key()
  114. * Signature for crypto drivers to implement for import_key()
  115. * @see import_key()
  116. */
  117. typedef PEP_STATUS (*import_key_t)(PEP_SESSION session, const char *key_data,
  118. size_t size, identity_list **private_keys, stringlist_t** imported_keys,
  119. uint64_t* changed_key_index);
  120. /**
  121. * @copydoc recv_key()
  122. * Signature for crypto drivers to implement for recv_key()
  123. * @see recv_key()
  124. */
  125. typedef PEP_STATUS (*recv_key_t)(PEP_SESSION session, const char *pattern);
  126. /**
  127. * @copydoc send_key()
  128. * Signature for crypto drivers to implement for send_key()
  129. * @see send_key()
  130. */
  131. typedef PEP_STATUS (*send_key_t)(PEP_SESSION session, const char *pattern);
  132. /**
  133. * @copydoc renew_key()
  134. * Signature for crypto drivers to implement for renew_key()
  135. * @see renew_key()
  136. */
  137. typedef PEP_STATUS (*renew_key_t)(PEP_SESSION session, const char *fpr,
  138. const timestamp *ts);
  139. /**
  140. * @copydoc revoke_key()
  141. * Signature for crypto drivers to implement for revoke_key()
  142. * @see revoke_key()
  143. */
  144. typedef PEP_STATUS (*revoke_key_t)(PEP_SESSION session, const char *fpr,
  145. const char *reason);
  146. /**
  147. * @copydoc key_expired()
  148. * Signature for crypto drivers to implement for key_expired()
  149. * @see key_expired()
  150. */
  151. typedef PEP_STATUS (*key_expired_t)(PEP_SESSION session, const char *fpr,
  152. const time_t when, bool *expired);
  153. /**
  154. * @copydoc key_revoked()
  155. * Signature for crypto drivers to implement for key_revoked()
  156. * @see key_revoked()
  157. */
  158. typedef PEP_STATUS (*key_revoked_t)(PEP_SESSION session, const char *fpr,
  159. bool *revoked);
  160. /**
  161. * @copydoc key_created()
  162. * Signature for crypto drivers to implement for key_created()
  163. * @see key_created()
  164. */
  165. typedef PEP_STATUS (*key_created_t)(PEP_SESSION session, const char *fpr,
  166. time_t *created);
  167. /**
  168. * @copydoc binary_path()
  169. * Signature for crypto drivers to implement for binary_path()
  170. * @see binary_path()
  171. */
  172. typedef PEP_STATUS (*binary_path_t)(const char **path);
  173. /**
  174. * @copydoc contains_priv_key()
  175. * Signature for crypto drivers to implement for contains_priv_key()
  176. * @see contains_priv_key()
  177. */
  178. typedef PEP_STATUS (*contains_priv_key_t)(PEP_SESSION session, const char *fpr,
  179. bool *has_private);
  180. /**
  181. * @copydoc find_private_keys()
  182. * Signature for crypto drivers to implement for find_private_keys()
  183. * @see find_private_keys()
  184. */
  185. typedef PEP_STATUS (*find_private_keys_t)(
  186. PEP_SESSION session, const char *pattern, stringlist_t **keylist
  187. );
  188. /**
  189. * @copydoc config_cipher_suite()
  190. * Signature for crypto drivers to implement for config_cipher_suite()
  191. * @see config_cipher_suite()
  192. */
  193. typedef PEP_STATUS (*config_cipher_suite_t)(PEP_SESSION session,
  194. PEP_CIPHER_SUITE suite);
  195. /**
  196. * @struct PEP_cryptotech_t
  197. *
  198. * @brief TODO
  199. *
  200. */
  201. typedef struct _PEP_cryptotech_t {
  202. uint8_t id;
  203. // the following are default values; comm_type may vary with key length or b0rken crypto
  204. uint8_t unconfirmed_comm_type;
  205. uint8_t confirmed_comm_type;
  206. decrypt_and_verify_t decrypt_and_verify;
  207. verify_text_t verify_text;
  208. encrypt_and_sign_t encrypt_and_sign;
  209. encrypt_only_t encrypt_only;
  210. sign_only_t sign_only;
  211. delete_keypair_t delete_keypair;
  212. export_key_t export_key;
  213. find_keys_t find_keys;
  214. generate_keypair_t generate_keypair;
  215. get_key_rating_t get_key_rating;
  216. import_key_t import_key;
  217. recv_key_t recv_key;
  218. send_key_t send_key;
  219. renew_key_t renew_key;
  220. revoke_key_t revoke_key;
  221. key_expired_t key_expired;
  222. key_revoked_t key_revoked;
  223. key_created_t key_created;
  224. binary_path_t binary_path;
  225. contains_priv_key_t contains_priv_key;
  226. find_private_keys_t find_private_keys;
  227. config_cipher_suite_t config_cipher_suite;
  228. } PEP_cryptotech_t;
  229. extern PEP_cryptotech_t cryptotech[PEP_crypt__count];
  230. typedef uint64_t cryptotech_mask;
  231. /**
  232. * <!-- init_cryptotech() -->
  233. *
  234. * @brief TODO
  235. *
  236. * @param[in] session PEP_SESSION
  237. * @param[in] in_first bool
  238. *
  239. */
  240. PEP_STATUS init_cryptotech(PEP_SESSION session, bool in_first);
  241. /**
  242. * <!-- release_cryptotech() -->
  243. *
  244. * @brief TODO
  245. *
  246. * @param[in] session PEP_SESSION
  247. * @param[in] out_last bool
  248. *
  249. */
  250. void release_cryptotech(PEP_SESSION session, bool out_last);