27 #include "gnunet_signatures.h"
124 "Revocation query MQ error\n");
144 "Revocation query result: %d\n",
258 "Revocation MQ error\n");
259 h->func (
h->func_cls,
278 "Revocation transmission result: %d\n",
280 h->func (
h->func_cls,
363 h->func_cls = func_cls;
369 memcpy (&rm[1], pow, extra_len);
398 for (
unsigned int j = 0; j<
POW_COUNT; j++)
399 sum +=
ph->best[j].bits;
416 spurp->
purpose.
size = htonl (
sizeof(*spurp) + ksize);
434 sig = ((
unsigned char*) &pow[1] + ksize);
465 unsigned int difficulty,
477 unsigned int score = 0;
478 unsigned int tmp_score = 0;
492 "Proof of work signature invalid!\n");
499 for (
unsigned int i = 0; i <
POW_COUNT - 1; i++)
516 for (
unsigned int i = 0; i <
POW_COUNT; i++)
526 "Score %u with %" PRIu64
" (#%u)\n",
527 tmp_score, pow_val, i);
533 if (score < difficulty)
536 epochs = score - difficulty + 1;
585 sig = ((
char*) &pow[1]) + ksize;
639 pc->difficulty = difficulty;
688 for (
unsigned int i = 0; i <
POW_COUNT; i++)
689 if (
pc->current_pow ==
pc->best[i].pow)
706 for (
unsigned int i = 0; i <
POW_COUNT; i++)
708 if (
pc->best[i].bits < zeros)
710 pc->best[i].bits = zeros;
711 pc->best[i].pow =
pc->current_pow;
712 pc->pow->pow[i] = pow_nbo;
714 "New best score %u with %" PRIu64
" (#%u)\n",
715 zeros,
pc->current_pow, i);
struct GNUNET_MQ_Envelope * env
#define GNUNET_SIGNATURE_PURPOSE_REVOCATION
Signature for confirming a key revocation.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static int ret
Return value of the commandline.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static char * rp
Relying party.
static int result
Global testing status.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_TIME_Relative epoch_duration
Epoch length.
static unsigned long long matching_bits
Number of matching bits required for revocation.
static unsigned int epochs
-e option.
Constants for network protocols.
API to perform and access key revocations.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Generate a random unsigned 64-bit value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
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.
ssize_t GNUNET_IDENTITY_write_public_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_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
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.
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.
ssize_t GNUNET_IDENTITY_signature_get_raw_length_by_type(uint32_t type)
Get the compacted length of a signature by type.
unsigned int GNUNET_CRYPTO_hash_count_leading_zeros(const struct GNUNET_HashCode *h)
Count the number of leading 0 bits in h.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
void GNUNET_CRYPTO_pow_hash(const struct GNUNET_CRYPTO_PowSalt *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the 'proof-of-work' hash (an expensive hash).
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY
Client to service: was this key revoked?
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
Client to service OR peer-to-peer: revoke this key!
#define GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE
Service to client: revocation confirmed.
#define GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE
Service to client: answer if key was revoked!
void GNUNET_REVOCATION_pow_stop(struct GNUNET_REVOCATION_PowCalculationHandle *pc)
Stop a PoW calculation.
size_t GNUNET_REVOCATION_proof_get_size(const struct GNUNET_REVOCATION_PowP *pow)
struct GNUNET_REVOCATION_Query * GNUNET_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.
void GNUNET_REVOCATION_pow_init(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
Initializes a fresh PoW computation.
void GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q)
Cancel key revocation check.
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_pow_round(struct GNUNET_REVOCATION_PowCalculationHandle *pc)
Calculate a key revocation valid for broadcasting for a number of epochs.
void GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h)
Cancel key revocation.
#define POW_COUNT
The proof-of-work narrowing factor.
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.
struct GNUNET_REVOCATION_PowCalculationHandle * GNUNET_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.
struct GNUNET_REVOCATION_Handle * GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_REVOCATION_PowP *pow, GNUNET_REVOCATION_Callback func, void *func_cls)
Perform key revocation.
void(* GNUNET_REVOCATION_Callback)(void *cls, enum GNUNET_GenericReturnValue is_valid)
Callback to call with the result of a key revocation query.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
#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.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
static unsigned int size
Size of the "table".
messages for key revocation
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 c...
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 c...
static void handle_revocation_query_response(void *cls, const struct QueryResponseMessage *qrm)
Handle response to our revocation query.
static unsigned int calculate_score(const struct GNUNET_REVOCATION_PowCalculationHandle *ph)
Calculate the average zeros in the pows.
enum GNUNET_GenericReturnValue check_signature_identity(const struct GNUNET_REVOCATION_PowP *pow, const struct GNUNET_IDENTITY_PublicKey *key)
enum GNUNET_GenericReturnValue sign_pow_identity(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
static int cmp_pow_value(const void *a, const void *b)
Comparison function for quicksort.
static struct GNUNET_CRYPTO_PowSalt salt
enum GNUNET_GenericReturnValue check_signature(const struct GNUNET_REVOCATION_PowP *pow)
static void handle_revocation_response(void *cls, const struct RevocationResponseMessage *rrm)
Handle response to our revocation query.
enum GNUNET_GenericReturnValue sign_pow(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
struct GNUNET_REVOCATION_SignaturePurposePS * REV_create_signature_message(const struct GNUNET_REVOCATION_PowP *pow)
Create the revocation metadata to sign for a revocation message.
Helper struct that holds a found pow nonce and the corresponding number of leading zeros.
unsigned int bits
Corresponding zero bits in hash.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
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...
Value for a salt for GNUNET_CRYPTO_pow_hash().
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
An identity key as per LSD0001.
Handle to a message queue.
Message handler for a specific message type.
Handle for the key revocation operation.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
GNUNET_REVOCATION_Callback func
Function to call once we are done.
void * func_cls
Closure for func.
The handle to a PoW calculation.
unsigned int epochs
Epochs how long the PoW should be valid.
struct BestPow best[POW_COUNT]
Current set of found PoWs.
uint64_t current_pow
The current nonce to try.
unsigned int difficulty
The difficulty (leading zeros) to achieve.
struct GNUNET_REVOCATION_PowP * pow
The final PoW result data structure.
Struct for a proof of work as part of the revocation.
uint64_t pow[32]
The PoWs.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the revocation.
Handle for the key revocation query.
void * func_cls
Closure for func.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
GNUNET_REVOCATION_Callback func
Function to call with the result.
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.
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Query key revocation status.
uint32_t key_len
Key length.
uint32_t is_valid
GNUNET_NO if revoked, GNUNET_YES if valid.
uint32_t is_valid
GNUNET_NO if revocation failed for internal reasons (e.g.
uint32_t pow_size
Length of PoW with signature.