gnunet_identity_provider_service.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2016 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Martin Schanzenbach
  19. *
  20. * @file
  21. * Identity provider service; implements identity provider for GNUnet
  22. *
  23. * @defgroup identity-provider Identity Provider service
  24. * @{
  25. */
  26. #ifndef GNUNET_IDENTITY_PROVIDER_SERVICE_H
  27. #define GNUNET_IDENTITY_PROVIDER_SERVICE_H
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #if 0 /* keep Emacsens' auto-indent happy */
  32. }
  33. #endif
  34. #endif
  35. #include "gnunet_util_lib.h"
  36. /**
  37. * Version number of GNUnet Identity Provider API.
  38. */
  39. #define GNUNET_IDENTITY_PROVIDER_VERSION 0x00000000
  40. /**
  41. * Handle to access the identity service.
  42. */
  43. struct GNUNET_IDENTITY_PROVIDER_Handle;
  44. /**
  45. * Handle for a token.
  46. */
  47. struct GNUNET_IDENTITY_PROVIDER_Token;
  48. /**
  49. * Handle for a ticket
  50. */
  51. struct GNUNET_IDENTITY_PROVIDER_Ticket;
  52. /**
  53. * Handle for an operation with the identity provider service.
  54. */
  55. struct GNUNET_IDENTITY_PROVIDER_Operation;
  56. /**
  57. * Method called when a token has been exchanged for a ticket.
  58. * On success returns a token
  59. *
  60. * @param cls closure
  61. * @param token the token
  62. */
  63. typedef void
  64. (*GNUNET_IDENTITY_PROVIDER_ExchangeCallback)(void *cls,
  65. const struct GNUNET_IDENTITY_PROVIDER_Token *token);
  66. /**
  67. * Method called when a token has been issued.
  68. * On success returns a ticket that can be given to the audience to retrive the
  69. * token
  70. *
  71. * @param cls closure
  72. * @param grant the label in GNS pointing to the token
  73. * @param ticket the ticket
  74. * @param token the issued token
  75. * @param name name assigned by the user for this ego,
  76. * NULL if the user just deleted the ego and it
  77. * must thus no longer be used
  78. */
  79. typedef void
  80. (*GNUNET_IDENTITY_PROVIDER_IssueCallback)(void *cls,
  81. const char *grant,
  82. const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
  83. const struct GNUNET_IDENTITY_PROVIDER_Token *token);
  84. /**
  85. * Connect to the identity provider service.
  86. *
  87. * @param cfg Configuration to contact the identity provider service.
  88. * @return handle to communicate with identity provider service
  89. */
  90. struct GNUNET_IDENTITY_PROVIDER_Handle *
  91. GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
  92. /**
  93. * Issue a token for a specific audience.
  94. *
  95. * @param id identity provider service to use
  96. * @param iss issuer (identity)
  97. * @param aud audience (identity)
  98. * @param scope the identity attributes requested, comman separated
  99. * @param expiration the token expiration
  100. * @param nonce the nonce that will be included in token and ticket
  101. * @param cb callback to call with result
  102. * @param cb_cls closure
  103. * @return handle to abort the operation
  104. */
  105. struct GNUNET_IDENTITY_PROVIDER_Operation *
  106. GNUNET_IDENTITY_PROVIDER_issue_token (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
  107. const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss_key,
  108. const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
  109. const char* scope,
  110. struct GNUNET_TIME_Absolute expiration,
  111. uint64_t nonce,
  112. GNUNET_IDENTITY_PROVIDER_IssueCallback cb,
  113. void *cb_cls);
  114. /**
  115. * Exchange a ticket for a token. Intended to be used by audience that
  116. * received a ticket.
  117. *
  118. * @param id identity provider service to use
  119. * @param ticket the ticket to exchange
  120. * @param aud_privkey the audience of the ticket
  121. * @param cont function to call once the operation finished
  122. * @param cont_cls closure for @a cont
  123. * @return handle to abort the operation
  124. */
  125. struct GNUNET_IDENTITY_PROVIDER_Operation *
  126. GNUNET_IDENTITY_PROVIDER_exchange_ticket (struct GNUNET_IDENTITY_PROVIDER_Handle *id,
  127. const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
  128. const struct GNUNET_CRYPTO_EcdsaPrivateKey *aud_privkey,
  129. GNUNET_IDENTITY_PROVIDER_ExchangeCallback cont,
  130. void *cont_cls);
  131. /**
  132. * Disconnect from identity provider service.
  133. *
  134. * @param h identity provider service to disconnect
  135. */
  136. void
  137. GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h);
  138. /**
  139. * Cancel an identity provider operation. Note that the operation MAY still
  140. * be executed; this merely cancels the continuation; if the request
  141. * was already transmitted, the service may still choose to complete
  142. * the operation.
  143. *
  144. * @param op operation to cancel
  145. */
  146. void
  147. GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op);
  148. /**
  149. * Convenience API
  150. */
  151. /**
  152. * Destroy token
  153. *
  154. * @param token the token
  155. */
  156. void
  157. GNUNET_IDENTITY_PROVIDER_token_destroy(struct GNUNET_IDENTITY_PROVIDER_Token *token);
  158. /**
  159. * Returns string representation of token. A JSON-Web-Token.
  160. *
  161. * @param token the token
  162. * @return The JWT (must be freed)
  163. */
  164. char *
  165. GNUNET_IDENTITY_PROVIDER_token_to_string (const struct GNUNET_IDENTITY_PROVIDER_Token *token);
  166. /**
  167. * Returns string representation of ticket. Base64-Encoded
  168. *
  169. * @param ticket the ticket
  170. * @return the Base64-Encoded ticket
  171. */
  172. char *
  173. GNUNET_IDENTITY_PROVIDER_ticket_to_string (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket);
  174. /**
  175. * Created a ticket from a string (Base64 encoded ticket)
  176. *
  177. * @param input Base64 encoded ticket
  178. * @param ticket pointer where the ticket is stored
  179. * @return GNUNET_OK
  180. */
  181. int
  182. GNUNET_IDENTITY_PROVIDER_string_to_ticket (const char* input,
  183. struct GNUNET_IDENTITY_PROVIDER_Ticket **ticket);
  184. /**
  185. * Destroys a ticket
  186. *
  187. * @param ticket the ticket to destroy
  188. */
  189. void
  190. GNUNET_IDENTITY_PROVIDER_ticket_destroy(struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket);
  191. #if 0 /* keep Emacsens' auto-indent happy */
  192. {
  193. #endif
  194. #ifdef __cplusplus
  195. }
  196. #endif
  197. /* ifndef GNUNET_IDENTITY_PROVIDER_SERVICE_H */
  198. #endif
  199. /** @} */ /* end of group identity */
  200. /* end of gnunet_identity_provider_service.h */