31#include "../../service/identity/identity.h"
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_TYPE "type"
79#define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname"
84#define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name"
89#define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key"
94#define GNUNET_REST_ERROR_NO_DATA "No data"
99#define GNUNET_REST_ERROR_DATA_INVALID "Data invalid"
104#define ID_REST_STATE_INIT 0
109#define ID_REST_STATE_POST_INIT 1
271 if (NULL !=
handle->timeout_task)
274 handle->timeout_task = NULL;
297 struct MHD_Response *resp;
298 json_t *json_error = json_object ();
302 json_object_set_new (json_error,
"error",
304 json_object_set_new (json_error,
"error_code", json_integer (
handle->ec));
306 if (0 == response_code)
308 response = json_dumps (json_error, 0);
312 "application/json"));
314 json_decref (json_error);
336 for (ego_entry =
ego_head; NULL != ego_entry;
337 ego_entry = ego_entry->
next)
346 for (ego_entry =
ego_head; NULL != ego_entry;
347 ego_entry = ego_entry->
next)
372 struct MHD_Response *resp;
379 json_root = json_array ();
381 for (ego_entry =
ego_head; NULL != ego_entry;
382 ego_entry = ego_entry->
next)
384 json_ego = json_object ();
385 json_object_set_new (json_ego,
391 handle->rest_handle->url_param_map, &
key))
395 json_object_set_new (json_ego,
397 json_string (privkey_str));
401 json_object_set_new (json_ego,
404 json_array_append (json_root, json_ego);
405 json_decref (json_ego);
408 result_str = json_dumps (json_root, 0);
413 "application/json"));
414 json_decref (json_root);
430 struct MHD_Response *resp;
436 json_ego = json_object ();
437 json_object_set_new (json_ego,
440 json_object_set_new (json_ego,
446 handle->rest_handle->url_param_map, &
key))
450 json_object_set_new (json_ego,
452 json_string (privkey_str));
456 result_str = json_dumps (json_ego, 0);
462 "application/json"));
463 json_decref (json_ego);
496 if (NULL == ego_entry)
534 if (NULL == ego_entry)
555 struct MHD_Response *resp;
606 char term_data[
handle->data_size + 1];
610 if (0 >=
handle->data_size)
617 term_data[
handle->data_size] =
'\0';
619 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
631 json_state = json_unpack (data_js,
640 json_decref (data_js);
648 json_decref (data_js);
652 if (0 >= strlen (newname))
656 json_decref (data_js);
669 json_decref (data_js);
672 json_decref (data_js);
704 if (NULL == ego_entry)
742 if (NULL == ego_entry)
773 int json_unpack_state;
774 char term_data[
handle->data_size + 1];
782 if (0 >=
handle->data_size)
788 term_data[
handle->data_size] =
'\0';
790 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
795 json_decref (data_js);
798 json_unpack_state = 0;
801 json_unpack (data_js,
"{s:s, s?:s, s?:s}",
805 if (0 != json_unpack_state)
809 json_decref (data_js);
813 if ((NULL != egotype) && (0 == strcasecmp (egotype,
"EDDSA")))
819 json_decref (data_js);
825 json_decref (data_js);
842 json_decref (data_js);
879 if (NULL == ego_entry)
920 if (NULL == ego_entry)
946 struct MHD_Response *resp;
967 strlen ( (
char*)
data),
980 "{\"signature\": \"%s\"}",
1006 const char *username_key =
"user";
1007 const char *data_key =
"data";
1021 handle->rest_handle->url_param_map,
1022 &cache_key_username)) ||
1024 handle->rest_handle->url_param_map,
1033 handle->rest_handle->url_param_map,
1034 &cache_key_username);
1037 handle->rest_handle->url_param_map,
1063 struct MHD_Response *resp;
1069 "Access-Control-Allow-Methods",
1081 const char *identifier)
1094 "Called with NULL ego\n");
1102 ego_entry->
ego = ego;
1109 if (identifier != NULL)
1111 for (ego_entry =
ego_head; NULL != ego_entry;
1112 ego_entry = ego_entry->
next)
1114 if (ego_entry->
ego == ego)
1122 if (NULL == ego_entry)
1128 ego_entry->
ego = ego;
1138 for (ego_entry =
ego_head; NULL != ego_entry;
1139 ego_entry = ego_entry->
next)
1141 if (ego_entry->
ego == ego)
1144 if (NULL == ego_entry)
1183 { MHD_HTTP_METHOD_PUT,
1188 { MHD_HTTP_METHOD_DELETE,
1191 { MHD_HTTP_METHOD_DELETE,
1200 handle->proc_cls = proc_cls;
1202 handle->rest_handle = rest_handle;
1248 "%s, %s, %s, %s, %s",
1249 MHD_HTTP_METHOD_GET,
1250 MHD_HTTP_METHOD_POST,
1251 MHD_HTTP_METHOD_PUT,
1252 MHD_HTTP_METHOD_DELETE,
1253 MHD_HTTP_METHOD_OPTIONS);
1281 for (ego_entry =
ego_head; NULL != ego_entry;)
1283 ego_tmp = ego_entry;
1284 ego_entry = ego_entry->
next;
struct GNUNET_MQ_MessageHandlers handlers[]
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static struct MHD_Response * response
Our canonical response.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static char * egoname
Ego Attribute String.
static struct GNUNET_FS_Handle * ctx
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
static uint32_t type
Type string converted to DNS type value.
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
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.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *id, const char *name, const struct GNUNET_CRYPTO_PrivateKey *privkey, enum GNUNET_CRYPTO_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *id, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing ego.
const struct GNUNET_CRYPTO_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_delete(struct GNUNET_IDENTITY_Handle *id, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing ego.
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_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.
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_PublicKey *pk)
Get the identifier (public key) of an ego.
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,...)
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
char * GNUNET_CRYPTO_private_key_to_string(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates a (Base32) string representation of the private key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
#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.
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 MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
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].
static struct EgoEntry * ego_tail
Ego list.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
void REST_identity_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
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,...
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)
static void do_finished_create(void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
Processing finished, when creating an ego.
const struct GNUNET_CONFIGURATION_Handle * id_cfg
The configuration handle.
#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.
void * REST_identity_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void do_finished(void *cls, enum GNUNET_ErrorCode ec)
Processing finished.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
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.
#define GNUNET_REST_IDENTITY_PARAM_TYPE
Parameter type.
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.
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.
#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.
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.
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_INVALID
The given ego is invalid or malformed.
@ GNUNET_EC_UNKNOWN
Unknown and unspecified error.
@ GNUNET_EC_NONE
No error (success).
@ GNUNET_EC_IDENTITY_NOT_FOUND
Ego not found.
The default namestore ego.
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.
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 GNUNET_CRYPTO_PrivateKey pk
The identity key pair.
Handle for an operation with the identity service.
struct returned by the initialization function of the plugin
void * cls
The closure of the plugin.
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
Handle to rest request.
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