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.

561 lines
18 KiB

3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. // p≡p Message API
  2. // Copyleft (c) 2019, p≡p foundation
  3. // this file is under GNU General Public License 3.0
  4. // see LICENSE.txt
  5. // written by Volker Birk and Nana Karlstetter
  6. enum text_format {
  7. hex plain 0;
  8. hex html 1;
  9. hex other 0xff;
  10. }
  11. enum direction {
  12. item incoming 0;
  13. item outgoing 1;
  14. }
  15. enum enc_format {
  16. item none 0 doc='message is not encrypted';
  17. item pieces 1 doc='inline PGP + PGP extensions';
  18. item S_MIME 2 doc='RFC5751';
  19. item PGP_MIME 3 doc='RFC3156';
  20. item PEP 4 doc='pEp encryption format';
  21. item PGP_MIME_Outlook1 5 doc='Message B0rken by Outlook type 1';
  22. }
  23. enum rating {
  24. item undefined 0 doc="no rating available";
  25. doc "no color";
  26. item cannot_decrypt 1;
  27. item have_no_key 2;
  28. item unencrypted 3;
  29. // 5 is reserved
  30. item unreliable 5;
  31. doc "yellow";
  32. item reliable 6;
  33. doc "green";
  34. item trusted 7;
  35. item trusted_and_anonymized 8;
  36. item fully_anonymous 9;
  37. doc "red";
  38. item mistrust -1;
  39. item b0rken -2;
  40. item under_attack -3;
  41. }
  42. enum color {
  43. item no_color 0;
  44. item yellow 1;
  45. item green 2;
  46. item red -1;
  47. }
  48. struct message {
  49. field direction dir;
  50. field string id doc='string of message ID';
  51. field string shortmsg doc='string of short message';
  52. field string longmsg doc='string of long message (plain)';
  53. field string longmsg_formatted doc='string of long message (formatted)';
  54. field blob_list attachments doc='blobs with attachements';
  55. field blob_ref rawmsg_ref doc='reference to raw message data';
  56. field size_t rawmsg_size doc='size of raw message data';
  57. field timestamp sent doc='when the message is sent';
  58. field timestamp recv doc='when the message is received';
  59. field identity from doc='whom the message is from';
  60. field identity_list to doc='whom the message is to';
  61. field identity recv_by doc='via which identity the message is received';
  62. field identity_list cc doc='whom a CC is being sent';
  63. field identity_list bcc doc='whom a BCC is being sent';
  64. field identity_list reply_to doc='where a reply should go to';
  65. field string_list in_reply_to doc='list of strings with MessageIDs of refering messages';
  66. field message_ref refering_msg_ref doc='reference to refering message';
  67. field string_list references doc='list of strings with references';
  68. field message_ref_list refered_by doc='list of references to messages being refered';
  69. field string_list keywords doc='list of strings with keywords';
  70. field string comments doc='string with comments';
  71. field stringpair_list opt_fields doc='optional fields';
  72. field enc_format format doc='format of encrypted data';
  73. new (msg_direction dir);
  74. }
  75. protocol session {
  76. method encrypt_message doc="encrypt message in memory"
  77. {
  78. // parms
  79. lend message src
  80. doc="""
  81. message to encrypt - usually in-only, but can be in-out for
  82. unencrypted messages; in that case, we may attach the key and
  83. decorate the message
  84. """;
  85. use hash_list extra doc="extra keys for encryption";
  86. create message dst
  87. doc="""
  88. pointer to new encrypted message or #NV if no encryption could
  89. take place
  90. """;
  91. use enc_format format doc="The desired format this message should be encrypted with";
  92. // flags
  93. flags {
  94. flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
  95. flag force_encryption 0x1;
  96. flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
  97. flag force_no_attached_key 0x4;
  98. flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
  99. flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
  100. flag key_reset_only 0x20
  101. doc="""This flag is used to let internal functions know that an encryption call is being
  102. used as part of a reencryption operation
  103. """;
  104. flag encrypt_reencrypt 0x40;
  105. }
  106. // exceptions
  107. throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
  108. throws unencrypted
  109. doc="""
  110. on demand or no recipients with usable key, is left unencrypted,
  111. and key is attached to it
  112. """;
  113. }
  114. method encrypt_message_and_add_priv_key
  115. doc="""
  116. encrypt message in memory, adding an encrypted private key (encrypted separately
  117. and sent within the inner message)
  118. """
  119. {
  120. // parms
  121. use message src doc="message to encrypt";
  122. create message dst
  123. doc="pointer to new encrypted message or empty if no encryption could take place";
  124. use hash to_fpr
  125. doc="fingerprint of the recipient key to which the private key should be encrypted";
  126. use enc_format format doc="encrypted format";
  127. // flags
  128. flags {
  129. flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
  130. flag force_encryption 0x1;
  131. flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
  132. flag force_no_attached_key 0x4;
  133. flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
  134. flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
  135. flag key_reset_only 0x20;
  136. }
  137. // exceptions
  138. throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
  139. throws unencrypted
  140. doc="""
  141. on demand or no recipients with usable key, is left unencrypted,
  142. and key is attached to it
  143. """;
  144. }
  145. method encrypt_message_for_self
  146. doc="""
  147. encrypt message in memory for user's identity only,
  148. ignoring recipients and other identities from the message
  149. """
  150. {
  151. // parms
  152. use identity target_id
  153. doc="""
  154. self identity this message should be encrypted for. Message is NOT encrypted for
  155. identities other than the target_id (and then, only if the target_id refers to self!).
  156. """;
  157. use message src doc="message to encrypt";
  158. use hash_list extra doc="extra keys for encryption";
  159. create message dst doc="pointer to new encrypted message or empty on failure";
  160. use enc_format format doc="encrypted format";
  161. // flags
  162. flags {
  163. flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
  164. flag force_encryption 0x1;
  165. flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
  166. flag force_no_attached_key 0x4;
  167. flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
  168. flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
  169. flag key_reset_only 0x20;
  170. }
  171. doc | (FIXME: The exceptions may not be correct or complete)
  172. throws key_not_found doc="at least one of the receipient keys could not be found";
  173. throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
  174. throws get_key_failed doc="cannot retrieve key";
  175. }
  176. method decrypt_message doc="decrypt message in memory"
  177. {
  178. // parms
  179. lend message src
  180. doc="""
  181. message to decrypt.
  182. The ownership of src remains with the caller - however, the contents
  183. might be modified (strings freed and allocated anew or set to empty,
  184. etc) intentionally; when this happens, decrypt_flag_src_modified is set.
  185. """;
  186. create message dst doc="pointer to new decrypted message or empty on failure";
  187. lend hash_list keylist
  188. doc="""
  189. in: stringlist with additional keyids for reencryption if needed
  190. (will be freed and replaced with output keylist)
  191. out: stringlist with keyids used for signing and encryption. first
  192. first key is signer, additional keys are the ones it was encrypted
  193. to. Only signer and whichever of the user's keys was used are reliable.
  194. The ownership of keylist goes to the caller.
  195. If src is unencrypted this function returns unencrypted and sets dst to empty.
  196. """;
  197. return rating msg_rating doc="rating for the message";
  198. // flags
  199. flags {
  200. flag decrypt_flag_own_private_key 0x1
  201. doc="""
  202. private key was imported for one of our addresses (NOT trusted
  203. or set to be used - handshake/trust is required for that)
  204. """;
  205. flag decrypt_flag_consume 0x2 doc='used by sync';
  206. flag decrypt_flag_ignore 0x4 doc='used by sync';
  207. flag decrypt_flag_src_modified 0x8
  208. doc="""
  209. indicates that the src object has been modified. At the moment,
  210. this is always as a direct result of the behaviour driven
  211. by the input flags. This flag is the ONLY value that should be
  212. relied upon to see if such changes have taken place.
  213. """;
  214. flag decrypt_flag_untrusted_server 0x100
  215. doc="""
  216. input flag. Used to signal that decrypt function should engage in behaviour
  217. specified for when the server storing the source is untrusted.
  218. """;
  219. flag decrypt_flag_dont_trigger_sync 0x200;
  220. }
  221. // exceptions
  222. throws decrypted doc="if message decrypted but not verified";
  223. throws cannot_reencrypt
  224. doc="""
  225. if message was decrypted (and possibly verified) but a reencryption
  226. operation is expected by the caller and failed.
  227. """;
  228. throws unencrypted
  229. doc="""
  230. if src is unencrypted this function returns unencrypted and sets
  231. dst to empty.
  232. """;
  233. throws any doc="all error status values allowed";
  234. }
  235. method own_message_private_key_details
  236. doc="""
  237. details on own key in own message. Note: In order to obtain details about key
  238. to be possibly imported as a replacement of key currently used as own identity,
  239. application passes message that have been previously flagged by decrypt_message()
  240. as own message containing own key to this function.
  241. """
  242. {
  243. // parms
  244. use message msg
  245. doc="""
  246. message to decrypt. msg MUST be encrypted so that this function
  247. can check own signature.
  248. """;
  249. create identity ident doc="identity containing uid, address and fpr of key";
  250. // exceptions
  251. throws any doc="error status";
  252. }
  253. method outgoing_message_rating doc="get rating for an outgoing message"
  254. {
  255. // parms
  256. use message msg
  257. doc="""
  258. message to get the rating for. From must point to a valid pEp_identity.
  259. Dir must be dir_outgoing.
  260. """;
  261. return rating msg_rating doc="rating for the message";
  262. // exceptions
  263. throws any doc="error status";
  264. }
  265. method outgoing_message_rating_preview doc="get rating preview"
  266. {
  267. // parms
  268. use message msg
  269. doc="""
  270. message to get the rating for. From must point to a valid pEp_identity.
  271. Dir must be dir_outgoing.
  272. """;
  273. return rating msg_rating doc="rating preview for the message";
  274. // exceptions
  275. throws any doc="error status";
  276. }
  277. method identity_rating doc="get rating for a single identity"
  278. {
  279. // parms
  280. use identity ident doc="identity to get the rating for";
  281. return rating identity_rating doc="rating for the identity";
  282. // exceptions
  283. throws any doc="error status";
  284. }
  285. method get_trustwords doc="get full trustwords string for a *pair* of identities"
  286. {
  287. // parms
  288. use identity id1 doc="identity of first party in communication - fpr can't be empty";
  289. use identity id2 doc="identity of second party in communication - fpr can't be empty";
  290. use ISO639_1 lang doc="string with ISO 639-1 language code";
  291. create string words
  292. doc="""
  293. string with all trustwords, separated
  294. by a blank each. Empty if language is not supported or trustword
  295. wordlist is damaged or unavailable.
  296. The word pointer goes to the ownership of the caller.
  297. The caller is responsible to free() it (on Windoze use pEp_free())
  298. """;
  299. use bool full
  300. doc="""
  301. if true, generate ALL trustwords for these identities.
  302. else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
  303. subset in next version)
  304. """;
  305. // exceptions
  306. throws out_of_memory doc="out of memory";
  307. throws trustword_not_found doc="at least one trustword not found";
  308. }
  309. method get_message_trustwords doc="get full trustwords string for message sender and reciever identities"
  310. {
  311. // parms
  312. use message msg doc="message to get sender identity from";
  313. use hash_list keylist doc="empty if message to be decrypted, keylist returned by decrypt_message() otherwise.";
  314. use identity received_by doc="identity for account receiving message can't be empty";
  315. use ISO639_1 lang doc="string with ISO 639-1 language code";
  316. create string words
  317. doc="""
  318. string with all trustwords, separated by a blank each.
  319. Empty if language is not supported or trustword wordlist is damaged or unavailable.
  320. """;
  321. use bool full
  322. doc="""
  323. if true, generate ALL trustwords for these identities.
  324. else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
  325. subset in next version)
  326. """;
  327. // exceptions
  328. throws out_of_memory doc="out of memory";
  329. throws trustword_not_found doc="at least one trustword not found";
  330. throws like decrypt_message doc="error status of decrypt_message() if decryption fails";
  331. }
  332. method get_trustwords_for_fprs doc="get full trustwords string for a pair of fingerprints"
  333. {
  334. // parms
  335. use string fpr1 doc="fingerprint 1";
  336. use string fpr2 doc="fingerprint 2";
  337. use ISO639_1 lang doc="string with ISO 639-1 language code";
  338. create string words
  339. doc="""
  340. pointer to string with all trustwords UTF-8 encoded, separated by a blank each.
  341. NULL if language is not supported or trustword wordlist is damaged or unavailable.
  342. The caller is responsible to free() it (on Windoze use pEp_free()).
  343. """;
  344. return size_t wsize doc="length of full trustwords string";
  345. use bool full
  346. doc="""
  347. if true, generate ALL trustwords for these identities. Else, generate a fixed-size
  348. subset. (TODO: fixed-minimum-entropy subset in next version)
  349. """;
  350. // exceptions
  351. throws out_of_memory doc="out of memory";
  352. throws trustword_not_found doc="at least one trustword not found";
  353. }
  354. method re_evaluate_message_rating doc="re-evaluate already decrypted message rating"
  355. {
  356. // parms
  357. use message msg doc="message to get the rating for. msg->from must point to a valid pEp_identity";
  358. use hash_list x_keylist doc="decrypted message recipients keys fpr";
  359. use rating x_enc_status doc="original rating for the decrypted message";
  360. return rating msg_rating doc="rating for the message";
  361. // exceptions
  362. throws illegal_value
  363. doc="""
  364. if decrypted message doesn't contain X-EncStatus optional field and
  365. x_enc_status is pEp_rating_udefined or if decrypted message doesn't
  366. contain X-Keylist optional field and x_keylist is empty.
  367. """;
  368. throws out_of_memory doc="if not enough memory could be allocated";
  369. }
  370. method get_key_rating_for_user doc="get the rating of a certain key for a certain user"
  371. {
  372. // parms
  373. use string user_id doc="string with user ID";
  374. use string fpr doc="string with fingerprint";
  375. return rating key_rating doc="rating of key for this user";
  376. // exceptions
  377. throws record_not_found doc="if no trust record for user_id and fpr can be found";
  378. }
  379. method rating_from_comm_type doc="get the rating for a comm type"
  380. {
  381. // parms
  382. use comm_type ct doc="the comm type to deliver the rating for";
  383. // exceptions
  384. throws any doc="rating value for comm type ct";
  385. }
  386. }
  387. func color_from_rating doc="calculate color from rating"
  388. {
  389. // parms
  390. use color_from_rating rating doc="color representing that rating";
  391. // return value
  392. return color rating_color doc="color representing that rating";
  393. }
  394. func get_binary_path doc="retrieve path of cryptotech binary if available"
  395. {
  396. //parms
  397. use cryptotech tech doc="cryptotech to get the binary for";
  398. use string path
  399. doc="""
  400. path to cryptotech binary or empty if not available. **path is owned by
  401. the library, do not change it!
  402. """;
  403. }