gnunet_reclaim_service.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Martin Schanzenbach
  18. *
  19. * @file
  20. * reclaim service; implements identity and personal data sharing
  21. * for GNUnet
  22. *
  23. * @defgroup reclaim service
  24. * @{
  25. */
  26. #ifndef GNUNET_RECLAIM_SERVICE_H
  27. #define GNUNET_RECLAIM_SERVICE_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #if 0 /* keep Emacsens' auto-indent happy */
  31. }
  32. #endif
  33. #endif
  34. #include "gnunet_reclaim_lib.h"
  35. #include "gnunet_util_lib.h"
  36. /**
  37. * Version number of the re:claimID API.
  38. */
  39. #define GNUNET_RECLAIM_VERSION 0x00000001
  40. /**
  41. * Opaque handle to access the service.
  42. */
  43. struct GNUNET_RECLAIM_Handle;
  44. /**
  45. * Opaque handle for an operation at the re:claimID service.
  46. */
  47. struct GNUNET_RECLAIM_Operation;
  48. /**
  49. * The authorization ticket. This ticket is meant to be transferred
  50. * out of band to a relying party.
  51. * The contents of a ticket must be protected and should be treated as a
  52. * shared secret between user and relying party.
  53. */
  54. struct GNUNET_RECLAIM_Ticket
  55. {
  56. /**
  57. * The ticket issuer (= the user)
  58. */
  59. struct GNUNET_CRYPTO_EcdsaPublicKey identity;
  60. /**
  61. * The ticket audience (= relying party)
  62. */
  63. struct GNUNET_CRYPTO_EcdsaPublicKey audience;
  64. /**
  65. * The ticket random identifier
  66. */
  67. struct GNUNET_RECLAIM_Identifier rnd;
  68. };
  69. /**
  70. * Method called when a token has been issued.
  71. * On success returns a ticket that can be given to a relying party
  72. * in order for it retrive identity attributes
  73. *
  74. * @param cls closure
  75. * @param ticket the ticket
  76. */
  77. typedef void (*GNUNET_RECLAIM_TicketCallback) (
  78. void *cls, const struct GNUNET_RECLAIM_Ticket *ticket);
  79. /**
  80. * Continuation called to notify client about result of the
  81. * operation.
  82. *
  83. * @param cls The callback closure
  84. * @param success #GNUNET_SYSERR on failure
  85. * @param emsg NULL on success, otherwise an error message
  86. */
  87. typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
  88. int32_t success,
  89. const char *emsg);
  90. /**
  91. * Callback used to notify the client of attribute results.
  92. *
  93. * @param cls The callback closure
  94. * @param identity The identity authoritative over the attributes
  95. * @param attr The attribute
  96. * @param attestation The attestation for the attribute (may be NULL)
  97. */
  98. typedef void (*GNUNET_RECLAIM_AttributeResult) (
  99. void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
  100. const struct GNUNET_RECLAIM_Attribute *attr);
  101. /**
  102. * Callback used to notify the client of attribute results.
  103. *
  104. * @param cls The callback closure
  105. * @param identity The identity authoritative over the attributes
  106. * @param attr The attribute
  107. * @param attestation The attestation for the attribute (may be NULL)
  108. */
  109. typedef void (*GNUNET_RECLAIM_AttributeTicketResult) (
  110. void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
  111. const struct GNUNET_RECLAIM_Attribute *attr,
  112. const struct GNUNET_RECLAIM_Attestation *attestation);
  113. /**
  114. * Callback used to notify the client of attestation results.
  115. *
  116. * @param cls The callback closure
  117. * @param identity The identity authoritative over the attributes
  118. * @param attestation The attestation
  119. * @param attributes the parsed attributes
  120. */
  121. typedef void (*GNUNET_RECLAIM_AttestationResult) (
  122. void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
  123. const struct GNUNET_RECLAIM_Attestation *attestation);
  124. /**
  125. * Connect to the re:claimID service.
  126. *
  127. * @param cfg Configuration to contact the re:claimID service.
  128. * @return handle to communicate with the service
  129. */
  130. struct GNUNET_RECLAIM_Handle *
  131. GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  132. /**
  133. * Store an attribute. If the attribute is already present,
  134. * it is replaced with the new attribute.
  135. *
  136. * @param h handle to the reclaim service
  137. * @param pkey Private key of the identity to add an attribute to
  138. * @param attr The attribute
  139. * @param exp_interval The relative expiration interval for the attribute
  140. * @param cont Continuation to call when done
  141. * @param cont_cls Closure for @a cont
  142. * @return handle Used to to abort the request
  143. */
  144. struct GNUNET_RECLAIM_Operation *
  145. GNUNET_RECLAIM_attribute_store (
  146. struct GNUNET_RECLAIM_Handle *h,
  147. const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
  148. const struct GNUNET_RECLAIM_Attribute *attr,
  149. const struct GNUNET_TIME_Relative *exp_interval,
  150. GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
  151. /**
  152. * Store an attestation. If the attestation is already present,
  153. * it is replaced with the new attestation.
  154. *
  155. * @param h handle to the re:claimID service
  156. * @param pkey private key of the identity
  157. * @param attr the attestation value
  158. * @param exp_interval the relative expiration interval for the attestation
  159. * @param cont continuation to call when done
  160. * @param cont_cls closure for @a cont
  161. * @return handle to abort the request
  162. */
  163. struct GNUNET_RECLAIM_Operation *
  164. GNUNET_RECLAIM_attestation_store (
  165. struct GNUNET_RECLAIM_Handle *h,
  166. const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
  167. const struct GNUNET_RECLAIM_Attestation *attestation,
  168. const struct GNUNET_TIME_Relative *exp_interval,
  169. GNUNET_RECLAIM_ContinuationWithStatus cont,
  170. void *cont_cls);
  171. /**
  172. * Delete an attribute. Tickets used to share this attribute are updated
  173. * accordingly.
  174. *
  175. * @param h handle to the re:claimID service
  176. * @param pkey Private key of the identity to add an attribute to
  177. * @param attr The attribute
  178. * @param cont Continuation to call when done
  179. * @param cont_cls Closure for @a cont
  180. * @return handle Used to to abort the request
  181. */
  182. struct GNUNET_RECLAIM_Operation *
  183. GNUNET_RECLAIM_attribute_delete (
  184. struct GNUNET_RECLAIM_Handle *h,
  185. const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
  186. const struct GNUNET_RECLAIM_Attribute *attr,
  187. GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls);
  188. /**
  189. * Delete an attestation. Tickets used to share this attestation are updated
  190. * accordingly.
  191. *
  192. * @param h handle to the re:claimID service
  193. * @param pkey Private key of the identity to add an attribute to
  194. * @param attr The attestation
  195. * @param cont Continuation to call when done
  196. * @param cont_cls Closure for @a cont
  197. * @return handle Used to to abort the request
  198. */
  199. struct GNUNET_RECLAIM_Operation *
  200. GNUNET_RECLAIM_attestation_delete (
  201. struct GNUNET_RECLAIM_Handle *h,
  202. const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
  203. const struct GNUNET_RECLAIM_Attestation *attr,
  204. GNUNET_RECLAIM_ContinuationWithStatus cont,
  205. void *cont_cls);
  206. /**
  207. * List all attributes for a local identity.
  208. * This MUST lock the `struct GNUNET_RECLAIM_Handle`
  209. * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
  210. * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
  211. * immediately, and then again after
  212. * #GNUNET_RECLAIM_get_attributes_next() is invoked.
  213. *
  214. * On error (disconnect), @a error_cb will be invoked.
  215. * On normal completion, @a finish_cb proc will be
  216. * invoked.
  217. *
  218. * @param h Handle to the re:claimID service
  219. * @param identity Identity to iterate over
  220. * @param error_cb Function to call on error (i.e. disconnect),
  221. * the handle is afterwards invalid
  222. * @param error_cb_cls Closure for @a error_cb
  223. * @param proc Function to call on each attribute
  224. * @param proc_cls Closure for @a proc
  225. * @param finish_cb Function to call on completion
  226. * the handle is afterwards invalid
  227. * @param finish_cb_cls Closure for @a finish_cb
  228. * @return an iterator Handle to use for iteration
  229. */
  230. struct GNUNET_RECLAIM_AttributeIterator *
  231. GNUNET_RECLAIM_get_attributes_start (
  232. struct GNUNET_RECLAIM_Handle *h,
  233. const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
  234. GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
  235. GNUNET_RECLAIM_AttributeResult proc, void *proc_cls,
  236. GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
  237. /**
  238. * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
  239. * for the next record.
  240. *
  241. * @param it The iterator
  242. */
  243. void
  244. GNUNET_RECLAIM_get_attributes_next (
  245. struct GNUNET_RECLAIM_AttributeIterator *it);
  246. /**
  247. * Stops iteration and releases the handle for further calls. Must
  248. * be called on any iteration that has not yet completed prior to calling
  249. * #GNUNET_RECLAIM_disconnect.
  250. *
  251. * @param it the iterator
  252. */
  253. void
  254. GNUNET_RECLAIM_get_attributes_stop (
  255. struct GNUNET_RECLAIM_AttributeIterator *it);
  256. /**
  257. * List all attestations for a local identity.
  258. * This MUST lock the `struct GNUNET_RECLAIM_Handle`
  259. * for any other calls than #GNUNET_RECLAIM_get_attestations_next() and
  260. * #GNUNET_RECLAIM_get_attestations_stop. @a proc will be called once
  261. * immediately, and then again after
  262. * #GNUNET_RECLAIM_get_attestations_next() is invoked.
  263. *
  264. * On error (disconnect), @a error_cb will be invoked.
  265. * On normal completion, @a finish_cb proc will be
  266. * invoked.
  267. *
  268. * @param h Handle to the re:claimID service
  269. * @param identity Identity to iterate over
  270. * @param error_cb Function to call on error (i.e. disconnect),
  271. * the handle is afterwards invalid
  272. * @param error_cb_cls Closure for @a error_cb
  273. * @param proc Function to call on each attestation
  274. * @param proc_cls Closure for @a proc
  275. * @param finish_cb Function to call on completion
  276. * the handle is afterwards invalid
  277. * @param finish_cb_cls Closure for @a finish_cb
  278. * @return an iterator Handle to use for iteration
  279. */
  280. struct GNUNET_RECLAIM_AttestationIterator *
  281. GNUNET_RECLAIM_get_attestations_start (
  282. struct GNUNET_RECLAIM_Handle *h,
  283. const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
  284. GNUNET_SCHEDULER_TaskCallback error_cb,
  285. void *error_cb_cls,
  286. GNUNET_RECLAIM_AttestationResult proc,
  287. void *proc_cls,
  288. GNUNET_SCHEDULER_TaskCallback finish_cb,
  289. void *finish_cb_cls);
  290. /**
  291. * Calls the record processor specified in #GNUNET_RECLAIM_get_attestation_start
  292. * for the next record.
  293. *
  294. * @param it the iterator
  295. */
  296. void
  297. GNUNET_RECLAIM_get_attestations_next (struct
  298. GNUNET_RECLAIM_AttestationIterator *ait);
  299. /**
  300. * Stops iteration and releases the handle for further calls. Must
  301. * be called on any iteration that has not yet completed prior to calling
  302. * #GNUNET_RECLAIM_disconnect.
  303. *
  304. * @param it the iterator
  305. */
  306. void
  307. GNUNET_RECLAIM_get_attestations_stop (struct
  308. GNUNET_RECLAIM_AttestationIterator *ait);
  309. /**
  310. * Issues a ticket to a relying party. The identity may use
  311. * GNUNET_RECLAIM_ticket_consume to consume the ticket
  312. * and retrieve the attributes specified in the attribute list.
  313. *
  314. * @param h the identity provider to use
  315. * @param iss the issuing identity (= the user)
  316. * @param rp the subject of the ticket (= the relying party)
  317. * @param attrs the attributes that the relying party is given access to
  318. * @param cb the callback
  319. * @param cb_cls the callback closure
  320. * @return handle to abort the operation
  321. */
  322. struct GNUNET_RECLAIM_Operation *
  323. GNUNET_RECLAIM_ticket_issue (
  324. struct GNUNET_RECLAIM_Handle *h,
  325. const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
  326. const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
  327. const struct GNUNET_RECLAIM_AttributeList *attrs,
  328. GNUNET_RECLAIM_TicketCallback cb, void *cb_cls);
  329. /**
  330. * Revoked an issued ticket. The relying party will be unable to retrieve
  331. * attributes. Other issued tickets remain unaffected.
  332. * This includes tickets issued to other relying parties as well as to
  333. * other tickets issued to the audience specified in this ticket.
  334. *
  335. * @param h the identity provider to use
  336. * @param identity the issuing identity
  337. * @param ticket the ticket to revoke
  338. * @param cb the callback
  339. * @param cb_cls the callback closure
  340. * @return handle to abort the operation
  341. */
  342. struct GNUNET_RECLAIM_Operation *
  343. GNUNET_RECLAIM_ticket_revoke (
  344. struct GNUNET_RECLAIM_Handle *h,
  345. const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
  346. const struct GNUNET_RECLAIM_Ticket *ticket,
  347. GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls);
  348. /**
  349. * Consumes an issued ticket. The ticket is used to retrieve identity
  350. * information from the issuer
  351. *
  352. * @param h the identity provider to use
  353. * @param identity the identity that is the subject of the issued ticket (the
  354. * relying party)
  355. * @param ticket the issued ticket to consume
  356. * @param cb the callback to call
  357. * @param cb_cls the callback closure
  358. * @return handle to abort the operation
  359. */
  360. struct GNUNET_RECLAIM_Operation *
  361. GNUNET_RECLAIM_ticket_consume (
  362. struct GNUNET_RECLAIM_Handle *h,
  363. const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
  364. const struct GNUNET_RECLAIM_Ticket *ticket,
  365. GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls);
  366. /**
  367. * Lists all tickets that have been issued to remote
  368. * identites (relying parties)
  369. *
  370. * @param h the identity provider to use
  371. * @param identity the issuing identity
  372. * @param error_cb function to call on error (i.e. disconnect),
  373. * the handle is afterwards invalid
  374. * @param error_cb_cls closure for @a error_cb
  375. * @param proc function to call on each ticket; it
  376. * will be called repeatedly with a value (if available)
  377. * @param proc_cls closure for @a proc
  378. * @param finish_cb function to call on completion
  379. * the handle is afterwards invalid
  380. * @param finish_cb_cls closure for @a finish_cb
  381. * @return an iterator handle to use for iteration
  382. */
  383. struct GNUNET_RECLAIM_TicketIterator *
  384. GNUNET_RECLAIM_ticket_iteration_start (
  385. struct GNUNET_RECLAIM_Handle *h,
  386. const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
  387. GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls,
  388. GNUNET_RECLAIM_TicketCallback proc, void *proc_cls,
  389. GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls);
  390. /**
  391. * Calls the ticket processor specified in
  392. * #GNUNET_RECLAIM_ticket_iteration_start for the next record.
  393. *
  394. * @param it the iterator
  395. */
  396. void
  397. GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it);
  398. /**
  399. * Stops iteration and releases the handle for further calls. Must
  400. * be called on any iteration that has not yet completed prior to calling
  401. * #GNUNET_RECLAIM_disconnect.
  402. *
  403. * @param it the iterator
  404. */
  405. void
  406. GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it);
  407. /**
  408. * Disconnect from identity provider service.
  409. *
  410. * @param h identity provider service to disconnect
  411. */
  412. void
  413. GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
  414. /**
  415. * Cancel an identity provider operation. Note that the operation MAY still
  416. * be executed; this merely cancels the continuation; if the request
  417. * was already transmitted, the service may still choose to complete
  418. * the operation.
  419. *
  420. * @param op operation to cancel
  421. */
  422. void
  423. GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
  424. #if 0 /* keep Emacsens' auto-indent happy */
  425. {
  426. #endif
  427. #ifdef __cplusplus
  428. }
  429. #endif
  430. /* ifndef GNUNET_RECLAIM_SERVICE_H */
  431. #endif
  432. /** @} */ /* end of group reclaim */
  433. /* end of gnunet_reclaim_service.h */