GNUnet 0.22.2
plugin_block_revocation.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2017 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
27#include "platform.h"
28#include "gnunet_signatures.h"
29#include "gnunet_block_plugin.h"
32#include "../../service/revocation/revocation.h"
34
35#define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING
36
41{
42 unsigned int matching_bits;
44};
45
46
61 const struct GNUNET_HashCode *query,
62 const void *xquery,
63 size_t xquery_size)
64{
65 (void) cls;
66 (void) query;
67 (void) xquery;
69 {
70 GNUNET_break (0);
71 return GNUNET_SYSERR;
72 }
73 if (0 != xquery_size)
74 return GNUNET_NO;
75 return GNUNET_OK;
76}
77
78
91 const void *block,
92 size_t block_size)
93{
94 struct InternalContext *ic = cls;
95 const struct RevokeMessage *rm = block;
96 const struct GNUNET_GNSRECORD_PowP *pow
97 = (const struct GNUNET_GNSRECORD_PowP *) &rm[1];
99 size_t pklen;
100 size_t left;
101
103 {
104 GNUNET_break (0);
105 return GNUNET_SYSERR;
106 }
107 if (block_size < sizeof(*rm) + sizeof(*pow))
108 {
109 GNUNET_break_op (0);
110 return GNUNET_NO;
111 }
112 if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
113 {
114 GNUNET_break_op (0);
115 return GNUNET_NO;
116 }
117 left = block_size - sizeof (*rm) - sizeof (*pow);
118 if (GNUNET_SYSERR ==
120 left,
121 &pk,
122 &pklen))
123 {
124 GNUNET_break_op (0);
125 return GNUNET_NO;
126 }
127 if (0 == pklen)
128 {
129 GNUNET_break_op (0);
130 return GNUNET_NO;
131 }
132 if (GNUNET_YES !=
134 ic->matching_bits,
135 ic->epoch_duration))
136 {
137 GNUNET_break_op (0);
138 return GNUNET_NO;
139 }
140 return GNUNET_OK;
141}
142
143
162 void *cls,
164 struct GNUNET_BLOCK_Group *group,
165 const struct GNUNET_HashCode *query,
166 const void *xquery,
167 size_t xquery_size,
168 const void *reply_block,
169 size_t reply_block_size)
170{
171 (void) cls;
172 (void) group;
173 (void) query;
174 (void) xquery;
175 (void) xquery_size;
176 (void) reply_block;
177 (void) reply_block_size;
179 {
180 GNUNET_break (0);
182 }
184}
185
186
201 const void *block,
202 size_t block_size,
203 struct GNUNET_HashCode *key)
204{
205 const struct RevokeMessage *rm = block;
206 const struct GNUNET_GNSRECORD_PowP *pow
207 = (const struct GNUNET_GNSRECORD_PowP *) &rm[1];
209 size_t pklen;
210 size_t left;
211
213 {
214 GNUNET_break (0);
215 return GNUNET_SYSERR;
216 }
217 if (block_size < sizeof(*rm) + sizeof(*pow))
218 {
219 GNUNET_break_op (0);
220 return GNUNET_NO;
221 }
222 if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
223 {
224 GNUNET_break_op (0);
225 return GNUNET_NO;
226 }
227 left = block_size - sizeof (*rm) - sizeof (*pow);
229 left,
230 &pk,
231 &pklen))
232 {
233 GNUNET_break_op (0);
234 return GNUNET_NO;
235 }
236 if (0 == pklen)
237 {
238 GNUNET_break_op (0);
239 return GNUNET_NO;
240 }
241 GNUNET_CRYPTO_hash (&pow[1],
242 pklen,
243 key);
244 return GNUNET_OK;
245}
246
247void *
249
255void *
257{
258 static const enum GNUNET_BLOCK_Type types[] = {
260 GNUNET_BLOCK_TYPE_ANY /* end of list */
261 };
262 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
264 struct InternalContext *ic;
265 unsigned long long matching_bits;
267
268 if (GNUNET_OK !=
270 "REVOCATION",
271 "WORKBITS",
273 return NULL;
274 if (GNUNET_OK !=
276 "REVOCATION",
277 "EPOCH_DURATION",
279 return NULL;
280
286 api->create_group = NULL;
287 api->types = types;
288 ic = GNUNET_new (struct InternalContext);
289 ic->matching_bits = (unsigned int) matching_bits;
291 api->cls = ic;
292 return api;
293}
294
295void *
297
301void *
303{
304 struct GNUNET_BLOCK_PluginFunctions *api = cls;
305 struct InternalContext *ic = api->cls;
306
307 GNUNET_free (ic);
308 GNUNET_free (api);
309 return NULL;
310}
311
312
313/* end of plugin_block_revocation.c */
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned long long matching_bits
Number of matching bits required for revocation.
API for block plugins.
API that can be used to manipulate GNS record data.
API to perform and access key revocations.
GNUNET_BLOCK_ReplyEvaluationResult
Possible ways for how a block may relate to a query.
@ GNUNET_BLOCK_REPLY_OK_LAST
Last possible valid result.
@ GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED
Specified block type not supported by any plugin.
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.
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.
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_public_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PublicKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PublicKey from a compact buffer.
Definition: crypto_pkey.c:102
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
static enum GNUNET_GenericReturnValue block_plugin_revocation_check_query(void *cls, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size)
Function called to validate a query.
static enum GNUNET_BLOCK_ReplyEvaluationResult block_plugin_revocation_check_reply(void *cls, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size, const void *reply_block, size_t reply_block_size)
Function called to validate a reply to a request.
static enum GNUNET_GenericReturnValue block_plugin_revocation_get_key(void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key)
Function called to obtain the key for a block.
void * libgnunet_plugin_block_revocation_init(void *cls)
Entry point for the plugin.
void * libgnunet_plugin_block_revocation_done(void *cls)
Exit point from the plugin.
static enum GNUNET_GenericReturnValue block_plugin_revocation_check_block(void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
Function called to validate a block for storage.
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_REVOCATION
Block type for a revocation message by which a key is revoked.
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
Block group data.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
enum GNUNET_BLOCK_Type * types
0-terminated array of block types supported by this plugin.
GNUNET_BLOCK_QueryEvaluationFunction check_query
Check that a query is well-formed.
GNUNET_BLOCK_BlockEvaluationFunction check_block
Check that a block is well-formed.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
GNUNET_BLOCK_ReplyEvaluationFunction check_reply
Check that a reply block matches a query.
GNUNET_BLOCK_GroupCreateFunction create_group
Create a block group to process a bunch of blocks in a shared context (i.e.
void * cls
Closure for all of the callbacks.
An identity key as per LSD0001.
Struct for a proof of work as part of the revocation.
uint64_t pow[32]
The PoWs.
A 512-bit hashcode.
Time for relative time used by GNUnet, in microseconds.
Context used inside the plugin.
struct GNUNET_TIME_Relative epoch_duration
Revoke key.
Definition: revocation.h:80
uint32_t pow_size
Length of PoW with signature.
Definition: revocation.h:89