PageRenderTime 27ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/src/include/gnunet_identity_service.h

https://gitlab.com/taler/gnunet
C Header | 334 lines | 82 code | 47 blank | 205 comment | 0 complexity | 357521bfe15fe91aa45438760b55c149 MD5 | raw file
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2013 GNUnet e.V.
  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 Christian Grothoff
  19. *
  20. * @file
  21. * Identity service; implements identity management for GNUnet
  22. *
  23. * @defgroup identity Identity service
  24. * Identity management.
  25. *
  26. * Egos in GNUnet are ECDSA keys. You assume an ego by using (signing
  27. * with) a particular private key. As GNUnet users are expected to
  28. * have many egos, we need an identity service to allow users to
  29. * manage their egos. The identity service manages the egos (private
  30. * keys) of the local user; it does NOT manage egos of other users
  31. * (public keys). For giving names to other users and manage their
  32. * public keys securely, we use GNS.
  33. *
  34. * @see [Documentation](https://gnunet.org/identity-subsystem)
  35. *
  36. * @{
  37. */
  38. #ifndef GNUNET_IDENTITY_SERVICE_H
  39. #define GNUNET_IDENTITY_SERVICE_H
  40. #ifdef __cplusplus
  41. extern "C"
  42. {
  43. #if 0 /* keep Emacsens' auto-indent happy */
  44. }
  45. #endif
  46. #endif
  47. #include "gnunet_util_lib.h"
  48. /**
  49. * Version number of GNUnet Identity API.
  50. */
  51. #define GNUNET_IDENTITY_VERSION 0x00000000
  52. /**
  53. * Handle to access the identity service.
  54. */
  55. struct GNUNET_IDENTITY_Handle;
  56. /**
  57. * Handle for a ego.
  58. */
  59. struct GNUNET_IDENTITY_Ego;
  60. /**
  61. * Handle for an operation with the identity service.
  62. */
  63. struct GNUNET_IDENTITY_Operation;
  64. /**
  65. * Obtain the ECC key associated with a ego.
  66. *
  67. * @param ego the ego
  68. * @return associated ECC key, valid as long as the ego is valid
  69. */
  70. const struct GNUNET_CRYPTO_EcdsaPrivateKey *
  71. GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego);
  72. /**
  73. * Obtain the ego representing 'anonymous' users.
  74. *
  75. * @return handle for the anonymous user, must not be freed
  76. */
  77. const struct GNUNET_IDENTITY_Ego *
  78. GNUNET_IDENTITY_ego_get_anonymous (void);
  79. /**
  80. * Get the identifier (public key) of an ego.
  81. *
  82. * @param ego identity handle with the private key
  83. * @param pk set to ego's public key
  84. */
  85. void
  86. GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
  87. struct GNUNET_CRYPTO_EcdsaPublicKey *pk);
  88. /**
  89. * Method called to inform about the egos of this peer.
  90. *
  91. * When used with #GNUNET_IDENTITY_connect, this function is
  92. * initially called for all egos and then again whenever a
  93. * ego's name changes or if it is deleted. At the end of
  94. * the initial pass over all egos, the function is once called
  95. * with 'NULL' for @a ego. That does NOT mean that the callback won't
  96. * be invoked in the future or that there was an error.
  97. *
  98. * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
  99. * this function is only called ONCE, and 'NULL' being passed in
  100. * @a ego does indicate an error (i.e. name is taken or no default
  101. * value is known). If @a ego is non-NULL and if '*ctx'
  102. * is set in those callbacks, the value WILL be passed to a subsequent
  103. * call to the identity callback of #GNUNET_IDENTITY_connect (if
  104. * that one was not NULL).
  105. *
  106. * When an identity is renamed, this function is called with the
  107. * (known) @a ego but the NEW @a name.
  108. *
  109. * When an identity is deleted, this function is called with the
  110. * (known) ego and "NULL" for the @a name. In this case,
  111. * the @a ego is henceforth invalid (and the @a ctx should also be
  112. * cleaned up).
  113. *
  114. * @param cls closure
  115. * @param ego ego handle
  116. * @param ctx context for application to store data for this ego
  117. * (during the lifetime of this process, initially NULL)
  118. * @param name name assigned by the user for this ego,
  119. * NULL if the user just deleted the ego and it
  120. * must thus no longer be used
  121. */
  122. typedef void
  123. (*GNUNET_IDENTITY_Callback)(void *cls,
  124. struct GNUNET_IDENTITY_Ego *ego,
  125. void **ctx,
  126. const char *name);
  127. /**
  128. * Connect to the identity service.
  129. *
  130. * @param cfg Configuration to contact the identity service.
  131. * @param cb function to call on all identity events, can be NULL
  132. * @param cb_cls closure for @a cb
  133. * @return handle to communicate with identity service
  134. */
  135. struct GNUNET_IDENTITY_Handle *
  136. GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  137. GNUNET_IDENTITY_Callback cb,
  138. void *cb_cls);
  139. /**
  140. * Obtain the ego that is currently preferred/default for a service.
  141. *
  142. * @param id identity service to query
  143. * @param service_name for which service is an identity wanted
  144. * @param cb function to call with the result (will only be called once)
  145. * @param cb_cls closure for @a cb
  146. * @return handle to abort the operation
  147. */
  148. struct GNUNET_IDENTITY_Operation *
  149. GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id,
  150. const char *service_name,
  151. GNUNET_IDENTITY_Callback cb,
  152. void *cb_cls);
  153. /**
  154. * Function called once the requested operation has
  155. * been completed.
  156. *
  157. * @param cls closure
  158. * @param emsg NULL on success, otherwise an error message
  159. */
  160. typedef void
  161. (*GNUNET_IDENTITY_Continuation)(void *cls,
  162. const char *emsg);
  163. /**
  164. * Set the preferred/default ego for a service.
  165. *
  166. * @param id identity service to inform
  167. * @param service_name for which service is an identity set
  168. * @param ego new default identity to be set for this service
  169. * @param cont function to call once the operation finished
  170. * @param cont_cls closure for @a cont
  171. * @return handle to abort the operation
  172. */
  173. struct GNUNET_IDENTITY_Operation *
  174. GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
  175. const char *service_name,
  176. struct GNUNET_IDENTITY_Ego *ego,
  177. GNUNET_IDENTITY_Continuation cont,
  178. void *cont_cls);
  179. /**
  180. * Disconnect from identity service.
  181. *
  182. * @param h identity service to disconnect
  183. */
  184. void
  185. GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
  186. /**
  187. * Create a new ego with the given name.
  188. *
  189. * @param id identity service to use
  190. * @param name desired name
  191. * @param cont function to call with the result (will only be called once)
  192. * @param cont_cls closure for @a cont
  193. * @return handle to abort the operation
  194. */
  195. struct GNUNET_IDENTITY_Operation *
  196. GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
  197. const char *name,
  198. GNUNET_IDENTITY_Continuation cont,
  199. void *cont_cls);
  200. /**
  201. * Renames an existing ego.
  202. *
  203. * @param id identity service to use
  204. * @param old_name old name
  205. * @param new_name desired new name
  206. * @param cb function to call with the result (will only be called once)
  207. * @param cb_cls closure for @a cb
  208. * @return handle to abort the operation
  209. */
  210. struct GNUNET_IDENTITY_Operation *
  211. GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
  212. const char *old_name,
  213. const char *new_name,
  214. GNUNET_IDENTITY_Continuation cb,
  215. void *cb_cls);
  216. /**
  217. * Delete an existing ego.
  218. *
  219. * @param id identity service to use
  220. * @param name name of the identity to delete
  221. * @param cb function to call with the result (will only be called once)
  222. * @param cb_cls closure for @a cb
  223. * @return handle to abort the operation
  224. */
  225. struct GNUNET_IDENTITY_Operation *
  226. GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
  227. const char *name,
  228. GNUNET_IDENTITY_Continuation cb,
  229. void *cb_cls);
  230. /**
  231. * Cancel an identity operation. Note that the operation MAY still
  232. * be executed; this merely cancels the continuation; if the request
  233. * was already transmitted, the service may still choose to complete
  234. * the operation.
  235. *
  236. * @param op operation to cancel
  237. */
  238. void
  239. GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
  240. /* ************* convenience API to lookup an ego ***************** */
  241. /**
  242. * Function called with the result.
  243. *
  244. * @param cls closure
  245. * @param ego NULL on error / ego not found
  246. */
  247. typedef void
  248. (*GNUNET_IDENTITY_EgoCallback)(void *cls,
  249. const struct GNUNET_IDENTITY_Ego *ego);
  250. /**
  251. * Handle for ego lookup.
  252. */
  253. struct GNUNET_IDENTITY_EgoLookup;
  254. /**
  255. * Lookup an ego by name.
  256. *
  257. * @param cfg configuration to use
  258. * @param name name to look up
  259. * @param cb callback to invoke with the result
  260. * @param cb_cls closure for @a cb
  261. * @return NULL on error
  262. */
  263. struct GNUNET_IDENTITY_EgoLookup *
  264. GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
  265. const char *name,
  266. GNUNET_IDENTITY_EgoCallback cb,
  267. void *cb_cls);
  268. /**
  269. * Abort ego lookup attempt.
  270. *
  271. * @param el handle for lookup to abort
  272. */
  273. void
  274. GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el);
  275. #if 0 /* keep Emacsens' auto-indent happy */
  276. {
  277. #endif
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281. /* ifndef GNUNET_IDENTITY_SERVICE_H */
  282. #endif
  283. /** @} */ /* end of group identity */
  284. /* end of gnunet_identity_service.h */