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.

629 lines
20 KiB

3 years ago
2 years ago
3 years ago
2 years ago
2 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
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
1 year ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 months ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 months ago
3 years ago
3 years ago
4 months ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
4 months ago
3 years ago
4 months ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 months ago
3 years ago
3 years ago
4 months ago
3 years ago
3 years ago
3 years ago
4 months ago
3 years ago
4 months ago
3 years ago
4 months ago
3 years ago
4 months ago
3 years ago
3 years ago
2 years ago
3 years ago
4 months ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
4 months ago
3 years ago
2 years ago
2 years ago
4 months ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
4 months ago
3 years ago
3 years ago
4 months ago
2 years ago
3 years ago
2 years ago
2 years ago
4 months ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
4 months ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
4 months ago
2 years ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
2 years ago
4 months ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
4 months ago
2 years ago
4 months ago
2 years ago
2 years ago
4 months ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
  1. // p≡p Message API
  2. // Copyleft (c) 2019-2020, 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. // 4 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 binary_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 any_ref refering_msg_ref doc='reference to refering message';
  67. field string_list references doc='list of strings with references';
  68. field string_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 string_pair_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
  77. doc="""
  78. encrypt message in memory. enc_format PEP_enc_inline_EA:
  79. internal format of the encrypted attachments is changing, see
  80. https://dev.pep.foundation/Engine/ElevatedAttachments
  81. Only use this for transports without support for attachments
  82. when attached data must be sent inline
  83. """
  84. {
  85. // parms
  86. lend message src
  87. doc="""
  88. message to encrypt - usually in-only, but can be in-out for
  89. unencrypted messages; in that case, we may attach the key and
  90. decorate the message
  91. """;
  92. use hash_list extra doc="extra keys for encryption";
  93. create message dst
  94. doc="""
  95. pointer to new encrypted message or #NV if no encryption could
  96. take place
  97. """;
  98. use enc_format format doc="The desired format this message should be encrypted with";
  99. // flags
  100. flags {
  101. flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
  102. flag force_encryption 0x1;
  103. flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
  104. flag force_no_attached_key 0x4;
  105. flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
  106. flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
  107. flag key_reset_only 0x20
  108. doc="""This flag is used to let internal functions know that an encryption call is being
  109. used as part of a reencryption operation
  110. """;
  111. flag encrypt_reencrypt 0x40;
  112. }
  113. // exceptions
  114. throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
  115. throws unencrypted
  116. doc="""
  117. on demand or no recipients with usable key, is left unencrypted,
  118. and key is attached to it
  119. """;
  120. throws illegal_value doc="illegal parameter values";
  121. throws out_of_memory doc="out of memory";
  122. throws any doc="any other value on error";
  123. }
  124. method encrypt_message_and_add_priv_key
  125. doc="""
  126. encrypt message in memory, adding an encrypted private key (encrypted separately
  127. and sent within the inner message)
  128. """
  129. {
  130. // parms
  131. use message src doc="message to encrypt";
  132. create message dst
  133. doc="pointer to new encrypted message or empty if no encryption could take place";
  134. use hash to_fpr
  135. doc="fingerprint of the recipient key to which the private key should be encrypted";
  136. use enc_format format doc="encrypted format";
  137. // flags
  138. flags {
  139. flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
  140. flag force_encryption 0x1;
  141. flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
  142. flag force_no_attached_key 0x4;
  143. flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
  144. flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
  145. flag key_reset_only 0x20;
  146. }
  147. // exceptions
  148. throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
  149. throws unencrypted
  150. doc="""
  151. on demand or no recipients with usable key, is left unencrypted,
  152. and key is attached to it
  153. """;
  154. throws illegal_value doc="illegal parameter values";
  155. throws out_of_memory doc="out of memory";
  156. throws any doc="any other value on error";
  157. throws unknown_error;
  158. throws any doc="any other value on error";
  159. }
  160. method encrypt_message_for_self
  161. doc="""
  162. encrypt message in memory for user's identity only,
  163. ignoring recipients and other identities from the message
  164. """
  165. {
  166. // parms
  167. use identity target_id
  168. doc="""
  169. self identity this message should be encrypted for. Message is NOT encrypted for
  170. identities other than the target_id (and then, only if the target_id refers to self!).
  171. """;
  172. use message src doc="message to encrypt";
  173. use hash_list extra doc="extra keys for encryption";
  174. create message dst doc="pointer to new encrypted message or empty on failure";
  175. use enc_format format doc="encrypted format";
  176. // flags
  177. flags {
  178. flag default 0x0 doc='"default" means whatever the default behaviour for the function is.';
  179. flag force_encryption 0x1;
  180. flag force_unsigned 0x2 doc='This flag is for special use cases and should not be used by normal pEp clients!';
  181. flag force_no_attached_key 0x4;
  182. flag inner_message 0x8 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device.';
  183. flag force_version_1 0x10 doc='This is mainly used by pEp clients to send private keys to their own PGP-only device';
  184. flag key_reset_only 0x20;
  185. }
  186. // exceptions
  187. throws key_not_found doc="at least one of the receipient keys could not be found";
  188. throws key_has_ambig_name doc="at least one of the receipient keys has an ambiguous name";
  189. throws get_key_failed doc="cannot retrieve key";
  190. throws cannot_find_identity;
  191. throws illegal_value;
  192. throws out_of_memory;
  193. }
  194. method decrypt_message doc="decrypt message in memory"
  195. {
  196. // parms
  197. lend message src
  198. doc="""
  199. message to decrypt.
  200. The ownership of src remains with the caller - HOWEVER, the contents
  201. might be modified (strings freed and allocated anew or set to empty,
  202. etc) intentionally; when this happens, decrypt_flag_src_modified is set.
  203. if src is unencrypted this function returns PEP_UNENCRYPTED and sets dst to NULL
  204. if src->enc_format is PEP_enc_inline_EA on input then elevated attachments
  205. will be expected
  206. decrypt_message RELIES on the fact that identity information provided in src
  207. for recips and sender is AS TAKEN FROM THE ORIGINAL PARSED MESSAGE. This means
  208. that if update_identity or myself is called on those identities by the caller
  209. before passing the message struct to decrypt_message, the caller will have to
  210. cache and restore those to their original state before sending them to this
  211. function. ADAPTERS AND APPLICATIONS PLEASE TAKE NOTE OF THIS. (Obviously, this
  212. doesn't include information like user_ids, but we very specifically need the
  213. incoming usernames preserved so that they can be handled by the internal
  214. algorithm appropriately)
  215. """;
  216. create message dst doc="pointer to new decrypted message or empty on failure";
  217. lend hash_list keylist
  218. doc="""
  219. in: stringlist with additional keyids for reencryption if needed
  220. (will be freed and replaced with output keylist)
  221. out: stringlist with keyids used for signing and encryption. first
  222. first key is signer, additional keys are the ones it was encrypted
  223. to. Only signer and whichever of the user's keys was used are reliable.
  224. The ownership of keylist goes to the caller.
  225. If src is unencrypted this function returns unencrypted and sets dst to empty.
  226. """;
  227. return rating msg_rating doc="rating for the message";
  228. // flags
  229. flags {
  230. flag decrypt_flag_untrusted_server 0x100
  231. doc="""
  232. incoming flag. Used to signal that decrypt function should engage in behaviour
  233. specified for when the server storing the source is untrusted.
  234. """;
  235. flag decrypt_flag_own_private_key 0x1
  236. doc="""
  237. outgoing flag: private key was imported for one of our addresses (NOT trusted
  238. or set to be used - handshake/trust is required for that)
  239. """;
  240. flag decrypt_flag_src_modified 0x8
  241. doc="""
  242. outgoing flag: indicates that the modified_src field should contain a modified
  243. version of the source, at the moment always as a result of the input flags.
  244. """;
  245. flag decrypt_flag_consume 0x2
  246. doc="""
  247. used by sync to indicate this was a pEp internal message and should be consumed
  248. externally without showing it as a normal message to the user
  249. """;
  250. flag decrypt_flag_ignore 0x4 doc='used by sync';
  251. }
  252. // exceptions
  253. throws error doc="any error status";
  254. throws decrypted doc="if message decrypted but not verified";
  255. throws cannot_reencrypt
  256. doc="""
  257. if message was decrypted (and possibly verified) but a reencryption
  258. operation is expected by the caller and failed.
  259. """;
  260. throws unencrypted
  261. doc="""
  262. if src is unencrypted this function returns unencrypted and sets
  263. dst to empty.
  264. """;
  265. }
  266. method own_message_private_key_details doc="details on own key in own message."
  267. {
  268. // parms
  269. use message msg
  270. doc="""
  271. message to decrypt. msg MUST be encrypted so that this function
  272. can check own signature.
  273. """;
  274. create identity ident
  275. doc="""
  276. identity containing uid, address and fpr of key.
  277. note: In order to obtain details about key to be possibly imported as a replacement
  278. of key currently used as own identity, application passes message that have been
  279. previously flagged by decrypt_message() as own message containing own key to this
  280. function.
  281. """;
  282. // exceptions
  283. throws illegal_value doc="illegal parameter values";
  284. throws any doc="any other value on error";
  285. }
  286. method outgoing_message_rating doc="get rating for an outgoing message"
  287. {
  288. // parms
  289. use message msg
  290. doc="""
  291. message to get the rating for. From must point to a valid pEp_identity
  292. msg->dir must be PEP_dir_outgoing
  293. """;
  294. return rating msg_rating doc="rating for the message";
  295. // exceptions
  296. throws illegal_value doc="illegal parameter values";
  297. }
  298. method outgoing_message_rating_preview doc="get rating preview"
  299. {
  300. // parms
  301. use message msg
  302. doc="""
  303. message to get the rating for. From must point to a valid pEp_identity.
  304. msg->dir must be dir_outgoing.
  305. """;
  306. return rating msg_rating doc="rating preview for the message";
  307. // exceptions
  308. throws illegal_value doc="illegal parameter values";
  309. }
  310. method identity_rating doc="get rating for a single identity"
  311. {
  312. // parms
  313. use identity ident doc="identity to get the rating for";
  314. return rating identity_rating doc="rating for the identity";
  315. // exceptions
  316. throws illegal_value doc="illegal parameter values";
  317. throws any doc="any other value on error";
  318. }
  319. method get_trustwords doc="get full trustwords string for a *pair* of identities"
  320. {
  321. // parms
  322. use identity id1 doc="identity of first party in communication - fpr can't be empty";
  323. use identity id2 doc="identity of second party in communication - fpr can't be empty";
  324. use ISO639_1 lang doc="string with ISO 639-1 language code";
  325. create string words
  326. doc="""
  327. pointer to string with all trustwords, separated
  328. by a blank each. Empty if language is not supported or trustword
  329. wordlist is damaged or unavailable.
  330. The word pointer goes to the ownership of the caller.
  331. The caller is responsible to free() it (on Windoze use pEp_free())
  332. """;
  333. create size_t wsize doc="length of full trustwords string";
  334. use bool full
  335. doc="""
  336. if true, generate ALL trustwords for these identities.
  337. else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
  338. subset in next version)
  339. """;
  340. // exceptions
  341. throws out_of_memory doc="out of memory";
  342. throws illegal_value doc="illegal parameter values";
  343. throws trustword_not_found doc="at least one trustword not found";
  344. }
  345. method get_message_trustwords doc="get full trustwords string for message sender and reciever identities"
  346. {
  347. // parms
  348. use message msg doc="message to get sender identity from";
  349. use hash_list keylist doc="empty if message to be decrypted, keylist returned by decrypt_message() otherwise.";
  350. use identity received_by doc="identity for account receiving message can't be empty";
  351. use ISO639_1 lang doc="string with ISO 639-1 language code";
  352. create string words
  353. doc="""
  354. pointer to string with all trustwords, separated by a blank each.
  355. Empty if language is not supported or trustword wordlist is damaged or unavailable.
  356. """;
  357. use bool full
  358. doc="""
  359. if true, generate ALL trustwords for these identities.
  360. else, generate a fixed-size subset. (TODO: fixed-minimum-entropy
  361. subset in next version)
  362. """;
  363. // exceptions
  364. throws illegal_value doc="illegal parameter values";
  365. throws out_of_memory doc="out of memory";
  366. throws trustword_not_found doc="at least one trustword not found";
  367. throws cannot_find_identity doc="identity not found";
  368. throws error doc="status of decrypt_message() if decryption fails.";
  369. }
  370. method get_trustwords_for_fprs doc="get full trustwords string for a pair of fingerprints"
  371. {
  372. // parms
  373. use string fpr1 doc="fingerprint 1";
  374. use string fpr2 doc="fingerprint 2";
  375. use ISO639_1 lang doc="string with ISO 639-1 language code";
  376. create string words
  377. doc="""
  378. pointer to string with all trustwords UTF-8 encoded, separated by a blank each.
  379. Empty if language is not supported or trustword wordlist is damaged or unavailable.
  380. The caller is responsible to free() it (on Windoze use pEp_free()).
  381. """;
  382. return size_t wsize doc="length of full trustwords string";
  383. use bool full
  384. doc="""
  385. if true, generate ALL trustwords for these identities. Else, generate a fixed-size
  386. subset. (TODO: fixed-minimum-entropy subset in next version)
  387. """;
  388. // exceptions
  389. throws out_of_memory doc="out of memory";
  390. throws illegal_value doc="illegal parameter values";
  391. throws trustword_not_found doc="at least one trustword not found";
  392. }
  393. method re_evaluate_message_rating doc="re-evaluate already decrypted message rating"
  394. {
  395. // parms
  396. use message msg doc="message to get the rating for. msg->from must point to a valid pEp_identity";
  397. use hash_list x_keylist doc="decrypted message recipients keys fpr";
  398. use rating x_enc_status doc="original rating for the decrypted message";
  399. return rating msg_rating doc="rating for the message";
  400. // exceptions
  401. throws illegal_value
  402. doc="""
  403. if decrypted message doesn't contain X-EncStatus optional field and
  404. x_enc_status is pEp_rating_udefined or if decrypted message doesn't
  405. contain X-Keylist optional field and x_keylist is empty.
  406. """;
  407. throws out_of_memory doc="if not enough memory could be allocated";
  408. throws any doc="any other value on error";
  409. }
  410. method get_key_rating_for_user doc="get the rating of a certain key for a certain user"
  411. {
  412. // parms
  413. use string user_id doc="string with user ID";
  414. use string fpr doc="string with fingerprint";
  415. return rating key_rating doc="rating of key for this user";
  416. // exceptions
  417. throws illegal_value doc="illegal parameter values";
  418. throws out_of_memory doc="out of memory";
  419. throws record_not_found doc="if no trust record for user_id and fpr can be found";
  420. throws any doc="any other value on error";
  421. }
  422. method rating_from_comm_type doc="get the rating for a comm type"
  423. {
  424. // parms
  425. use comm_type ct doc="the comm type to deliver the rating for";
  426. // exceptions
  427. throws rating doc="rating value for comm type ct";
  428. }
  429. }
  430. func color_from_rating doc="calculate color from rating"
  431. {
  432. // parms
  433. use color_from_rating rating doc="color representing that rating";
  434. // return value
  435. return color rating_color doc="color representing that rating";
  436. }
  437. func get_binary_path doc="retrieve path of cryptotech binary if available"
  438. {
  439. //parms
  440. use cryptotech tech doc="cryptotech to get the binary for";
  441. use string path
  442. doc="""
  443. path to cryptotech binary or empty if not available. **path is owned by
  444. the library, do not change it!
  445. """;
  446. }