#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_identity_service.h"
#include "gnunet_rest_lib.h"
#include "../../service/identity/identity.h"
#include "gnunet_util_lib.h"
#include "microhttpd.h"
#include <jansson.h>
#include "identity_plugin.h"
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | EgoEntry |
The default namestore ego. More... | |
struct | RequestHandle |
The request handle. More... | |
struct | ego_sign_data_cls |
Macros | |
#define | GNUNET_REST_API_NS_IDENTITY "/identity" |
Identity Namespace. More... | |
#define | GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey" |
Identity Namespace with public key specifier. More... | |
#define | GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name" |
Identity Namespace with public key specifier. More... | |
#define | GNUNET_REST_API_NS_SIGN "/sign" |
Identity Namespace with sign specifier. More... | |
#define | GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" |
Parameter public key. More... | |
#define | GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" |
Parameter private key. More... | |
#define | GNUNET_REST_IDENTITY_PARAM_NAME "name" |
Parameter name. More... | |
#define | GNUNET_REST_IDENTITY_PARAM_TYPE "type" |
Parameter type. More... | |
#define | GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname" |
Parameter new name. More... | |
#define | GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name" |
Error message Missing identity name. More... | |
#define | GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key" |
Error message Missing identity name. More... | |
#define | GNUNET_REST_ERROR_NO_DATA "No data" |
Error message No data. More... | |
#define | GNUNET_REST_ERROR_DATA_INVALID "Data invalid" |
Error message Data invalid. More... | |
#define | ID_REST_STATE_INIT 0 |
State while collecting all egos. More... | |
#define | ID_REST_STATE_POST_INIT 1 |
Done collecting egos. More... | |
Functions | |
static void | cleanup_handle (void *cls) |
Cleanup lookup handle. More... | |
static void | do_error (void *cls) |
Task run on errors. More... | |
static struct EgoEntry * | get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) |
Get EgoEntry from list with either a public key or a name If public key and name are not NULL, it returns the public key result first. More... | |
static void | ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity GET request - responds with all identities. More... | |
static void | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) |
Responds with the ego_entry identity. More... | |
static void | ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity GET request with a public key. More... | |
static void | ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity GET request with a name. More... | |
static void | do_finished (void *cls, enum GNUNET_ErrorCode ec) |
Processing finished. More... | |
static void | do_finished_create (void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec) |
Processing finished, when creating an ego. More... | |
static void | ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) |
Processing edit ego with EgoEntry ego_entry. More... | |
static void | ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity PUT request with public key. More... | |
static void | ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity PUT request with name. More... | |
static void | ego_create (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity POST request. More... | |
static void | ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity DELETE request with public key. More... | |
static void | ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle identity DELETE request with name. More... | |
static void | ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
static void | ego_sign_data (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
static void | options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Respond to OPTIONS request. More... | |
static void | list_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier) |
enum GNUNET_GenericReturnValue | REST_identity_process_request (void *plugin, struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls) |
Function processing the REST call. More... | |
void * | REST_identity_init (const struct GNUNET_CONFIGURATION_Handle *c) |
Entry point for the plugin. More... | |
void | REST_identity_done (struct GNUNET_REST_Plugin *api) |
Exit point from the plugin. More... | |
Variables | |
const struct GNUNET_CONFIGURATION_Handle * | id_cfg |
The configuration handle. More... | |
static char * | allow_methods |
HTTP methods allows for this plugin. More... | |
static struct EgoEntry * | ego_head |
Ego list. More... | |
static struct EgoEntry * | ego_tail |
Ego list. More... | |
static int | state |
The processing state. More... | |
static struct GNUNET_IDENTITY_Handle * | identity_handle |
Handle to Identity service. More... | |
static struct RequestHandle * | requests_head |
DLL. More... | |
static struct RequestHandle * | requests_tail |
DLL. More... | |
#define GNUNET_REST_API_NS_IDENTITY "/identity" |
Identity Namespace.
Definition at line 40 of file identity_plugin.c.
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey" |
Identity Namespace with public key specifier.
Definition at line 45 of file identity_plugin.c.
#define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name" |
Identity Namespace with public key specifier.
Definition at line 50 of file identity_plugin.c.
#define GNUNET_REST_API_NS_SIGN "/sign" |
Identity Namespace with sign specifier.
Definition at line 55 of file identity_plugin.c.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey" |
Parameter public key.
Definition at line 60 of file identity_plugin.c.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey" |
Parameter private key.
Definition at line 65 of file identity_plugin.c.
#define GNUNET_REST_IDENTITY_PARAM_NAME "name" |
Parameter name.
Definition at line 70 of file identity_plugin.c.
#define GNUNET_REST_IDENTITY_PARAM_TYPE "type" |
Parameter type.
Definition at line 75 of file identity_plugin.c.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname" |
Parameter new name.
Definition at line 80 of file identity_plugin.c.
Error message Missing identity name.
Definition at line 85 of file identity_plugin.c.
Error message Missing identity name.
Definition at line 90 of file identity_plugin.c.
#define GNUNET_REST_ERROR_NO_DATA "No data" |
Error message No data.
Definition at line 95 of file identity_plugin.c.
#define GNUNET_REST_ERROR_DATA_INVALID "Data invalid" |
Error message Data invalid.
Definition at line 100 of file identity_plugin.c.
#define ID_REST_STATE_INIT 0 |
State while collecting all egos.
Definition at line 105 of file identity_plugin.c.
#define ID_REST_STATE_POST_INIT 1 |
Done collecting egos.
Definition at line 110 of file identity_plugin.c.
|
static |
Cleanup lookup handle.
cls | Handle to clean up |
Definition at line 274 of file identity_plugin.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.
Referenced by do_error(), do_finished(), ego_get_all(), ego_get_response(), ego_sign_data_cb(), options_cont(), REST_identity_done(), and REST_identity_process_request().
|
static |
Task run on errors.
Reports an error and cleans up everything.
cls | the struct RequestHandle |
Definition at line 302 of file identity_plugin.c.
References cleanup_handle(), GNUNET_assert, GNUNET_ErrorCode_get_hint(), GNUNET_ErrorCode_get_http_status(), GNUNET_free, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and response.
Referenced by do_finished(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), ego_edit_name(), ego_edit_pubkey(), ego_get_name(), ego_get_pubkey(), ego_sign_data(), ego_sign_data_cb(), and REST_identity_process_request().
|
static |
Get EgoEntry from list with either a public key or a name If public key and name are not NULL, it returns the public key result first.
handle | the RequestHandle |
pubkey | the public key of an identity (only one can be NULL) |
name | the name of an identity (only one can be NULL) |
Definition at line 338 of file identity_plugin.c.
References ego_head, EgoEntry::identifier, EgoEntry::keystring, name, EgoEntry::next, and pubkey.
Referenced by ego_delete_name(), ego_delete_pubkey(), ego_edit_name(), ego_edit_pubkey(), ego_get_name(), and ego_get_pubkey().
|
static |
Handle identity GET request - responds with all identities.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 374 of file identity_plugin.c.
References cleanup_handle(), EgoEntry::ego, ego_head, GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_private_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_REST_create_response(), GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_REST_IDENTITY_PARAM_PUBKEY, GNUNET_SCHEDULER_add_now(), GNUNET_YES, handle, EgoEntry::identifier, key, EgoEntry::keystring, and EgoEntry::next.
Referenced by REST_identity_process_request().
|
static |
Responds with the ego_entry identity.
handle | the struct RequestHandle |
ego_entry | the struct EgoEntry for the response |
Definition at line 436 of file identity_plugin.c.
References cleanup_handle(), EgoEntry::ego, GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_private_key_to_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_REST_create_response(), GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_REST_IDENTITY_PARAM_PUBKEY, GNUNET_SCHEDULER_add_now(), GNUNET_YES, handle, EgoEntry::identifier, key, and EgoEntry::keystring.
Referenced by ego_get_name(), and ego_get_pubkey().
|
static |
Handle identity GET request with a public key.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 485 of file identity_plugin.c.
References do_error(), ego_get_response(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_SCHEDULER_add_now(), handle, and EgoEntry::keystring.
Referenced by REST_identity_process_request().
|
static |
Handle identity GET request with a name.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 523 of file identity_plugin.c.
References do_error(), ego_get_response(), egoname, get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_SCHEDULER_add_now(), and handle.
Referenced by REST_identity_process_request().
|
static |
Processing finished.
cls | request handle |
ec | error code |
Definition at line 560 of file identity_plugin.c.
References cleanup_handle(), do_error(), GNUNET_EC_NONE, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
Referenced by do_finished_create(), ego_delete_name(), ego_delete_pubkey(), and ego_edit().
|
static |
Processing finished, when creating an ego.
cls | request handle |
pk | private key of the ego, or NULL on error |
ec | error code |
Definition at line 593 of file identity_plugin.c.
References do_finished(), RequestHandle::ec, handle, and pk.
Referenced by ego_create().
|
static |
Processing edit ego with EgoEntry ego_entry.
handle | the struct RequestHandle |
ego_entry | the struct EgoEntry we want to edit |
Definition at line 611 of file identity_plugin.c.
References do_error(), do_finished(), RequestHandle::ego_entry, GNUNET_EC_IDENTITY_INVALID, GNUNET_EC_UNKNOWN, GNUNET_IDENTITY_rename(), GNUNET_memcpy, GNUNET_REST_IDENTITY_PARAM_NEWNAME, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, and identity_handle.
Referenced by ego_edit_name(), and ego_edit_pubkey().
|
static |
Handle identity PUT request with public key.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 696 of file identity_plugin.c.
References do_error(), ego_edit(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_SCHEDULER_add_now(), handle, and EgoEntry::keystring.
Referenced by REST_identity_process_request().
|
static |
Handle identity PUT request with name.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 734 of file identity_plugin.c.
References do_error(), ego_edit(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_SCHEDULER_add_now(), handle, and name.
Referenced by REST_identity_process_request().
|
static |
Handle identity POST request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 772 of file identity_plugin.c.
References do_error(), do_finished_create(), egoname, GNUNET_EC_IDENTITY_INVALID, GNUNET_IDENTITY_create(), GNUNET_memcpy, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_REST_API_NS_IDENTITY, GNUNET_REST_IDENTITY_PARAM_NAME, GNUNET_REST_IDENTITY_PARAM_PRIVKEY, GNUNET_REST_IDENTITY_PARAM_TYPE, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_STRINGS_string_to_data(), GNUNET_STRINGS_utf8_tolower(), handle, identity_handle, pk, and type.
Referenced by REST_identity_process_request().
|
static |
Handle identity DELETE request with public key.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 873 of file identity_plugin.c.
References do_error(), do_finished(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_IDENTITY_delete(), GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity_handle, and EgoEntry::keystring.
Referenced by REST_identity_process_request().
|
static |
Handle identity DELETE request with name.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 915 of file identity_plugin.c.
References do_error(), do_finished(), get_egoentry(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_IDENTITY_delete(), GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_SCHEDULER_add_now(), handle, EgoEntry::identifier, identity_handle, and name.
Referenced by REST_identity_process_request().
|
static |
Definition at line 956 of file identity_plugin.c.
References cleanup_handle(), data, do_error(), GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_asprintf(), GNUNET_CRYPTO_eddsa_sign_raw(), GNUNET_EC_IDENTITY_NOT_FOUND, GNUNET_EC_UNKNOWN, GNUNET_OK, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_base64url_encode(), handle, GNUNET_IDENTITY_Ego::pk, result, and GNUNET_CRYPTO_PrivateKey::type.
Referenced by ego_sign_data().
|
static |
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 1016 of file identity_plugin.c.
References data, ego_sign_data_cls::data, do_error(), ego_sign_data_cb(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_EC_UNKNOWN, GNUNET_IDENTITY_ego_lookup(), GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, ego_sign_data_cls::handle, and id_cfg.
Referenced by REST_identity_process_request().
|
static |
Respond to OPTIONS request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 1074 of file identity_plugin.c.
References allow_methods, cleanup_handle(), GNUNET_assert, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
Referenced by REST_identity_process_request().
|
static |
Definition at line 1093 of file identity_plugin.c.
References EgoEntry::ego, ego_head, ego_tail, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_public_key_to_string(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), GNUNET_log, GNUNET_new, GNUNET_strdup, ID_REST_STATE_INIT, ID_REST_STATE_POST_INIT, EgoEntry::identifier, EgoEntry::keystring, EgoEntry::next, pk, and state.
Referenced by REST_identity_init().
enum GNUNET_GenericReturnValue REST_identity_process_request | ( | void * | plugin, |
struct GNUNET_REST_RequestHandle * | rest_handle, | ||
GNUNET_REST_ResultProcessor | proc, | ||
void * | proc_cls | ||
) |
Function processing the REST call.
method | HTTP method |
url | URL of the HTTP request |
data | body of the HTTP request (optional) |
data_size | length of the body |
proc | callback function for the result |
proc_cls | closure for callback function |
Definition at line 1186 of file identity_plugin.c.
References cleanup_handle(), GNUNET_REST_RequestHandle::data, GNUNET_REST_RequestHandle::data_size, do_error(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit_name(), ego_edit_pubkey(), ego_get_all(), ego_get_name(), ego_get_pubkey(), ego_sign_data(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_IDENTITY, GNUNET_REST_API_NS_IDENTITY_NAME, GNUNET_REST_API_NS_IDENTITY_PUBKEY, GNUNET_REST_API_NS_SIGN, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, handle, handlers, options_cont(), GNUNET_REST_RequestHandler::proc, requests_head, requests_tail, and GNUNET_REST_RequestHandle::url.
Referenced by run().
void * REST_identity_init | ( | const struct GNUNET_CONFIGURATION_Handle * | c | ) |
Entry point for the plugin.
cls | Config info |
Definition at line 1249 of file identity_plugin.c.
References _, allow_methods, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_new, GNUNET_REST_API_NS_IDENTITY, id_cfg, ID_REST_STATE_INIT, identity_handle, list_ego(), GNUNET_REST_Plugin::name, plugin, and state.
Referenced by run().
void REST_identity_done | ( | struct GNUNET_REST_Plugin * | api | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 1284 of file identity_plugin.c.
References allow_methods, Plugin::api, cleanup_handle(), GNUNET_BLOCK_PluginFunctions::cls, ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_log, EgoEntry::identifier, identity_handle, EgoEntry::keystring, EgoEntry::next, plugin, and requests_head.
Referenced by do_shutdown().
const struct GNUNET_CONFIGURATION_Handle* id_cfg |
The configuration handle.
Definition at line 115 of file identity_plugin.c.
Referenced by ego_sign_data(), and REST_identity_init().
|
static |
HTTP methods allows for this plugin.
Definition at line 120 of file identity_plugin.c.
Referenced by options_cont(), REST_identity_done(), and REST_identity_init().
|
static |
Ego list.
Definition at line 125 of file identity_plugin.c.
Referenced by ego_get_all(), get_egoentry(), list_ego(), and REST_identity_done().
|
static |
|
static |
The processing state.
Definition at line 135 of file identity_plugin.c.
Referenced by list_ego(), and REST_identity_init().
|
static |
Handle to Identity service.
Definition at line 140 of file identity_plugin.c.
Referenced by ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), REST_identity_done(), and REST_identity_init().
|
static |
DLL.
Definition at line 262 of file identity_plugin.c.
Referenced by cleanup_handle(), REST_identity_done(), and REST_identity_process_request().
|
static |
DLL.
Definition at line 267 of file identity_plugin.c.
Referenced by cleanup_handle(), and REST_identity_process_request().