GNUnet  0.17.6
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 zeros. 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 calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph)
 Calculate the average zeros in the pows. More...
 
struct GNUNET_REVOCATION_SignaturePurposePSREV_create_signature_message (const struct GNUNET_REVOCATION_PowP *pow)
 Create the revocation metadata to sign for a revocation message. 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:97
@ 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:

◆ 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 zeros.

Definition at line 398 of file revocation_api.c.

399 {
400  double sum = 0.0;
401  for (unsigned int j = 0; j<POW_COUNT; j++)
402  sum += ph->best[j].bits;
403  double avg = sum / POW_COUNT;
404  return avg;
405 }
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.

◆ REV_create_signature_message()

struct GNUNET_REVOCATION_SignaturePurposePS* REV_create_signature_message ( const struct GNUNET_REVOCATION_PowP pow)

Create the revocation metadata to sign for a revocation message.

Parameters
powthe PoW to sign
Returns
the signature purpose

Definition at line 408 of file revocation_api.c.

409 {
411  const struct GNUNET_IDENTITY_PublicKey *pk;
412  size_t ksize;
413 
414  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
416  spurp = GNUNET_malloc (sizeof (*spurp) + ksize);
417  spurp->timestamp = pow->timestamp;
419  spurp->purpose.size = htonl (sizeof(*spurp) + ksize);
421  (char*) &spurp[1],
422  ksize);
423  return spurp;
424 }
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
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:991
#define GNUNET_malloc(size)
Wrapper around malloc.
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.
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.

Referenced by run().

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

429 {
431  unsigned char *sig;
432  size_t ksize;
433 
435  spurp = REV_create_signature_message (pow);
436  sig = ((unsigned char*) &pow[1] + ksize);
437  if (GNUNET_OK !=
439  &spurp->purpose,
440  sig,
441  key))
442  {
443  return GNUNET_SYSERR;
444  }
445  return GNUNET_OK;
446 }
struct GNUNET_HashCode key
The key used in the DHT.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_signature_verify_raw_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const unsigned char *sig, const struct GNUNET_IDENTITY_PublicKey *pub)
Verify a given signature.
@ GNUNET_OK
Definition: gnunet_common.h:99
struct GNUNET_REVOCATION_SignaturePurposePS * REV_create_signature_message(const struct GNUNET_REVOCATION_PowP *pow)
Create the revocation metadata to sign for a revocation message.

◆ check_signature()

enum GNUNET_GenericReturnValue check_signature ( const struct GNUNET_REVOCATION_PowP pow)

Definition at line 408 of file revocation_api.c.

451 {
452  const struct GNUNET_IDENTITY_PublicKey *pk;
453 
454  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
455  return check_signature_identity (pow, pk);
456 }
enum GNUNET_GenericReturnValue check_signature_identity(const struct GNUNET_REVOCATION_PowP *pow, const struct GNUNET_IDENTITY_PublicKey *key)

References GNUNET_IDENTITY_key_get_length(), GNUNET_IDENTITY_write_key_to_buffer(), GNUNET_malloc, GNUNET_SIGNATURE_PURPOSE_REVOCATION, pk, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_REVOCATION_SignaturePurposePS::purpose, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_REVOCATION_SignaturePurposePS::timestamp, and GNUNET_REVOCATION_PowP::timestamp.

Here is the call 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 408 of file revocation_api.c.

572 {
575  const struct GNUNET_IDENTITY_PublicKey *pk;
576  size_t ksize;
577  char *sig;
578 
585  pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1];
589  sig = ((char*) &pow[1]) + ksize;
591  &rp->purpose,
592  (void*) sig);
593  if (result == GNUNET_SYSERR)
594  return GNUNET_NO;
595  else
596  return result;
597 }
static char * rp
Relying party.
static int result
Global testing status.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_sign_raw_(const struct GNUNET_IDENTITY_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, unsigned char *sig)
Sign a given block.
@ GNUNET_NO
Definition: gnunet_common.h:98
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:110
#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:468
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:637
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 408 of file revocation_api.c.

603 {
605 
606  pk = (struct GNUNET_IDENTITY_PublicKey *) &pow[1];
608  return sign_pow_identity (key, pow);
609 }
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 665 of file revocation_api.c.

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

References 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.