GNUnet  0.11.x
Data Structures | Macros | Functions
plugin_block_revocation.c File Reference
#include "platform.h"
#include "gnunet_signatures.h"
#include "gnunet_block_plugin.h"
#include "gnunet_block_group_lib.h"
#include "revocation.h"
#include "gnunet_revocation_service.h"
Include dependency graph for plugin_block_revocation.c:

Go to the source code of this file.

Data Structures

struct  InternalContext
 Context used inside the plugin. More...
 

Macros

#define DEBUG_REVOCATION   GNUNET_EXTRA_LOGGING
 
#define BLOOMFILTER_K   16
 Number of bits we set per entry in the bloomfilter. More...
 
#define REVOCATION_BF_SIZE   8
 How big is the BF we use for DHT blocks? More...
 

Functions

static struct GNUNET_BLOCK_Groupblock_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. More...
 
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. More...
 
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. More...
 
void * libgnunet_plugin_block_revocation_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_block_revocation_done (void *cls)
 Exit point from the plugin. More...
 

Macro Definition Documentation

◆ DEBUG_REVOCATION

#define DEBUG_REVOCATION   GNUNET_EXTRA_LOGGING

Definition at line 34 of file plugin_block_revocation.c.

◆ BLOOMFILTER_K

#define BLOOMFILTER_K   16

Number of bits we set per entry in the bloomfilter.

Do not change!

Definition at line 40 of file plugin_block_revocation.c.

Referenced by block_plugin_revocation_create_group().

◆ REVOCATION_BF_SIZE

#define REVOCATION_BF_SIZE   8

How big is the BF we use for DHT blocks?

Definition at line 46 of file plugin_block_revocation.c.

Referenced by block_plugin_revocation_create_group().

Function Documentation

◆ block_plugin_revocation_create_group()

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 
)
static

Create a new block group.

Parameters
ctxblock context in which the block group is created
typetype of the block for which we are creating the group
noncerandom value used to seed the group creation
raw_dataoptional serialized prior state of the group, NULL if unavailable/fresh
raw_data_sizenumber of bytes in raw_data, 0 if unavailable/fresh
vavariable arguments specific to type
Returns
block group handle, NULL if block groups are not supported by this type of block (this is not an error)

Definition at line 71 of file plugin_block_revocation.c.

References BLOOMFILTER_K, GNUNET_BLOCK_GROUP_bf_create(), GNUNET_BLOCK_GROUP_compute_bloomfilter_size(), GNUNET_break, and REVOCATION_BF_SIZE.

Referenced by libgnunet_plugin_block_revocation_init().

77 {
78  unsigned int bf_size;
79  const char *guard;
80 
81  guard = va_arg (va, const char *);
82  if (0 == strcmp (guard,
83  "seen-set-size"))
84  bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned
85  int),
87  else if (0 == strcmp (guard,
88  "filter-size"))
89  bf_size = va_arg (va, unsigned int);
90  else
91  {
92  GNUNET_break (0);
93  bf_size = REVOCATION_BF_SIZE;
94  }
95  GNUNET_break (NULL == va_arg (va, const char *));
96  return GNUNET_BLOCK_GROUP_bf_create (cls,
97  bf_size,
99  type,
100  nonce,
101  raw_data,
102  raw_data_size);
103 }
#define REVOCATION_BF_SIZE
How big is the BF we use for DHT blocks?
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:174
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...
#define BLOOMFILTER_K
Number of bits we set per entry in the bloomfilter.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_plugin_revocation_evaluate()

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 
)
static

Function called to validate a reply or a request.

For request evaluation, simply pass "NULL" for the reply_block.

Parameters
clsour struct InternalContext
ctxcontext
typeblock type
groupblock group to use
eocontrol flags
queryoriginal query (hash)
xqueryextrended query data (can be NULL, depending on type)
xquery_sizenumber of bytes in xquery
reply_blockresponse to validate
reply_block_sizenumber of bytes in reply block
Returns
characterization of result

Definition at line 123 of file plugin_block_revocation.c.

References GNUNET_BLOCK_EVALUATION_OK_DUPLICATE, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, GNUNET_BLOCK_EVALUATION_RESULT_INVALID, GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED, GNUNET_BLOCK_GROUP_bf_test_and_set(), GNUNET_break_op, GNUNET_CRYPTO_ecdsa_verify(), GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_REVOCATION_check_pow(), GNUNET_SIGNATURE_PURPOSE_REVOCATION, GNUNET_YES, InternalContext::matching_bits, RevokeMessage::proof_of_work, RevokeMessage::public_key, RevokeMessage::purpose, and RevokeMessage::signature.

Referenced by libgnunet_plugin_block_revocation_init().

133 {
134  struct InternalContext *ic = cls;
135  struct GNUNET_HashCode chash;
136  const struct RevokeMessage *rm = reply_block;
137 
138  if (NULL == reply_block)
140  if (reply_block_size != sizeof(*rm))
141  {
142  GNUNET_break_op (0);
144  }
145  if (GNUNET_YES !=
147  rm->proof_of_work,
148  ic->matching_bits))
149  {
150  GNUNET_break_op (0);
152  }
153  if (GNUNET_OK !=
155  &rm->purpose,
156  &rm->signature,
157  &rm->public_key))
158  {
159  GNUNET_break_op (0);
161  }
163  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
164  &chash);
165  if (GNUNET_YES ==
167  &chash))
170 }
Block does not match query (invalid result)
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature confirming revocation.
Definition: revocation.h:99
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:1045
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:105
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Revoke key.
Definition: revocation.h:79
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:48
uint64_t proof_of_work
Number that causes a hash collision with the public_key.
Definition: revocation.h:94
A 512-bit hashcode.
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
Specified block type not supported by this plugin.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
struct GNUNET_CRYPTO_EcdsaPublicKey public_key
Key to revoke.
Definition: revocation.h:110
#define GNUNET_YES
Definition: gnunet_common.h:77
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
Query is valid, no reply given.
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...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_plugin_revocation_get_key()

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 
)
static

Function called to obtain the key for a block.

Parameters
clsclosure
typeblock type
blockblock to get the key for
block_sizenumber of bytes in block
keyset to the key (query) for the given block
Returns
GNUNET_OK on success, GNUNET_SYSERR if type not supported (or if extracting a key from a block of this type does not work)

Definition at line 185 of file plugin_block_revocation.c.

References GNUNET_break_op, GNUNET_CRYPTO_hash(), GNUNET_OK, GNUNET_SYSERR, and RevokeMessage::public_key.

Referenced by libgnunet_plugin_block_revocation_init().

190 {
191  const struct RevokeMessage *rm = block;
192 
193  if (block_size != sizeof(*rm))
194  {
195  GNUNET_break_op (0);
196  return GNUNET_SYSERR;
197  }
199  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
200  key);
201  return GNUNET_OK;
202 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Revoke key.
Definition: revocation.h:79
#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:48
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
struct GNUNET_CRYPTO_EcdsaPublicKey public_key
Key to revoke.
Definition: revocation.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_block_revocation_init()

void* libgnunet_plugin_block_revocation_init ( void *  cls)

Entry point for the plugin.

Parameters
clsthe configuration to use

Definition at line 211 of file plugin_block_revocation.c.

References block_plugin_revocation_create_group(), block_plugin_revocation_evaluate(), block_plugin_revocation_get_key(), cfg, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_BLOCK_PluginFunctions::create_group, GNUNET_BLOCK_PluginFunctions::evaluate, GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_REVOCATION, GNUNET_CONFIGURATION_get_value_number(), GNUNET_new, GNUNET_OK, InternalContext::matching_bits, and GNUNET_BLOCK_PluginFunctions::types.

212 {
213  static enum GNUNET_BLOCK_Type types[] = {
215  GNUNET_BLOCK_TYPE_ANY /* end of list */
216  };
217  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
218  struct GNUNET_BLOCK_PluginFunctions *api;
219  struct InternalContext *ic;
220  unsigned long long matching_bits;
221 
222  if (GNUNET_OK !=
224  "REVOCATION",
225  "WORKBITS",
226  &matching_bits))
227  return NULL;
228 
233  api->types = types;
234  ic = GNUNET_new (struct InternalContext);
235  ic->matching_bits = (unsigned int) matching_bits;
236  api->cls = ic;
237  return api;
238 }
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.
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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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.
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.
Block type for a revocation message by which a key is revoked.
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
GNUNET_BLOCK_GroupCreateFunction create_group
Create a block group to process a bunch of blocks in a shared context (i.e.
GNUNET_BLOCK_GetKeyFunction get_key
Obtain the key for a given block (if possible).
configuration data
Definition: configuration.c:85
static unsigned long long matching_bits
Number of matching bits required for revocation.
void * cls
Closure for all of the callbacks.
Here is the call graph for this function:

◆ libgnunet_plugin_block_revocation_done()

void* libgnunet_plugin_block_revocation_done ( void *  cls)

Exit point from the plugin.

Definition at line 245 of file plugin_block_revocation.c.

References GNUNET_BLOCK_PluginFunctions::cls, and GNUNET_free.

246 {
247  struct GNUNET_BLOCK_PluginFunctions *api = cls;
248  struct InternalContext *ic = api->cls;
249 
250  GNUNET_free (ic);
251  GNUNET_free (api);
252  return NULL;
253 }
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.
void * cls
Closure for all of the callbacks.
#define GNUNET_free(ptr)
Wrapper around free.