31#include "../../service/identity/identity.h"
33#include "microhttpd.h"
40#define GNUNET_REST_API_NS_IDENTITY "/identity"
45#define GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey"
50#define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name"
55#define GNUNET_REST_API_NS_SIGN "/sign"
60#define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey"
65#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey"
70#define GNUNET_REST_IDENTITY_PARAM_NAME "name"
75#define GNUNET_REST_IDENTITY_PARAM_TYPE "type"
80#define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname"
85#define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name"
90#define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key"
95#define GNUNET_REST_ERROR_NO_DATA "No data"
100#define GNUNET_REST_ERROR_DATA_INVALID "Data invalid"
105#define ID_REST_STATE_INIT 0
110#define ID_REST_STATE_POST_INIT 1
279 if (NULL !=
handle->timeout_task)
282 handle->timeout_task = NULL;
305 struct MHD_Response *resp;
306 json_t *json_error = json_object ();
310 json_object_set_new (json_error,
"error",
312 json_object_set_new (json_error,
"error_code", json_integer (
handle->ec));
314 if (0 == response_code)
315 response_code = MHD_HTTP_OK;
316 response = json_dumps (json_error, 0);
320 "application/json"));
322 json_decref (json_error);
344 for (ego_entry =
ego_head; NULL != ego_entry;
345 ego_entry = ego_entry->
next)
354 for (ego_entry =
ego_head; NULL != ego_entry;
355 ego_entry = ego_entry->
next)
380 struct MHD_Response *resp;
387 json_root = json_array ();
389 for (ego_entry =
ego_head; NULL != ego_entry;
390 ego_entry = ego_entry->
next)
392 json_ego = json_object ();
393 json_object_set_new (json_ego,
399 handle->rest_handle->url_param_map, &
key))
403 json_object_set_new (json_ego,
405 json_string (privkey_str));
409 json_object_set_new (json_ego,
412 json_array_append (json_root, json_ego);
413 json_decref (json_ego);
416 result_str = json_dumps (json_root, 0);
421 "application/json"));
422 json_decref (json_root);
438 struct MHD_Response *resp;
444 json_ego = json_object ();
445 json_object_set_new (json_ego,
448 json_object_set_new (json_ego,
454 handle->rest_handle->url_param_map, &
key))
458 json_object_set_new (json_ego,
460 json_string (privkey_str));
464 result_str = json_dumps (json_ego, 0);
470 "application/json"));
471 json_decref (json_ego);
504 if (NULL == ego_entry)
542 if (NULL == ego_entry)
563 struct MHD_Response *resp;
574 if (0 !=
handle->success_code)
575 response_code =
handle->success_code;
577 response_code = MHD_HTTP_OK;
616 char term_data[
handle->data_size + 1];
620 if (0 >=
handle->data_size)
627 term_data[
handle->data_size] =
'\0';
629 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
641 json_state = json_unpack (data_js,
650 json_decref (data_js);
658 json_decref (data_js);
662 if (0 >= strlen (newname))
666 json_decref (data_js);
670 handle->success_code = MHD_HTTP_NO_CONTENT;
680 json_decref (data_js);
683 json_decref (data_js);
715 if (NULL == ego_entry)
753 if (NULL == ego_entry)
784 int json_unpack_state;
786 char term_data[
handle->data_size + 1];
794 if (0 >=
handle->data_size)
800 term_data[
handle->data_size] =
'\0';
802 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
807 json_decref (data_js);
810 json_unpack_state = 0;
813 json_unpack (data_js,
"{s:s, s?:s, s?:s}",
817 if (0 != json_unpack_state)
821 json_decref (data_js);
825 if ((NULL != egotype) && (0 == strcasecmp (egotype,
"EDDSA")))
831 json_decref (data_js);
837 json_decref (data_js);
854 json_decref (data_js);
855 handle->success_code = MHD_HTTP_CREATED;
892 if (NULL == ego_entry)
899 handle->success_code = MHD_HTTP_NO_CONTENT;
934 if (NULL == ego_entry)
941 handle->success_code = MHD_HTTP_NO_CONTENT;
961 struct MHD_Response *resp;
982 strlen ( (
char*)
data),
995 "{\"signature\": \"%s\"}",
1021 const char *username_key =
"user";
1022 const char *data_key =
"data";
1036 handle->rest_handle->url_param_map,
1037 &cache_key_username)) ||
1039 handle->rest_handle->url_param_map,
1048 handle->rest_handle->url_param_map,
1049 &cache_key_username);
1052 handle->rest_handle->url_param_map,
1078 struct MHD_Response *resp;
1084 "Access-Control-Allow-Methods",
1096 const char *identifier)
1109 "Called with NULL ego\n");
1117 ego_entry->
ego = ego;
1124 if (identifier != NULL)
1126 for (ego_entry =
ego_head; NULL != ego_entry;
1127 ego_entry = ego_entry->
next)
1129 if (ego_entry->
ego == ego)
1137 if (NULL == ego_entry)
1143 ego_entry->
ego = ego;
1153 for (ego_entry =
ego_head; NULL != ego_entry;
1154 ego_entry = ego_entry->
next)
1156 if (ego_entry->
ego == ego)
1159 if (NULL == ego_entry)
1198 { MHD_HTTP_METHOD_PUT,
1203 { MHD_HTTP_METHOD_DELETE,
1206 { MHD_HTTP_METHOD_DELETE,
1215 handle->proc_cls = proc_cls;
1217 handle->rest_handle = rest_handle;
1263 "%s, %s, %s, %s, %s",
1264 MHD_HTTP_METHOD_GET,
1265 MHD_HTTP_METHOD_POST,
1266 MHD_HTTP_METHOD_PUT,
1267 MHD_HTTP_METHOD_DELETE,
1268 MHD_HTTP_METHOD_OPTIONS);
1296 for (ego_entry =
ego_head; NULL != ego_entry;)
1298 ego_tmp = ego_entry;
1299 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.
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.
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".
static struct EgoEntry * ego_tail
Ego list.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
static void ego_sign_data(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
void REST_identity_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
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.
static void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
static void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
void * REST_identity_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
static void do_finished(void *cls, enum GNUNET_ErrorCode ec)
Processing finished.
static void ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
static void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.
static void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
#define ID_REST_STATE_INIT
State while collecting all egos.
#define GNUNET_REST_IDENTITY_PARAM_TYPE
Parameter type.
static void ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request - responds with all identities.
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 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 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 void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
static char * allow_methods
HTTP methods allows for this plugin.
static struct RequestHandle * requests_tail
DLL.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void ego_sign_data_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
static 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_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.
static void do_error(void *cls)
Task run on errors.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static void ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
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 * name
Plugin name.
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.
unsigned int success_code
Success http status code.
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