33 #include "microhttpd.h"
39 #define GNUNET_REST_API_NS_IDENTITY "/identity"
44 #define GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey"
49 #define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name"
54 #define GNUNET_REST_API_NS_SIGN "/sign"
59 #define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey"
64 #define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey"
69 #define GNUNET_REST_IDENTITY_PARAM_NAME "name"
74 #define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname"
79 #define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name"
84 #define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key"
89 #define GNUNET_REST_ERROR_NO_DATA "No data"
94 #define GNUNET_REST_ERROR_DATA_INVALID "Data invalid"
99 #define ID_REST_STATE_INIT 0
104 #define ID_REST_STATE_POST_INIT 1
266 if (NULL !=
handle->timeout_task)
269 handle->timeout_task = NULL;
292 struct MHD_Response *resp;
293 json_t *json_error = json_object ();
297 json_object_set_new (json_error,
"error",
299 json_object_set_new (json_error,
"error_code", json_integer (
handle->ec));
301 if (0 == response_code)
303 response = json_dumps (json_error, 0);
307 "application/json"));
309 json_decref (json_error);
331 for (ego_entry =
ego_head; NULL != ego_entry;
332 ego_entry = ego_entry->
next)
341 for (ego_entry =
ego_head; NULL != ego_entry;
342 ego_entry = ego_entry->
next)
367 struct MHD_Response *resp;
374 json_root = json_array ();
376 for (ego_entry =
ego_head; NULL != ego_entry;
377 ego_entry = ego_entry->
next)
379 json_ego = json_object ();
380 json_object_set_new (json_ego,
386 handle->rest_handle->url_param_map, &
key))
390 json_object_set_new (json_ego,
392 json_string (privkey_str));
396 json_object_set_new (json_ego,
399 json_array_append (json_root, json_ego);
400 json_decref (json_ego);
403 result_str = json_dumps (json_root, 0);
408 "application/json"));
409 json_decref (json_root);
425 struct MHD_Response *resp;
431 json_ego = json_object ();
432 json_object_set_new (json_ego,
435 json_object_set_new (json_ego,
441 handle->rest_handle->url_param_map, &
key))
445 json_object_set_new (json_ego,
447 json_string (privkey_str));
451 result_str = json_dumps (json_ego, 0);
457 "application/json"));
458 json_decref (json_ego);
491 if (NULL == ego_entry)
529 if (NULL == ego_entry)
550 struct MHD_Response *resp;
601 char term_data[
handle->data_size + 1];
605 if (0 >=
handle->data_size)
612 term_data[
handle->data_size] =
'\0';
614 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
626 json_state = json_unpack (data_js,
635 json_decref (data_js);
643 json_decref (data_js);
647 if (0 >= strlen (newname))
651 json_decref (data_js);
664 json_decref (data_js);
667 json_decref (data_js);
699 if (NULL == ego_entry)
737 if (NULL == ego_entry)
767 int json_unpack_state;
768 char term_data[
handle->data_size + 1];
776 if (0 >=
handle->data_size)
782 term_data[
handle->data_size] =
'\0';
784 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
789 json_decref (data_js);
792 json_unpack_state = 0;
795 json_unpack (data_js,
"{s:s, s?:s!}",
798 if (0 != json_unpack_state)
802 json_decref (data_js);
810 json_decref (data_js);
816 json_decref (data_js);
833 json_decref (data_js);
870 if (NULL == ego_entry)
911 if (NULL == ego_entry)
936 struct MHD_Response *resp;
957 strlen ( (
char*)
data),
970 "{\"signature\": \"%s\"}",
995 const char *username_key =
"user";
996 const char *data_key =
"data";
1010 handle->rest_handle->url_param_map,
1011 &cache_key_username)) ||
1013 handle->rest_handle->url_param_map,
1022 handle->rest_handle->url_param_map,
1023 &cache_key_username);
1026 handle->rest_handle->url_param_map,
1051 struct MHD_Response *resp;
1057 "Access-Control-Allow-Methods",
1069 const char *identifier)
1082 "Called with NULL ego\n");
1090 ego_entry->
ego = ego;
1097 if (identifier != NULL)
1099 for (ego_entry =
ego_head; NULL != ego_entry;
1100 ego_entry = ego_entry->
next)
1102 if (ego_entry->
ego == ego)
1110 if (NULL == ego_entry)
1116 ego_entry->
ego = ego;
1126 for (ego_entry =
ego_head; NULL != ego_entry;
1127 ego_entry = ego_entry->
next)
1129 if (ego_entry->
ego == ego)
1132 if (NULL == ego_entry)
1170 { MHD_HTTP_METHOD_PUT,
1175 { MHD_HTTP_METHOD_DELETE,
1178 { MHD_HTTP_METHOD_DELETE,
1187 handle->proc_cls = proc_cls;
1189 handle->rest_handle = rest_handle;
1236 "%s, %s, %s, %s, %s",
1237 MHD_HTTP_METHOD_GET,
1238 MHD_HTTP_METHOD_POST,
1239 MHD_HTTP_METHOD_PUT,
1240 MHD_HTTP_METHOD_DELETE,
1241 MHD_HTTP_METHOD_OPTIONS);
1270 for (ego_entry =
ego_head; NULL != ego_entry;)
1272 ego_tmp = ego_entry;
1273 ego_entry = ego_entry->
next;
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
unsigned int GNUNET_ErrorCode_get_http_status(enum GNUNET_ErrorCode ec)
Return HTTP status for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_IDENTITY_NOT_FOUND
Ego not found.
@ GNUNET_EC_UNKNOWN
Unknown and unspecified error.
@ GNUNET_EC_NONE
No error (success).
@ GNUNET_EC_IDENTITY_INVALID
The given ego is invalid or malformed.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct MHD_Response * response
Our canonical response.
struct GNUNET_HashCode key
The key used in the DHT.
static char * egoname
Ego Attribut String.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
uint32_t data
The data value.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static int result
Global testing status.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
Identity service; implements identity management for GNUnet.
API for helper library to parse/create REST.
GNUnet service REST plugin header.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing identity.
char * GNUNET_IDENTITY_private_key_to_string(const struct GNUNET_IDENTITY_PrivateKey *key)
Creates a (Base32) string representation of the private key.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, const char *name, const struct GNUNET_IDENTITY_PrivateKey *privkey, enum GNUNET_IDENTITY_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing identity.
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
@ GNUNET_IDENTITY_TYPE_EDDSA
EDDSA identity.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_raw(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *data, size_t size, struct GNUNET_CRYPTO_EddsaSignature *sig)
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_HANDLER_END
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
@ MHD_HTTP_NO_CONTENT
No Content [RFC7231, Section 6.3.5].
Common type definitions for the identity service and API.
static struct EgoEntry * ego_tail
Ego list.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
void ego_sign_data(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
void ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request - responds with all identities.
void ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
static void do_finished(void *cls, enum GNUNET_ErrorCode ec)
Processing finished.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
void * libgnunet_plugin_rest_identity_done(void *cls)
Exit point from the plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
void ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with name.
#define ID_REST_STATE_INIT
State while collecting all egos.
void * libgnunet_plugin_rest_identity_init(void *cls)
Entry point for the plugin.
static struct RequestHandle * requests_head
DLL.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
static enum GNUNET_GenericReturnValue rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static void do_finished_create(void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, enum GNUNET_ErrorCode ec)
Processing finished, when creating an ego.
#define GNUNET_REST_API_NS_SIGN
Identity Namespace with sign specifier.
static int state
The processing state.
static struct EgoEntry * ego_head
Ego list.
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.
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,...
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
static char * allow_methods
HTTP methods allows for this plugin.
void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.
void ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
static struct RequestHandle * requests_tail
DLL.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
void ego_sign_data_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
#define ID_REST_STATE_POST_INIT
Done collecting egos.
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public key.
void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
static void do_error(void *cls)
Task run on errors.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
char * identifier
Ego Identifier.
struct EgoEntry * prev
DLL.
char * keystring
Public key string.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
void * cls
Closure for all of the callbacks.
an ECC signature using EdDSA.
struct GNUNET_IDENTITY_PrivateKey pk
The identity key pair.
Handle for an operation with the identity service.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.
An identity key as per LSD0001.
struct returned by the initialization function of the plugin
void * cls
The closure of the plugin.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
const char * data
The POST data.
const char * url
The url as string.
size_t data_size
The POST data size.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
enum GNUNET_ErrorCode ec
Error code.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
struct RequestHandle * prev
DLL.
size_t data_size
the length of the REST data
struct EgoEntry * ego_entry
IDENTITY Operation.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
void * proc_cls
The closure of the result processor.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
struct RequestHandle * next
DLL.
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
char * name
Name to look up.
const char * data
The data from the REST request.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
struct RequestHandle * handle