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.

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().

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 }
void GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q)
Cancel key revocation check.
void * func_cls
Closure for func.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
Handle for the key revocation query.
#define GNUNET_log(kind,...)
GNUNET_REVOCATION_Callback func
Function to call with the result.
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.

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.

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 }
void GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q)
Cancel key revocation check.
void * func_cls
Closure for func.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
uint32_t is_valid
GNUNET_NO if revoked, GNUNET_YES if valid.
Definition: revocation.h:69
Handle for the key revocation query.
#define GNUNET_log(kind,...)
GNUNET_REVOCATION_Callback func
Function to call with the result.
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.

References GNUNET_REVOCATION_Handle::func, GNUNET_REVOCATION_Handle::func_cls, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_REVOCATION_revoke_cancel(), GNUNET_SYSERR, and h.

Referenced by GNUNET_REVOCATION_revoke().

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
void * func_cls
Closure for func.
#define GNUNET_log(kind,...)
Handle for the key revocation operation.
GNUNET_REVOCATION_Callback func
Function to call once we are done.
void GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h)
Cancel key revocation.
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.

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

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 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void * func_cls
Closure for func.
#define GNUNET_log(kind,...)
Handle for the key revocation operation.
GNUNET_REVOCATION_Callback func
Function to call once we are done.
uint32_t is_valid
GNUNET_NO if revocation failed for internal reasons (e.g.
Definition: revocation.h:110
void GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h)
Cancel key revocation.
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.

References GNUNET_CRYPTO_hash_get_bit_ltr().

Referenced by GNUNET_REVOCATION_check_pow(), and GNUNET_REVOCATION_pow_round().

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
Here is the call graph for this function:
Here is the caller 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.

References GNUNET_REVOCATION_PowCalculationHandle::best, BestPow::bits, POW_COUNT, and consensus-simulation::sum.

Referenced by GNUNET_REVOCATION_pow_round().

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 }
#define POW_COUNT
The proof-of-work narrowing factor.
struct BestPow best[POW_COUNT]
Current set of found PoWs.
unsigned int bits
Corresponding zero bits in hash.
Here is the caller graph for this function:

◆ check_signature_identity()

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

Definition at line 426 of file revocation_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_key_get_length(), GNUNET_IDENTITY_signature_verify_(), GNUNET_IDENTITY_write_key_to_buffer(), GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_REVOCATION, GNUNET_SYSERR, pk, GNUNET_REVOCATION_SignaturePurposePS::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_REVOCATION_SignaturePurposePS::timestamp, and GNUNET_REVOCATION_PowP::timestamp.

Referenced by check_signature().

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];
435  ksize = GNUNET_IDENTITY_key_get_length (pk);
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 }
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.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
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
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.
The signature object we use for the PoW.
An identity signature as per LSD0001.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The signature purpose.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_signature()

enum GNUNET_GenericReturnValue check_signature ( const struct GNUNET_REVOCATION_PowP pow)

Definition at line 461 of file revocation_api.c.

References check_signature_identity(), and pk.

Referenced by GNUNET_REVOCATION_check_pow().

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)
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 579 of file revocation_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_key_get_length(), GNUNET_IDENTITY_sign_(), GNUNET_IDENTITY_write_key_to_buffer(), GNUNET_log, GNUNET_malloc, GNUNET_NO, GNUNET_SIGNATURE_PURPOSE_REVOCATION, GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_absolute_subtract(), GNUNET_TIME_UNIT_WEEKS, pk, GNUNET_REVOCATION_SignaturePurposePS::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, result, rp, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_REVOCATION_SignaturePurposePS::timestamp, and GNUNET_REVOCATION_PowP::timestamp.

Referenced by sign_pow().

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];
595  ksize = GNUNET_IDENTITY_key_get_length (pk);
597  rp = GNUNET_malloc (sizeof (*rp) + ksize);
598  rp->timestamp = pow->timestamp;
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;
608  int result = GNUNET_IDENTITY_sign_ (key,
609  &rp->purpose,
610  (void*) sig);
611  if (result == GNUNET_SYSERR)
612  return GNUNET_NO;
613  else
614  return result;
615 }
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 timestamp
The timestamp of the revocation.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
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
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.
The signature object we use for the PoW.
static int result
Global testing status.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
#define GNUNET_TIME_UNIT_WEEKS
One week.
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.
#define GNUNET_log(kind,...)
static char * rp
Relying party.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The signature purpose.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_pow()

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

Definition at line 619 of file revocation_api.c.

References GNUNET_IDENTITY_key_get_public(), pk, and sign_pow_identity().

Referenced by GNUNET_REVOCATION_pow_init().

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
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
enum GNUNET_GenericReturnValue sign_pow_identity(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
Here is the call graph for this function:
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.

References GNUNET_ntohll().

Referenced by GNUNET_REVOCATION_pow_round().

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
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ salt

struct GNUNET_CRYPTO_PowSalt salt = { "GnsRevocationPow" }
static

Definition at line 106 of file revocation_api.c.