GNUnet 0.21.0
revocation_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2016 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 */
25#include "platform.h"
27#include "gnunet_signatures.h"
28#include "gnunet_protocols.h"
29#include "revocation.h"
30#include <inttypes.h>
31
36{
41
46
50 void *func_cls;
51};
52
53
63static void
65 enum GNUNET_MQ_Error error)
66{
67 struct GNUNET_REVOCATION_Query *q = cls;
68
70 "Revocation query MQ error\n");
71 q->func (q->func_cls,
74}
75
76
83static void
85 const struct QueryResponseMessage *qrm)
86{
87 struct GNUNET_REVOCATION_Query *q = cls;
88
90 "Revocation query result: %d\n",
91 (uint32_t) ntohl (qrm->is_valid));
92 q->func (q->func_cls,
93 ntohl (qrm->is_valid));
95}
96
97
109 const struct GNUNET_CRYPTO_PublicKey *key,
111 void *func_cls)
112{
116 GNUNET_MQ_hd_fixed_size (revocation_query_response,
119 q),
121 };
122 struct QueryMessage *qm;
123 struct GNUNET_MQ_Envelope *env;
124 size_t key_len;
125
127 "revocation",
128 handlers,
130 q);
131 if (NULL == q->mq)
132 {
133 GNUNET_free (q);
134 return NULL;
135 }
136 q->func = func;
137 q->func_cls = func_cls;
139 env = GNUNET_MQ_msg_extra (qm, key_len,
142 qm->key_len = htonl (key_len);
144 env);
145 return q;
146}
147
148
154void
156{
157 if (NULL != q->mq)
158 {
160 q->mq = NULL;
161 }
162 GNUNET_free (q);
163}
164
165
170{
175
180
184 void *func_cls;
185};
186
187
197static void
199 enum GNUNET_MQ_Error error)
200{
201 struct GNUNET_REVOCATION_Handle *h = cls;
202
204 "Revocation MQ error\n");
205 h->func (h->func_cls,
208}
209
210
217static void
219 const struct RevocationResponseMessage *rrm)
220{
221 struct GNUNET_REVOCATION_Handle *h = cls;
222
224 "Revocation transmission result: %d\n",
225 (uint32_t) ntohl (rrm->is_valid));
226 h->func (h->func_cls,
227 ntohl (rrm->is_valid));
229}
230
231
250 const struct GNUNET_GNSRECORD_PowP *pow,
252 void *func_cls)
253{
257 GNUNET_MQ_hd_fixed_size (revocation_response,
260 h),
262 };
263 unsigned long long matching_bits;
265 struct RevokeMessage *rm;
266 struct GNUNET_MQ_Envelope *env;
267
268 if ((GNUNET_OK !=
270 "REVOCATION",
271 "WORKBITS",
272 &matching_bits)))
273 {
274 GNUNET_break (0);
275 GNUNET_free (h);
276 return NULL;
277 }
278 if ((GNUNET_OK !=
280 "REVOCATION",
281 "EPOCH_DURATION",
283 {
284 GNUNET_break (0);
285 GNUNET_free (h);
286 return NULL;
287 }
289 (unsigned int) matching_bits,
291 {
292 GNUNET_break (0);
293 GNUNET_free (h);
294 return NULL;
295 }
296
297
299 "revocation",
300 handlers,
302 h);
303 if (NULL == h->mq)
304 {
305 GNUNET_free (h);
306 return NULL;
307 }
308 h->func = func;
309 h->func_cls = func_cls;
310 size_t extra_len = GNUNET_GNSRECORD_proof_get_size (pow);
312 extra_len,
314 rm->pow_size = htonl (extra_len);
315 memcpy (&rm[1], pow, extra_len);
317 env);
318 return h;
319}
320
321
322void
324{
325 if (NULL != h->mq)
326 {
328 h->mq = NULL;
329 }
330 GNUNET_free (h);
331}
332
333
334/* end of revocation_api.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned long long matching_bits
Number of matching bits required for revocation.
Constants for network protocols.
API to perform and access key revocations.
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
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
size_t GNUNET_GNSRECORD_proof_get_size(const struct GNUNET_GNSRECORD_PowP *pow)
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_check_pow(const struct GNUNET_GNSRECORD_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:68
#define GNUNET_log(kind,...)
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
Definition: crypto_pkey.c:128
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#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_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_fixed_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_REVOCATION_QUERY
Client to service: was this key revoked?
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
Client to service OR peer-to-peer: revoke this key!
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE
Service to client: revocation confirmed.
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE
Service to client: answer if key was revoked!
struct GNUNET_REVOCATION_Handle * GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_GNSRECORD_PowP *pow, GNUNET_REVOCATION_Callback func, void *func_cls)
Perform key revocation.
void GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q)
Cancel key revocation check.
void GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h)
Cancel key revocation.
struct GNUNET_REVOCATION_Query * GNUNET_REVOCATION_query(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_PublicKey *key, GNUNET_REVOCATION_Callback func, void *func_cls)
Check if a key was revoked.
void(* GNUNET_REVOCATION_Callback)(void *cls, enum GNUNET_GenericReturnValue is_valid)
Callback to call with the result of a key revocation query.
messages for key revocation
static void query_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 revocation_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_revocation_query_response(void *cls, const struct QueryResponseMessage *qrm)
Handle response to our revocation query.
static void handle_revocation_response(void *cls, const struct RevocationResponseMessage *rrm)
Handle response to our revocation query.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
An identity key as per LSD0001.
Struct for a proof of work as part of the revocation.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Handle for the key revocation operation.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
GNUNET_REVOCATION_Callback func
Function to call once we are done.
void * func_cls
Closure for func.
Handle for the key revocation query.
void * func_cls
Closure for func.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
GNUNET_REVOCATION_Callback func
Function to call with the result.
Time for relative time used by GNUnet, in microseconds.
Query key revocation status.
Definition: revocation.h:38
uint32_t key_len
Key length.
Definition: revocation.h:47
Key revocation response.
Definition: revocation.h:59
uint32_t is_valid
GNUNET_NO if revoked, GNUNET_YES if valid.
Definition: revocation.h:68
Key revocation response.
Definition: revocation.h:99
uint32_t is_valid
GNUNET_NO if revocation failed for internal reasons (e.g.
Definition: revocation.h:109
Revoke key.
Definition: revocation.h:80
uint32_t pow_size
Length of PoW with signature.
Definition: revocation.h:89