GNUnet 0.21.2
identity_api_lookup.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_util_lib.h"
29#include "identity.h"
30
31#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__)
32
33
38{
43
47 char *name;
48
53
57 void *cb_cls;
58};
59
60
69static int
70check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
71{
72 if (sizeof(*rcm) != htons (rcm->header.size))
74 return GNUNET_OK;
75}
76
77
84static void
85handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
86{
87 struct GNUNET_IDENTITY_EgoLookup *el = cls;
88
89 el->cb (el->cb_cls, NULL);
91}
92
93
101static int
102check_identity_update (void *cls, const struct UpdateMessage *um)
103{
104 uint16_t size = ntohs (um->header.size);
105 uint16_t name_len = ntohs (um->name_len);
106 const char *str = (const char *) &um[1];
107
108 if ((size < name_len + sizeof(struct UpdateMessage)) ||
109 ((0 != name_len) && ('\0' != str[name_len - 1])))
110 {
111 GNUNET_break (0);
112 return GNUNET_SYSERR;
113 }
114 return GNUNET_OK;
115}
116
117
124static void
125handle_identity_update (void *cls, const struct UpdateMessage *um)
126{
127 struct GNUNET_IDENTITY_EgoLookup *el = cls;
128 uint16_t name_len = ntohs (um->name_len);
129 const char *str;
130 size_t key_len;
131 size_t kb_read;
132 struct GNUNET_HashCode id;
133 struct GNUNET_IDENTITY_Ego ego;
134 struct GNUNET_CRYPTO_PrivateKey private_key;
135 const char *tmp;
136
137 memset (&ego, 0, sizeof (ego));
138
139 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
140 tmp = (const char*) &um[1];
141 str = (0 == name_len) ? NULL : tmp;
142 memset (&private_key, 0, sizeof (private_key));
143 key_len = ntohs (um->header.size) - sizeof (*um) - name_len;
146 key_len,
147 &private_key,
148 &kb_read));
149 GNUNET_assert (key_len == kb_read);
150 GNUNET_CRYPTO_hash (&private_key, sizeof (private_key), &id);
151 ego.pk = private_key;
152 ego.name = (char *) str;
153 ego.id = id;
154 el->cb (el->cb_cls, &ego);
156}
157
158
167static void
168mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
169{
170 struct GNUNET_IDENTITY_EgoLookup *el = cls;
171
172 el->cb (el->cb_cls, NULL);
173}
174
175
187 const char *name,
189 void *cb_cls)
190{
192 struct GNUNET_MQ_Envelope *env;
193 struct GNUNET_MessageHeader *req;
194 size_t nlen;
195
196 GNUNET_assert (NULL != cb);
198 el->cb = cb;
199 el->cb_cls = cb_cls;
200 {
202 { GNUNET_MQ_hd_var_size (identity_result_code,
204 struct ResultCodeMessage,
205 el),
206 GNUNET_MQ_hd_var_size (identity_update,
208 struct UpdateMessage,
209 el),
211
212 el->mq =
214 }
215 if (NULL == el->mq)
216 {
217 GNUNET_break (0);
218 GNUNET_free (el);
219 return NULL;
220 }
222 nlen = strlen (name) + 1;
224 memcpy (&req[1], name, nlen);
226 return el;
227}
228
229
235void
237{
240 GNUNET_free (el);
241}
242
243
244/* end of identity_api_lookup.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static char * name
Name (label) of the records to list.
static struct GNUNET_IDENTITY_EgoLookup * el
Handle to identity lookup.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
Identity service; implements identity management for GNUnet.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
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.
void GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
Abort ego lookup attempt.
void(* GNUNET_IDENTITY_EgoCallback)(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Function called with the result.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PrivateKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer.
Definition: crypto_pkey.c:163
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#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.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP
First message send from identity client to service to lookup a single ego.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
Generic response from identity service with success and/or error message.
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
Common type definitions for the identity service and API.
static void handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
We received a result code from the service.
static int check_identity_update(void *cls, const struct UpdateMessage *um)
Check validity of identity update message.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void handle_identity_update(void *cls, const struct UpdateMessage *um)
Handle identity update message.
static int check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
We received a result code from the service.
static unsigned int size
Size of the "table".
Definition: peer.c:68
A private key for an identity as per LSD0001.
A 512-bit hashcode.
Handle for ego lookup.
struct GNUNET_MQ_Handle * mq
Connection to service.
void * cb_cls
Closure for cb.
char * name
Name of the ego we are looking up.
GNUNET_IDENTITY_EgoCallback cb
Function to call with the result.
Handle for an ego.
Definition: identity.h:37
char * name
Current name associated with this ego.
Definition: identity.h:56
struct GNUNET_CRYPTO_PrivateKey pk
The identity key pair.
Definition: identity.h:51
struct GNUNET_HashCode id
Hash of the private key of this ego.
Definition: identity.h:41
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Definition: identity.h:81
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE.
Definition: identity.h:85
Service informs client about status of a pseudonym.
Definition: identity.h:114
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:129
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted.
Definition: identity.h:124
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:118