GNUnet  0.20.0
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"
30 #include "gnunet_block_group_lib.h"
31 #include "revocation.h"
33 
34 #define DEBUG_REVOCATION GNUNET_EXTRA_LOGGING
35 
40 {
41  unsigned int matching_bits;
43 };
44 
45 
57 static enum GNUNET_GenericReturnValue
60  const struct GNUNET_HashCode *query,
61  const void *xquery,
62  size_t xquery_size)
63 {
64  (void) cls;
65  (void) query;
66  (void) xquery;
68  {
69  GNUNET_break (0);
70  return GNUNET_SYSERR;
71  }
72  if (0 != xquery_size)
73  return GNUNET_NO;
74  return GNUNET_OK;
75 }
76 
77 
87 static enum GNUNET_GenericReturnValue
90  const void *block,
91  size_t block_size)
92 {
93  struct InternalContext *ic = cls;
94  const struct RevokeMessage *rm = block;
95  const struct GNUNET_REVOCATION_PowP *pow
96  = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
98  size_t pklen;
99  size_t left;
100 
102  {
103  GNUNET_break (0);
104  return GNUNET_SYSERR;
105  }
106  if (block_size < sizeof(*rm) + sizeof(*pow))
107  {
108  GNUNET_break_op (0);
109  return GNUNET_NO;
110  }
111  if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
112  {
113  GNUNET_break_op (0);
114  return GNUNET_NO;
115  }
116  left = block_size - sizeof (*rm) - sizeof (*pow);
117  if (GNUNET_SYSERR ==
119  left,
120  &pk,
121  &pklen))
122  {
123  GNUNET_break_op (0);
124  return GNUNET_NO;
125  }
126  if (0 == pklen)
127  {
128  GNUNET_break_op (0);
129  return GNUNET_NO;
130  }
131  if (GNUNET_YES !=
133  ic->matching_bits,
134  ic->epoch_duration))
135  {
136  GNUNET_break_op (0);
137  return GNUNET_NO;
138  }
139  return GNUNET_OK;
140 }
141 
142 
161  void *cls,
162  enum GNUNET_BLOCK_Type type,
163  struct GNUNET_BLOCK_Group *group,
164  const struct GNUNET_HashCode *query,
165  const void *xquery,
166  size_t xquery_size,
167  const void *reply_block,
168  size_t reply_block_size)
169 {
170  (void) cls;
171  (void) group;
172  (void) query;
173  (void) xquery;
174  (void) xquery_size;
175  (void) reply_block;
176  (void) reply_block_size;
178  {
179  GNUNET_break (0);
181  }
183 }
184 
185 
197 static enum GNUNET_GenericReturnValue
199  enum GNUNET_BLOCK_Type type,
200  const void *block,
201  size_t block_size,
202  struct GNUNET_HashCode *key)
203 {
204  const struct RevokeMessage *rm = block;
205  const struct GNUNET_REVOCATION_PowP *pow
206  = (const struct GNUNET_REVOCATION_PowP *) &rm[1];
208  size_t pklen;
209  size_t left;
210 
212  {
213  GNUNET_break (0);
214  return GNUNET_SYSERR;
215  }
216  if (block_size < sizeof(*rm) + sizeof(*pow))
217  {
218  GNUNET_break_op (0);
219  return GNUNET_NO;
220  }
221  if (block_size != sizeof(*rm) + ntohl (rm->pow_size))
222  {
223  GNUNET_break_op (0);
224  return GNUNET_NO;
225  }
226  left = block_size - sizeof (*rm) - sizeof (*pow);
228  left,
229  &pk,
230  &pklen))
231  {
232  GNUNET_break_op (0);
233  return GNUNET_NO;
234  }
235  if (0 == pklen)
236  {
237  GNUNET_break_op (0);
238  return GNUNET_NO;
239  }
240  GNUNET_CRYPTO_hash (&pow[1],
241  pklen,
242  key);
243  return GNUNET_OK;
244 }
245 
246 
252 void *
254 {
255  static const enum GNUNET_BLOCK_Type types[] = {
257  GNUNET_BLOCK_TYPE_ANY /* end of list */
258  };
259  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
260  struct GNUNET_BLOCK_PluginFunctions *api;
261  struct InternalContext *ic;
262  unsigned long long matching_bits;
264 
265  if (GNUNET_OK !=
267  "REVOCATION",
268  "WORKBITS",
269  &matching_bits))
270  return NULL;
271  if (GNUNET_OK !=
273  "REVOCATION",
274  "EPOCH_DURATION",
275  &epoch_duration))
276  return NULL;
277 
283  api->create_group = NULL;
284  api->types = types;
285  ic = GNUNET_new (struct InternalContext);
286  ic->matching_bits = (unsigned int) matching_bits;
288  api->cls = ic;
289  return api;
290 }
291 
292 
296 void *
298 {
299  struct GNUNET_BLOCK_PluginFunctions *api = cls;
300  struct InternalContext *ic = api->cls;
301 
302  GNUNET_free (ic);
303  GNUNET_free (api);
304  return NULL;
305 }
306 
307 
308 /* end of plugin_block_revocation.c */
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
@ GNUNET_BLOCK_TYPE_REVOCATION
Block type for a revocation message by which a key is revoked.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
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 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.
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_IDENTITY_read_public_key_from_buffer(const void *buffer, size_t len, struct GNUNET_IDENTITY_PublicKey *key, size_t *kb_read)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
Definition: identity_api.c:865
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.
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow(const struct GNUNET_REVOCATION_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
void * libgnunet_plugin_block_revocation_done(void *cls)
Exit point from the plugin.
void * libgnunet_plugin_block_revocation_init(void *cls)
Entry point for the plugin.
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.
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.
messages for key revocation
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.
A 512-bit hashcode.
An identity key as per LSD0001.
Struct for a proof of work as part of the revocation.
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
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model