GNUnet  0.11.x
Data Structures | Functions | Variables
revocation_api.c File Reference

API to perform and access key revocations. More...

#include "platform.h"
#include "gnunet_revocation_service.h"
#include "gnunet_signatures.h"
#include "gnunet_protocols.h"
#include "revocation.h"
#include <inttypes.h>
Include dependency graph for revocation_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_REVOCATION_Query
 Handle for the key revocation query. More...
 
struct  BestPow
 Helper struct that holds a found pow nonce and the corresponding number of leading zeroes. More...
 
struct  GNUNET_REVOCATION_PowCalculationHandle
 The handle to a PoW calculation. More...
 
struct  GNUNET_REVOCATION_Handle
 Handle for the key revocation operation. More...
 

Functions

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 creation of the message queue. More...
 
static void handle_revocation_query_response (void *cls, const struct QueryResponseMessage *qrm)
 Handle response to our revocation query. More...
 
struct GNUNET_REVOCATION_QueryGNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_IDENTITY_PublicKey *key, GNUNET_REVOCATION_Callback func, void *func_cls)
 Check if a key was revoked. More...
 
void GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q)
 Cancel key revocation check. More...
 
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 creation of the message queue. More...
 
static void handle_revocation_response (void *cls, const struct RevocationResponseMessage *rrm)
 Handle response to our revocation query. More...
 
struct GNUNET_REVOCATION_HandleGNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_REVOCATION_PowP *pow, GNUNET_REVOCATION_Callback func, void *func_cls)
 Perform key revocation. More...
 
void GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
 Cancel key revocation. More...
 
static unsigned int count_leading_zeroes (const struct GNUNET_HashCode *hash)
 Count the leading zeroes in hash. More...
 
static unsigned int calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph)
 Calculate the average zeros in the pows. More...
 
enum GNUNET_GenericReturnValue check_signature_identity (const struct GNUNET_REVOCATION_PowP *pow, const struct GNUNET_IDENTITY_PublicKey *key)
 
enum GNUNET_GenericReturnValue check_signature (const struct GNUNET_REVOCATION_PowP *pow)
 
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, unsigned int difficulty, struct GNUNET_TIME_Relative epoch_duration)
 Check if the given proof-of-work is valid. More...
 
enum GNUNET_GenericReturnValue sign_pow_identity (const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
 
enum GNUNET_GenericReturnValue sign_pow (const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
 
void GNUNET_REVOCATION_pow_init (const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
 Initializes a fresh PoW computation. More...
 
struct GNUNET_REVOCATION_PowCalculationHandleGNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_PowP *pow, int epochs, unsigned int difficulty)
 Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty. More...
 
static int cmp_pow_value (const void *a, const void *b)
 Comparison function for quicksort. More...
 
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
 Calculate a key revocation valid for broadcasting for a number of epochs. More...
 
void GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
 Stop a PoW calculation. More...
 
size_t GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow)
 

Variables

static struct GNUNET_CRYPTO_PowSalt salt = { "GnsRevocationPow" }
 

Detailed Description

API to perform and access key revocations.

Author
Christian Grothoff

Definition in file revocation_api.c.

Function Documentation

◆ query_mq_error_handler()

static void query_mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_NSE_Handle *
errorerror code

Definition at line 118 of file revocation_api.c.

120 {
121  struct GNUNET_REVOCATION_Query *q = cls;
122 
124  "Revocation query MQ error\n");
125  q->func (q->func_cls,
126  GNUNET_SYSERR);
128 }
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
#define GNUNET_log(kind,...)
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q)
Cancel key revocation check.
Handle for the key revocation query.
void * func_cls
Closure for func.
GNUNET_REVOCATION_Callback func
Function to call with the result.

References GNUNET_REVOCATION_Query::func, GNUNET_REVOCATION_Query::func_cls, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_REVOCATION_query_cancel(), GNUNET_SYSERR, and q.

Referenced by GNUNET_REVOCATION_query().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_revocation_query_response()

static void handle_revocation_query_response ( void *  cls,
const struct QueryResponseMessage qrm 
)
static

Handle response to our revocation query.

Parameters
clsour struct GNUNET_REVOCATION_Query handle
qrmresponse we got

Definition at line 138 of file revocation_api.c.

140 {
141  struct GNUNET_REVOCATION_Query *q = cls;
142 
144  "Revocation query result: %d\n",
145  (uint32_t) ntohl (qrm->is_valid));
146  q->func (q->func_cls,
147  ntohl (qrm->is_valid));
149 }
@ GNUNET_ERROR_TYPE_DEBUG
uint32_t is_valid
GNUNET_NO if revoked, GNUNET_YES if valid.
Definition: revocation.h:69

References GNUNET_REVOCATION_Query::func, GNUNET_REVOCATION_Query::func_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_REVOCATION_query_cancel(), QueryResponseMessage::is_valid, and q.

Here is the call graph for this function:

◆ revocation_mq_error_handler()

static void revocation_mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_NSE_Handle *
errorerror code

Definition at line 250 of file revocation_api.c.

252 {
253  struct GNUNET_REVOCATION_Handle *h = cls;
254 
256  "Revocation MQ error\n");
257  h->func (h->func_cls,
258  GNUNET_SYSERR);
260 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
@ GNUNET_ERROR_TYPE_WARNING
void GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h)
Cancel key revocation.
Handle for the key revocation operation.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_REVOCATION_revoke_cancel(), GNUNET_SYSERR, and h.

Referenced by GNUNET_REVOCATION_revoke().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_revocation_response()

static void handle_revocation_response ( void *  cls,
const struct RevocationResponseMessage rrm 
)
static

Handle response to our revocation query.

Parameters
clsour struct GNUNET_REVOCATION_Handle handle
rrmresponse we got

Definition at line 270 of file revocation_api.c.

272 {
273  struct GNUNET_REVOCATION_Handle *h = cls;
274 
276  "Revocation transmission result: %d\n",
277  (uint32_t) ntohl (rrm->is_valid));
278  h->func (h->func_cls,
279  ntohl (rrm->is_valid));
281 }
uint32_t is_valid
GNUNET_NO if revocation failed for internal reasons (e.g.
Definition: revocation.h:110

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_REVOCATION_revoke_cancel(), h, and RevocationResponseMessage::is_valid.

Here is the call graph for this function:

◆ count_leading_zeroes()

static unsigned int count_leading_zeroes ( const struct GNUNET_HashCode hash)
static

Count the leading zeroes in hash.

Parameters
hashto count leading zeros in
Returns
the number of leading zero bits.

Definition at line 398 of file revocation_api.c.

399 {
400  unsigned int hash_count;
401  hash_count = 0;
402  while ((0 == GNUNET_CRYPTO_hash_get_bit_ltr (hash, hash_count)))
403  hash_count++;
404  return hash_count;
405 }
int GNUNET_CRYPTO_hash_get_bit_ltr(const struct GNUNET_HashCode *code, unsigned int bit)
Obtain a bit from a hashcode.
Definition: crypto_hash.c:171

References GNUNET_CRYPTO_hash_get_bit_ltr().

Here is the call graph for this function:

◆ calculate_score()

static unsigned int calculate_score ( const struct GNUNET_REVOCATION_PowCalculationHandle ph)
static

Calculate the average zeros in the pows.

Parameters
phthe PowHandle
Returns
the average number of zeroes.

Definition at line 415 of file revocation_api.c.

416 {
417  double sum = 0.0;
418  for (unsigned int j = 0; j<POW_COUNT; j++)
419  sum += ph->best[j].bits;
420  double avg = sum / POW_COUNT;
421  return avg;
422 }
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
#define POW_COUNT
The proof-of-work narrowing factor.

References ph, POW_COUNT, and consensus-simulation::sum.

◆ check_signature_identity()

enum GNUNET_GenericReturnValue check_signature_identity ( const struct GNUNET_REVOCATION_PowP pow,
const struct GNUNET_IDENTITY_PublicKey key 
)

Definition at line 415 of file revocation_api.c.

428 {
430  struct GNUNET_IDENTITY_Signature *sig;
431  const struct GNUNET_IDENTITY_PublicKey *pk;
432  size_t ksize;
433 
434  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
436 
437  spurp = GNUNET_malloc (sizeof (*spurp) + ksize);
438  spurp->timestamp = pow->timestamp;
440  spurp->purpose.size = htonl (sizeof(*spurp) + ksize);
442  (char*) &spurp[1],
443  ksize);
445  "Expected signature payload len: %u\n",
446  ntohl (spurp->purpose.size));
447  sig = (struct GNUNET_IDENTITY_Signature *) ((char*) &pow[1] + ksize);
448  if (GNUNET_OK !=
450  &spurp->purpose,
451  sig,
452  key))
453  {
454  return GNUNET_SYSERR;
455  }
456  return GNUNET_OK;
457 }
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
@ GNUNET_OK
Definition: gnunet_common.h:95
int GNUNET_IDENTITY_signature_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_IDENTITY_Signature *sig, const struct GNUNET_IDENTITY_PublicKey *pub)
Verify a given signature.
ssize_t GNUNET_IDENTITY_write_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
ssize_t GNUNET_IDENTITY_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:976
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
An identity key as per LSD0001.
An identity signature as per LSD0001.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
The signature object we use for the PoW.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The signature purpose.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.

◆ check_signature()

enum GNUNET_GenericReturnValue check_signature ( const struct GNUNET_REVOCATION_PowP pow)

Definition at line 415 of file revocation_api.c.

462 {
463  const struct GNUNET_IDENTITY_PublicKey *pk;
464 
465  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
466  return check_signature_identity (pow, pk);
467 }
enum GNUNET_GenericReturnValue check_signature_identity(const struct GNUNET_REVOCATION_PowP *pow, const struct GNUNET_IDENTITY_PublicKey *key)

◆ sign_pow_identity()

enum GNUNET_GenericReturnValue sign_pow_identity ( const struct GNUNET_IDENTITY_PrivateKey key,
struct GNUNET_REVOCATION_PowP pow 
)

Predate the validity period to prevent rejections due to unsynchronized clocks

Definition at line 415 of file revocation_api.c.

581 {
584  const struct GNUNET_IDENTITY_PublicKey *pk;
585  size_t ksize;
586  char *sig;
587 
594  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
597  rp = GNUNET_malloc (sizeof (*rp) + ksize);
598  rp->timestamp = pow->timestamp;
599  rp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
600  rp->purpose.size = htonl (sizeof(*rp) + ksize);
602  "Signature payload len: %u\n",
603  ntohl (rp->purpose.size));
605  ((char*) &rp[1]),
606  ksize);
607  sig = ((char*) &pow[1]) + ksize;
609  &rp->purpose,
610  (void*) sig);
611  if (result == GNUNET_SYSERR)
612  return GNUNET_NO;
613  else
614  return result;
615 }
static char * rp
Relying party.
static int result
Global testing status.
@ GNUNET_NO
Definition: gnunet_common.h:94
int GNUNET_IDENTITY_sign_(const struct GNUNET_IDENTITY_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_IDENTITY_Signature *sig)
Sign a given block.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
#define GNUNET_TIME_UNIT_WEEKS
One week.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:296
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
Time for absolute times used by GNUnet, in microseconds.

◆ sign_pow()

enum GNUNET_GenericReturnValue sign_pow ( const struct GNUNET_IDENTITY_PrivateKey key,
struct GNUNET_REVOCATION_PowP pow 
)

Definition at line 415 of file revocation_api.c.

621 {
623 
624  pk = (struct GNUNET_IDENTITY_PublicKey *) &pow[1];
626  return sign_pow_identity (key, pow);
627 }
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
enum GNUNET_GenericReturnValue sign_pow_identity(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)

Referenced by GNUNET_REVOCATION_pow_init().

Here is the caller graph for this function:

◆ cmp_pow_value()

static int cmp_pow_value ( const void *  a,
const void *  b 
)
static

Comparison function for quicksort.

Parameters
aleft element
bright element
Returns
a-b

Definition at line 683 of file revocation_api.c.

684 {
685  return (GNUNET_ntohll (*(uint64_t*) a) - GNUNET_ntohll (*(uint64_t*) b));
686 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53

References testconfigure::b, and GNUNET_ntohll().

Here is the call graph for this function:

Variable Documentation

◆ salt

struct GNUNET_CRYPTO_PowSalt salt = { "GnsRevocationPow" }
static

Definition at line 1 of file revocation_api.c.