GNUnet  0.10.x
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 #define BLOOMFILTER_K 16
41 
42 
46 #define REVOCATION_BF_SIZE 8
47 
48 
53 {
54 
55  unsigned int matching_bits;
56 
57 };
58 
59 
72 static struct GNUNET_BLOCK_Group *
75  uint32_t nonce,
76  const void *raw_data,
77  size_t raw_data_size,
78  va_list va)
79 {
80  unsigned int bf_size;
81  const char *guard;
82 
83  guard = va_arg (va, const char *);
84  if (0 == strcmp (guard,
85  "seen-set-size"))
86  bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
88  else if (0 == strcmp (guard,
89  "filter-size"))
90  bf_size = va_arg (va, unsigned int);
91  else
92  {
93  GNUNET_break (0);
94  bf_size = REVOCATION_BF_SIZE;
95  }
96  GNUNET_break (NULL == va_arg (va, const char *));
97  return GNUNET_BLOCK_GROUP_bf_create (cls,
98  bf_size,
100  type,
101  nonce,
102  raw_data,
103  raw_data_size);
104 }
105 
106 
125  struct GNUNET_BLOCK_Context *ctx,
126  enum GNUNET_BLOCK_Type type,
127  struct GNUNET_BLOCK_Group *group,
129  const struct GNUNET_HashCode *query,
130  const void *xquery,
131  size_t xquery_size,
132  const void *reply_block,
133  size_t reply_block_size)
134 {
135  struct InternalContext *ic = cls;
136  struct GNUNET_HashCode chash;
137  const struct RevokeMessage *rm = reply_block;
138 
139  if (NULL == reply_block)
141  if (reply_block_size != sizeof (*rm))
142  {
143  GNUNET_break_op (0);
145  }
146  if (GNUNET_YES !=
148  rm->proof_of_work,
149  ic->matching_bits))
150  {
151  GNUNET_break_op (0);
153  }
154  if (GNUNET_OK !=
156  &rm->purpose,
157  &rm->signature,
158  &rm->public_key))
159  {
160  GNUNET_break_op (0);
162  }
164  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
165  &chash);
166  if (GNUNET_YES ==
168  &chash))
171 }
172 
173 
185 static int
187  enum GNUNET_BLOCK_Type type,
188  const void *block,
189  size_t block_size,
190  struct GNUNET_HashCode *key)
191 {
192  const struct RevokeMessage *rm = block;
193 
194  if (block_size != sizeof (*rm))
195  {
196  GNUNET_break_op (0);
197  return GNUNET_SYSERR;
198  }
200  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
201  key);
202  return GNUNET_OK;
203 }
204 
205 
211 void *
213 {
214  static enum GNUNET_BLOCK_Type types[] =
215  {
217  GNUNET_BLOCK_TYPE_ANY /* end of list */
218  };
219  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
220  struct GNUNET_BLOCK_PluginFunctions *api;
221  struct InternalContext *ic;
222  unsigned long long matching_bits;
223 
224  if (GNUNET_OK !=
226  "REVOCATION",
227  "WORKBITS",
228  &matching_bits))
229  return NULL;
230 
235  api->types = types;
236  ic = GNUNET_new (struct InternalContext);
237  ic->matching_bits = (unsigned int) matching_bits;
238  api->cls = ic;
239  return api;
240 }
241 
242 
246 void *
248 {
249  struct GNUNET_BLOCK_PluginFunctions *api = cls;
250  struct InternalContext *ic = api->cls;
251 
252  GNUNET_free (ic);
253  GNUNET_free (api);
254  return NULL;
255 }
256 
257 /* end of plugin_block_revocation.c */
Block does not match query (invalid result)
static struct GNUNET_BLOCK_Group * block_plugin_revocation_create_group(void *cls, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size, va_list va)
Create a new block group.
Handle to an initialized block library.
Definition: block.c:54
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature confirming revocation.
Definition: revocation.h:101
int 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.
void * libgnunet_plugin_block_revocation_init(void *cls)
Entry point for the plugin.
enum GNUNET_BLOCK_Type * types
0-terminated array of block types supported by this plugin.
Any type of block, used as a wildcard when searching.
int GNUNET_CRYPTO_ecdsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:1048
static enum GNUNET_BLOCK_EvaluationResult block_plugin_revocation_evaluate(void *cls, struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, enum GNUNET_BLOCK_EvaluationOptions eo, 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 or a request.
GNUNET_BLOCK_EvaluationFunction evaluate
Main function of a block plugin.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
#define REVOCATION_BF_SIZE
How big is the BF we use for DHT blocks?
Block type for a revocation message by which a key is revoked.
struct GNUNET_BLOCK_Group * GNUNET_BLOCK_GROUP_bf_create(void *cls, size_t bf_size, unsigned int bf_k, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size)
Create a new block group that filters duplicates using a Bloom filter.
Definition: bg_bf.c:175
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Context used inside the plugin.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Must have purpose GNUNET_SIGNATURE_PURPOSE_REVOCATION, size expands over the public key...
Definition: revocation.h:107
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
size_t GNUNET_BLOCK_GROUP_compute_bloomfilter_size(unsigned int entry_count, unsigned int k)
How many bytes should a bloomfilter be if we have already seen entry_count responses? Sized so that do not have to re-size the filter too often (to keep it cheap).
Definition: bg_bf.c:250
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static int 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.
Revoke key.
Definition: revocation.h:81
Valid result, but suppressed because it is a duplicate.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
messages for key revocation
uint64_t proof_of_work
Number that causes a hash collision with the public_key.
Definition: revocation.h:96
A 512-bit hashcode.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
GNUNET_BLOCK_GroupCreateFunction create_group
Create a block group to process a bunch of blocks in a shared context (i.e.
void * libgnunet_plugin_block_revocation_done(void *cls)
Exit point from the plugin.
GNUNET_BLOCK_EvaluationResult
Possible ways for how a block may relate to a query.
Specified block type not supported by this plugin.
#define BLOOMFILTER_K
Number of bits we set per entry in the bloomfilter.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
configuration data
Definition: configuration.c:85
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Block group data.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_CRYPTO_EcdsaPublicKey public_key
Key to revoke.
Definition: revocation.h:112
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_BLOCK_GROUP_bf_test_and_set(struct GNUNET_BLOCK_Group *bg, const struct GNUNET_HashCode *hc)
Test if hc is contained in the Bloom filter of bg.
Definition: bg_bf.c:214
void * cls
Closure for all of the callbacks.
GNUNET_BLOCK_EvaluationOptions
Flags that can be set to control the evaluation.
Query is valid, no reply given.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_REVOCATION_check_pow(const struct GNUNET_CRYPTO_EcdsaPublicKey *key, uint64_t pow, unsigned int matching_bits)
Check if the given proof-of-work value would be acceptable for revoking the given key...