GNUnet  0.19.5
GNS Record library

Manipulate GNS record data. More...

Collaboration diagram for GNS Record library:

Data Structures

struct  GNUNET_GNSRECORD_Data
 A GNS record. More...
 
struct  GNUNET_GNSRECORD_PlaceData
 Data stored in a PLACE record. More...
 
struct  GNUNET_GNSRECORD_EcdsaBlock
 Information we have in an encrypted block with record data (i.e. More...
 
struct  GNUNET_GNSRECORD_EddsaBlock
 Information we have in an encrypted block with record data (i.e. More...
 
struct  GNUNET_GNSRECORD_Block
 
struct  GNUNET_GNSRECORD_BoxRecord
 Record type used to box up SRV and TLSA records. More...
 
struct  GNUNET_GNSRECORD_ReverseRecord
 Record type used internally to keep track of reverse mappings into a namespace. More...
 

Macros

#define GNUNET_GNS_EMPTY_LABEL_AT   "@"
 String we use to indicate an empty label (top-level entry in the zone). More...
 
#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE   (63 * 1024)
 Maximum size of a value that can be stored in a GNS block. More...
 
#define GNUNET_GNSRECORD_TYPE_ANY   0
 Record type indicating any record/'*'. More...
 
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS   (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
 Include the record types generated from GANA. More...
 

Typedefs

typedef void(* GNUNET_GNSRECORD_RecordCallback) (void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Process a records that were decrypted from a block. More...
 

Enumerations

enum  GNUNET_GNSRECORD_Flags {
  GNUNET_GNSRECORD_RF_NONE = 0 , GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15) , GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14) , GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13) ,
  GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 1 << (15 - 1) , GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0) , GNUNET_GNSRECORD_RF_NONE = 0 , GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15) ,
  GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14) , GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13) , GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 1 << (15 - 1) , GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0)
}
 Flags that can be set for a record. More...
 
enum  GNUNET_GNSRECORD_Filter { GNUNET_GNSRECORD_FILTER_NONE = 0 , GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE = 1 , GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE = 2 }
 Filter for GNUNET_GNSRECORD_normalize_record_set(). More...
 

Functions

struct GNUNET_JSON_Specification GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, unsigned int *rd_count, char **name)
 JSON Specification for GNS Records. More...
 
json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord (const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Convert GNS record to JSON. More...
 
char * GNUNET_GNSRECORD_value_to_string (uint32_t type, const void *data, size_t data_size)
 Convert the binary value data of a record of type type to a human-readable string. More...
 
int GNUNET_GNSRECORD_string_to_value (uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of the value s of a record of type type to the respective binary representation. More...
 
uint32_t GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
 Convert a type name (e.g. More...
 
const char * GNUNET_GNSRECORD_number_to_typename (uint32_t type)
 Convert a type number to the corresponding type string (e.g. More...
 
ssize_t GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Calculate how many bytes we will need to serialize the given records. More...
 
ssize_t GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
 Serialize the given records to the given destination buffer. More...
 
unsigned int GNUNET_GNSRECORD_records_deserialize_get_size (size_t len, const char *src)
 
int GNUNET_GNSRECORD_records_deserialize (size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
 Deserialize the given records to the given destination. More...
 
int GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd)
 Test if a given record is expired. More...
 
char * GNUNET_GNSRECORD_string_normalize (const char *src)
 Normalize a UTF-8 string to a GNS name. More...
 
const char * GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z)
 Convert a zone to a string (for printing debug messages). More...
 
const char * GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey)
 Convert public key to the respective absolute domain name in the ".zkey" pTLD. More...
 
int GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, struct GNUNET_IDENTITY_PublicKey *pkey)
 Convert an absolute domain name to the respective public key. More...
 
void GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone. More...
 
void GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone. More...
 
ssize_t GNUNET_GNSRECORD_block_calculate_size (const struct GNUNET_IDENTITY_PrivateKey *key, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Get size of buffer for block creation. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_sign (const struct GNUNET_IDENTITY_PrivateKey *key, const char *label, struct GNUNET_GNSRECORD_Block *block)
 Sign a block create with GNUNET_GNSRECORD_block_create_unsigned. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block)
 Sign name and records. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create_unsigned (const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
 Create name and records but do not sign! Sign later with GNUNET_GNSRECORD_block_sign(). More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result)
 Sign name and records, cache derived public key (also keeps the private key in static memory, so do not use this function if keeping the private key in the process'es RAM is a major issue). More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
 Check if a signature is valid. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 Decrypt block. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, const struct GNUNET_GNSRECORD_Data *b)
 Compares if two records are equal. More...
 
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute min)
 Returns the expiration time of the given block of records. More...
 
size_t GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block)
 Returns the length of this block in bytes. More...
 
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_block_get_expiration (const struct GNUNET_GNSRECORD_Block *block)
 Returns the expiration of a block. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, struct GNUNET_HashCode *query)
 Builds the query hash from a block. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data (const char *data, size_t data_size, uint32_t type, struct GNUNET_IDENTITY_PublicKey *key)
 Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity (const struct GNUNET_IDENTITY_PublicKey *key, char **data, size_t *data_size, uint32_t *type)
 Create record data and size from an identity key. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type (uint32_t type)
 Check if this type is one of the supported GNS zone types. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_critical (uint32_t type)
 Check if this type is a critical record. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_normalize_record_set (const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *rd_public, unsigned int *rd_count_public, struct GNUNET_TIME_Absolute *min_expiry, enum GNUNET_GNSRECORD_Filter filter, char **emsg)
 Normalize namestore records: Check for consistency and expirations. More...
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_label_check (const char *label, char **emsg)
 Check label for invalid characters. More...
 

Detailed Description

Manipulate GNS record data.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_GNS_EMPTY_LABEL_AT

#define GNUNET_GNS_EMPTY_LABEL_AT   "@"

String we use to indicate an empty label (top-level entry in the zone).

DNS uses "@", so do we.

Definition at line 55 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_MAX_BLOCK_SIZE

#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE   (63 * 1024)

Maximum size of a value that can be stored in a GNS block.

Definition at line 60 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_TYPE_ANY

#define GNUNET_GNSRECORD_TYPE_ANY   0

Record type indicating any record/'*'.

Definition at line 66 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_RF_RCMP_FLAGS

#define GNUNET_GNSRECORD_RF_RCMP_FLAGS   (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)

Include the record types generated from GANA.

When comparing flags for record equality for removal, which flags should must match (in addition to the type, name, expiration value and data of the record)? All flags that are not listed here will be ignored for this purpose. (for example, we don't expect that users will remember to pass the '–private' option when removing a record from the namestore, hence we don't require this particular option to match upon removal). See also GNUNET_GNSRECORD_records_cmp.

Definition at line 84 of file gnunet_gnsrecord_lib.h.

Typedef Documentation

◆ GNUNET_GNSRECORD_RecordCallback

typedef void(* GNUNET_GNSRECORD_RecordCallback) (void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)

Process a records that were decrypted from a block.

Parameters
clsclosure
rd_countnumber of entries in rd array
rdarray of records with data to store

Definition at line 360 of file gnunet_gnsrecord_lib.h.

Enumeration Type Documentation

◆ GNUNET_GNSRECORD_Flags

Flags that can be set for a record.

The numbers in the registry correspond to the bit index as specified in LSD0001 Chapter "Resource Records". Each enum member represents the 16-bit integer value of the flags field if only that particular flag was set. The value can be used to efficiently compare the bitmask setting for the record flag in C. WARNING: The values are in host byte order! In order to correctly check against the flags field a record, the respective fields must also be converted to HBO (or the enum value to NBO).

Enumerator
GNUNET_GNSRECORD_RF_NONE 

Entry for no flags / cleared flags.

GNUNET_GNSRECORD_RF_CRITICAL 

This record is critical.

If it cannot be processed (for example because the record type is unknown) resolution MUST fail

GNUNET_GNSRECORD_RF_SHADOW 

This record should not be used unless all (other) records in the set with an absolute expiration time have expired.

GNUNET_GNSRECORD_RF_SUPPLEMENTAL 

This is a supplemental record.

GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION 

This expiration time of the record is a relative time (not an absolute time).

Used in GNUnet implementation.

GNUNET_GNSRECORD_RF_PRIVATE 

This is a private record of this peer and it should thus not be published.

GNUNET_GNSRECORD_RF_NONE 

Entry for no flags / cleared flags.

GNUNET_GNSRECORD_RF_CRITICAL 

This record is critical.

If it cannot be processed (for example because the record type is unknown) resolution MUST fail

GNUNET_GNSRECORD_RF_SHADOW 

This record should not be used unless all (other) records in the set with an absolute expiration time have expired.

GNUNET_GNSRECORD_RF_SUPPLEMENTAL 

This is a supplemental record.

GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION 

This expiration time of the record is a relative time (not an absolute time).

Used in GNUnet implementation.

GNUNET_GNSRECORD_RF_PRIVATE 

This is a private record of this peer and it should thus not be published.

Definition at line 99 of file gnunet_gnsrecord_lib.h.

100 {
105 
106 
110  GNUNET_GNSRECORD_RF_CRITICAL = 1 << (15 - 15),
111 
112 
116  GNUNET_GNSRECORD_RF_SHADOW = 1 << (15 - 14),
117 
118 
122  GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 1 << (15 - 13),
123 
124 
129 
130 
134  GNUNET_GNSRECORD_RF_PRIVATE = 1 << (15 - 0),
135 
136 };
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_CRITICAL
This record is critical.
@ GNUNET_GNSRECORD_RF_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
@ GNUNET_GNSRECORD_RF_NONE
Entry for no flags / cleared flags.

◆ GNUNET_GNSRECORD_Filter

Filter for GNUNET_GNSRECORD_normalize_record_set().

Enumerator
GNUNET_GNSRECORD_FILTER_NONE 

No filter flags set.

Private and public records are returned, maintenance records (TOMBSTONE etc) are not.

GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE 

Include maintenance records (TOMBSTONE etc).

GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE 

Filter private records.

Definition at line 142 of file gnunet_gnsrecord_lib.h.

143 {
150 
155 
160 
165  // GNUNET_NAMESTORE_FILTER_OMIT_PUBLIC = 4,
166 };
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
@ GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE
Include maintenance records (TOMBSTONE etc).
@ GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE
Filter private records.

Function Documentation

◆ GNUNET_GNSRECORD_JSON_spec_gnsrecord()

struct GNUNET_JSON_Specification GNUNET_GNSRECORD_JSON_spec_gnsrecord ( struct GNUNET_GNSRECORD_Data **  rd,
unsigned int *  rd_count,
char **  name 
)

JSON Specification for GNS Records.

Parameters
gnsrecord_objectstruct of GNUNET_GNSRECORD_Data to fill
Returns
JSON Specification

Definition at line 258 of file json_gnsrecord.c.

276 {
277  struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
278 
279  gnsrecord_info->rd = rd;
280  gnsrecord_info->name = name;
281  gnsrecord_info->rd_count = rd_count;
283  .cleaner = &clean_gnsrecordobject,
284  .cls = NULL,
285  .field = NULL,
286  .ptr = (struct GnsRecordInfo *)
287  gnsrecord_info,
288  .ptr_size = 0,
289  .size_ptr = NULL };
290  return ret;
291 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void clean_gnsrecordobject(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing the record.
static int parse_gnsrecordobject(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
const char * name
Entry in parser specification for GNUNET_JSON_parse().
struct GNUNET_GNSRECORD_Data ** rd
unsigned int * rd_count

Referenced by bulk_tx_start(), and namestore_add_or_update().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_JSON_from_gnsrecord()

json_t* GNUNET_GNSRECORD_JSON_from_gnsrecord ( const char *  rname,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

Convert GNS record to JSON.

Parameters
rnamename of record
rdrecord data
Returns
corresponding JSON encoding

Definition at line 302 of file json_gnsrecord.c.

305 {
306  const char *record_type_str;
307  char *value_str;
308  json_t *data;
309  json_t *record;
310  json_t *records;
311 
312  data = json_object ();
313  if (NULL == data)
314  {
315  GNUNET_break (0);
316  return NULL;
317  }
318  if (0 !=
319  json_object_set_new (data,
320  "record_name",
321  json_string (rname)))
322  {
323  GNUNET_break (0);
324  json_decref (data);
325  return NULL;
326  }
327  records = json_array ();
328  if (NULL == records)
329  {
330  GNUNET_break (0);
331  json_decref (data);
332  return NULL;
333  }
334  for (int i = 0; i < rd_count; i++)
335  {
336  value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
337  rd[i].data,
338  rd[i].data_size);
339  record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
341  "Packing %s %s %" PRIu64 " %d\n",
342  value_str, record_type_str, rd[i].expiration_time, rd[i].flags);
343  record = json_pack ("{s:s,s:s,s:I,s:b,s:b,s:b,s:b}",
345  value_str,
347  record_type_str,
348  (rd[i].flags
352  rd[i].expiration_time,
354  rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
360  rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW);
361  GNUNET_free (value_str);
362  if (NULL == record)
363  {
364  GNUNET_break (0);
365  json_decref (records);
366  json_decref (data);
367  return NULL;
368  }
369  if (0 !=
370  json_array_append_new (records,
371  record))
372  {
373  GNUNET_break (0);
374  json_decref (records);
375  json_decref (data);
376  return NULL;
377  }
378  }
379  if (0 !=
380  json_object_set_new (data,
381  "data",
382  records))
383  {
384  GNUNET_break (0);
385  json_decref (data);
386  return NULL;
387  }
388  return data;
389 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
uint32_t data
The data value.
static unsigned int records
Number of records we found.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition: gnsrecord.c:227
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
Definition: gnsrecord.c:155
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_JSON_GNSRECORD_VALUE
#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE
#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME
#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL
#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME
#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE
#define GNUNET_JSON_GNSRECORD_TYPE

References data, data_size, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW, GNUNET_GNSRECORD_RF_SUPPLEMENTAL, GNUNET_GNSRECORD_value_to_string(), GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME, GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME, GNUNET_JSON_GNSRECORD_TYPE, GNUNET_JSON_GNSRECORD_VALUE, GNUNET_log, rd, rd_count, record(), and records.

Referenced by handle_gns_response(), namestore_list_iteration(), and ns_get_lookup_cb().

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

◆ GNUNET_GNSRECORD_value_to_string()

char* GNUNET_GNSRECORD_value_to_string ( uint32_t  type,
const void *  data,
size_t  data_size 
)

Convert the binary value data of a record of type type to a human-readable string.

Parameters
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Convert the binary value data of a record of type type to a human-readable string.

Parameters
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 155 of file gnsrecord.c.

158 {
159  struct Plugin *plugin;
160  char *ret;
161 
162  init ();
163  for (unsigned int i = 0; i < num_plugins; i++)
164  {
165  plugin = gns_plugins[i];
166  if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
167  type,
168  data,
169  data_size)))
170  return ret;
171  }
172  return NULL;
173 }
static unsigned int num_plugins
Size of the 'plugins' array.
Definition: gnsrecord.c:62
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:57
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:99
struct TestcasePlugin * plugin
The process handle to the testbed service.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_TESTING_PluginFunctions * api
Plugin API.
Definition: testing.h:103
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References TestcasePlugin::api, data, data_size, gns_plugins, init(), num_plugins, plugin, ret, and type.

Referenced by check_pkey(), del_monitor(), display_record(), display_records_from_block(), gns_value_to_string(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), process_lookup_result(), and start_phone().

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

◆ GNUNET_GNSRECORD_string_to_value()

int GNUNET_GNSRECORD_string_to_value ( uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)

Convert human-readable version of the value s of a record of type type to the respective binary representation.

Parameters
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 177 of file gnsrecord.c.

181 {
182  struct Plugin *plugin;
183 
184  init ();
185  for (unsigned int i = 0; i < num_plugins; i++)
186  {
187  plugin = gns_plugins[i];
188  if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
189  type,
190  s,
191  data,
192  data_size))
193  return GNUNET_OK;
194  }
195  return GNUNET_SYSERR;
196 }
@ GNUNET_OK
@ GNUNET_SYSERR

References TestcasePlugin::api, data, data_size, gns_plugins, GNUNET_OK, GNUNET_SYSERR, init(), num_plugins, plugin, and type.

Referenced by gns_string_to_value(), parse(), parse_record(), parse_recordline(), run(), run_with_zone_pkey(), and store_cb().

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

◆ GNUNET_GNSRECORD_typename_to_number()

uint32_t GNUNET_GNSRECORD_typename_to_number ( const char *  dns_typename)

Convert a type name (e.g.

"AAAA") to the corresponding number.

Parameters
dns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 200 of file gnsrecord.c.

201 {
202  struct Plugin *plugin;
203  uint32_t ret;
204 
205  if (0 == strcasecmp (dns_typename,
206  "ANY"))
208  init ();
209  for (unsigned int i = 0; i < num_plugins; i++)
210  {
211  plugin = gns_plugins[i];
212  if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
213  dns_typename)))
214  return ret;
215  }
216  return UINT32_MAX;
217 }
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.

References TestcasePlugin::api, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, and ret.

Referenced by del_monitor(), DID_create(), display_record(), get_gns_cont(), namestore_get(), parse(), parse_record(), parse_recordline(), run(), and run_with_zone_pkey().

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

◆ GNUNET_GNSRECORD_number_to_typename()

const char* GNUNET_GNSRECORD_number_to_typename ( uint32_t  type)

Convert a type number to the corresponding type string (e.g.

1 to "A")

Parameters
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 227 of file gnsrecord.c.

228 {
229  struct Plugin *plugin;
230  const char *ret;
231 
233  return "ANY";
234  init ();
235  for (unsigned int i = 0; i < num_plugins; i++)
236  {
237  plugin = gns_plugins[i];
238  if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
239  type)))
240  return ret;
241  }
242  return NULL;
243 }

Referenced by display_record(), display_records_from_block(), GNUNET_GNSRECORD_JSON_from_gnsrecord(), parse_recordline(), process_lookup_result(), and run_with_zone_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_records_get_size()

ssize_t GNUNET_GNSRECORD_records_get_size ( unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)

Calculate how many bytes we will need to serialize the given records.

Parameters
rd_countnumber of records in the rd array
rdarray of GNUNET_GNSRECORD_Data with rd_count elements
Returns
the required size to serialize, -1 on error

Efficiently round up to the next power of 2 for padding https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

Definition at line 78 of file gnsrecord_serialization.c.

80 {
81  size_t ret;
82 
83  if (0 == rd_count)
84  return 0;
85 
86  ret = sizeof(struct NetworkRecord) * rd_count;
87  for (unsigned int i = 0; i < rd_count; i++)
88  {
89  if ((ret + rd[i].data_size) < ret)
90  {
91  GNUNET_break (0);
92  return -1;
93  }
94  ret += rd[i].data_size;
95 #if DEBUG_GNSRECORDS
96  {
97  char *str;
98 
100  rd[i].data,
101  rd[i].data_size);
102  if (NULL == str)
103  {
104  GNUNET_break_op (0);
105  return -1;
106  }
107  GNUNET_free (str);
108  }
109 #endif
110  }
111  if (ret > SSIZE_MAX)
112  {
113  GNUNET_break (0);
114  return -1;
115  }
116  // Do not pad PKEY
119  return ret;ret--;
125  ret |= ret >> 1;
126  ret |= ret >> 2;
127  ret |= ret >> 4;
128  ret |= ret >> 8;
129  ret |= ret >> 16;
130  ret++;
131  return (ssize_t) ret;
132 }
#define GNUNET_GNSRECORD_TYPE_PKEY
WARNING: This header is generated! In order to add GNS record types, you must register them in GANA,...
#define GNUNET_GNSRECORD_TYPE_EDKEY
GNS zone delegation (EDKEY)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t record_type
Type of the GNS/DNS record.
size_t data_size
Number of bytes in data.
Internal format of a record in the serialized form.
uint32_t record_type
Type of the GNS/DNS record, network byte order.

References data, data_size, GNUNET_GNSRECORD_Data::data_size, GNUNET_break, GNUNET_break_op, GNUNET_free, GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_GNSRECORD_value_to_string(), rd, rd_count, NetworkRecord::record_type, GNUNET_GNSRECORD_Data::record_type, and ret.

Referenced by block_create_ecdsa(), block_create_eddsa(), check_zone_to_name(), consistency_iter(), GNUNET_NAMESTORE_records_store2(), lookup_it(), result_processor(), run_edkey(), run_pkey(), rvk_ticket_update(), send_lookup_response(), send_lookup_response_with_filter(), and store_and_free_entries().

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

◆ GNUNET_GNSRECORD_records_serialize()

ssize_t GNUNET_GNSRECORD_records_serialize ( unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd,
size_t  dest_size,
char *  dest 
)

Serialize the given records to the given destination buffer.

Parameters
rd_countnumber of records in the rd array
rdarray of GNUNET_GNSRECORD_Data with rd_count elements
dest_sizesize of the destination array dst
destwhere to write the result
Returns
the size of serialized records, -1 if records do not fit

Definition at line 136 of file gnsrecord_serialization.c.

140 {
141  struct NetworkRecord rec;
142  size_t off;
143 
144  off = 0;
145  for (unsigned int i = 0; i < rd_count; i++)
146  {
148  "Serializing record %u with flags %d and expiration time %llu\n",
149  i,
150  rd[i].flags,
151  (unsigned long long) rd[i].expiration_time);
152  rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
153  rec.data_size = htons ((uint16_t) rd[i].data_size);
154  rec.record_type = htonl (rd[i].record_type);
155  rec.flags = htons (rd[i].flags);
156  if ((off + sizeof(rec) > dest_size) ||
157  (off + sizeof(rec) < off))
158  {
159  GNUNET_break (0);
160  return -1;
161  }
162  GNUNET_memcpy (&dest[off],
163  &rec,
164  sizeof(rec));
165  off += sizeof(rec);
166  if ((off + rd[i].data_size > dest_size) ||
167  (off + rd[i].data_size < off))
168  {
169  GNUNET_break (0);
170  return -1;
171  }
172  GNUNET_memcpy (&dest[off],
173  rd[i].data,
174  rd[i].data_size);
175  off += rd[i].data_size;
176 #if DEBUG_GNSRECORDS
177  {
178  char *str;
179 
181  rd[i].data,
182  rd[i].data_size);
183  if (NULL == str)
184  {
185  GNUNET_break_op (0);
186  return -1;
187  }
188  GNUNET_free (str);
189  }
190 #endif
191  }
192  memset (&dest[off],
193  0,
194  dest_size - off);
195  return dest_size;
196 }
#define LOG(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint64_t expiration_time
Expiration time for the DNS record; relative or absolute depends on flags, network byte order.
uint16_t flags
Flags for the record, network byte order.

References data, data_size, NetworkRecord::data_size, GNUNET_GNSRECORD_Data::data_size, warningfilter::dest, NetworkRecord::expiration_time, NetworkRecord::flags, GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_value_to_string(), GNUNET_htonll(), GNUNET_memcpy, LOG, rd, rd_count, and NetworkRecord::record_type.

Referenced by check_zone_to_name(), consistency_iter(), GNUNET_NAMESTORE_records_store2(), lookup_it(), result_processor(), run_edkey(), run_pkey(), rvk_ticket_update(), send_lookup_response(), send_lookup_response_with_filter(), and store_and_free_entries().

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

◆ GNUNET_GNSRECORD_records_deserialize_get_size()

unsigned int GNUNET_GNSRECORD_records_deserialize_get_size ( size_t  len,
const char *  src 
)

Definition at line 199 of file gnsrecord_serialization.c.

201 {
202  struct NetworkRecord rec;
203  struct NetworkRecord rec_zero;
204  size_t off;
205  unsigned int rd_count = 0;
206 
207  memset (&rec_zero, 0, sizeof (rec_zero));
208 
209  off = 0;
210  for (off = 0; (off + sizeof(rec) <= len) && (off + sizeof(rec) >= off);)
211  {
212  GNUNET_memcpy (&rec,
213  &src[off],
214  sizeof(rec));
215  /*
216  * If we have found a byte string of zeroes, we have reached
217  * the padding
218  */
219  if (0 == GNUNET_memcmp (&rec, &rec_zero))
220  break;
221  off += sizeof(rec);
222  if ((off + ntohs ((uint16_t) rec.data_size) > len) ||
223  (off + ntohs ((uint16_t) rec.data_size) < off))
224  {
225  GNUNET_break_op (0);
226  return 0;
227  }
228  off += ntohs ((uint16_t) rec.data_size);
229  rd_count++;
230  }
231  return rd_count;
232 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.

References NetworkRecord::data_size, GNUNET_break_op, GNUNET_memcmp, GNUNET_memcpy, len, and rd_count.

◆ GNUNET_GNSRECORD_records_deserialize()

int GNUNET_GNSRECORD_records_deserialize ( size_t  len,
const char *  src,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Data dest 
)

Deserialize the given records to the given destination.

Parameters
lensize of the serialized record data
srcthe serialized record data
rd_countnumber of records in the dest array
destwhere to put the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error
Parameters
lensize of the serialized record data
srcthe serialized record data
rd_countnumber of records parsed
destwhere to put the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 244 of file gnsrecord_serialization.c.

248 {
249  struct NetworkRecord rec;
250  size_t off;
251 
252  off = 0;
253  for (unsigned int i = 0; i < rd_count; i++)
254  {
255  if ((off + sizeof(rec) > len) ||
256  (off + sizeof(rec) < off))
257  {
258  GNUNET_break_op (0);
259  return GNUNET_SYSERR;
260  }
261  GNUNET_memcpy (&rec,
262  &src[off],
263  sizeof(rec));
264  dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
265  dest[i].data_size = ntohs ((uint16_t) rec.data_size);
266  dest[i].record_type = ntohl (rec.record_type);
267  dest[i].flags = ntohs (rec.flags);
268  off += sizeof(rec);
269  if ((off + dest[i].data_size > len) ||
270  (off + dest[i].data_size < off))
271  {
272  GNUNET_break_op (0);
273  return GNUNET_SYSERR;
274  }
275  dest[i].data = &src[off];
276  off += dest[i].data_size;
277 #if GNUNET_EXTRA_LOGGING
278  {
279  char *str;
280 
282  dest[i].data,
283  dest[i].data_size);
284  if (NULL == str)
285  {
286  GNUNET_break_op (0);
287  return GNUNET_SYSERR;
288  }
289  GNUNET_free (str);
290  }
291 #endif
293  "Deserialized record %u with flags %d and expiration time %llu\n",
294  i,
295  dest[i].flags,
296  (unsigned long long) dest[i].expiration_time);
297  }
298  return GNUNET_OK;
299 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54

References data, data_size, NetworkRecord::data_size, warningfilter::dest, NetworkRecord::expiration_time, NetworkRecord::flags, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_value_to_string(), GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, len, LOG, rd_count, and NetworkRecord::record_type.

Referenced by check_rd(), check_result(), continue_store_activity(), database_setup(), handle_lookup_result(), handle_record_result(), handle_result(), handle_zone_to_name_response(), lookup_records(), process_tickets(), update_tickets(), and vpn_allocation_cb().

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

◆ GNUNET_GNSRECORD_is_expired()

int GNUNET_GNSRECORD_is_expired ( const struct GNUNET_GNSRECORD_Data rd)

Test if a given record is expired.

Parameters
rdrecord to test
Returns
GNUNET_YES if the record is expired, GNUNET_NO if not
GNUNET_YES if the record is expired, GNUNET_NO if not

Definition at line 209 of file gnsrecord_misc.c.

210 {
211  struct GNUNET_TIME_Absolute at;
212 
214  return GNUNET_NO;
215  at.abs_value_us = rd->expiration_time;
216  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ?
218 }
@ GNUNET_YES
@ GNUNET_NO
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?
Definition: time.c:405
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Time for absolute times used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_NO, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, and rd.

Here is the call graph for this function:

◆ GNUNET_GNSRECORD_string_normalize()

char* GNUNET_GNSRECORD_string_normalize ( const char *  src)

Normalize a UTF-8 string to a GNS name.

Parameters
srcsource string
Returns
converted result

Definition at line 40 of file gnsrecord_misc.c.

41 {
42  /*FIXME: We may want to follow RFC5890/RFC5891 */
43  return GNUNET_STRINGS_utf8_normalize (src);
44 }
char * GNUNET_STRINGS_utf8_normalize(const char *input)
Normalize the utf-8 input string to NFC.
Definition: strings.c:429

Referenced by continue_store_activity(), GNUNET_GNSRECORD_query_from_private_key(), handle_record_lookup(), run_edkey(), and run_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_z2s()

const char* GNUNET_GNSRECORD_z2s ( const struct GNUNET_IDENTITY_PublicKey z)

Convert a zone to a string (for printing debug messages).

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
zpublic key of a zone
Returns
string form; will be overwritten by next call to GNUNET_GNSRECORD_z2s.

Definition at line 65 of file gnsrecord_misc.c.

66 {
67  static char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) * 8];
68  char *end;
69 
70  end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
71  sizeof(struct
73  buf, sizeof(buf));
74  if (NULL == end)
75  {
76  GNUNET_break (0);
77  return NULL;
78  }
79  *end = '\0';
80  return buf;
81 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static char buf[2048]
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:708
An identity key as per LSD0001.

Referenced by get_nick_record(), handle_gns_resolution_result(), handle_namecache_block_response(), handle_revocation_result(), namestore_flat_zone_to_name(), recursive_gns_resolution_namecache(), and recursive_gns_resolution_revocation().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_pkey_to_zkey()

const char* GNUNET_GNSRECORD_pkey_to_zkey ( const struct GNUNET_IDENTITY_PublicKey pkey)

Convert public key to the respective absolute domain name in the ".zkey" pTLD.

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
pkeya public key with a point on the eliptic curve
Returns
string "X.zkey" where X is the coordinates of the public key in an encoding suitable for DNS labels.

This is one of the very few calls in the entire API that is NOT reentrant!

Parameters
pkeya public key with a point on the eliptic curve
Returns
string "X.zkey" where X is the public key in an encoding suitable for DNS labels.

Definition at line 232 of file gnsrecord_misc.c.

233 {
234  static char ret[128];
235  char *pkeys;
236 
239  sizeof(ret),
240  "%s",
241  pkeys);
242  GNUNET_free (pkeys);
243  return ret;
244 }
static char * pkey
Public key of the zone to look in, in ASCII.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.

References GNUNET_free, GNUNET_IDENTITY_public_key_to_string(), GNUNET_snprintf(), pkey, and ret.

Referenced by caller_event_handler(), do_accept(), do_call(), do_resume(), do_status(), handle_phone_hangup(), phone_event_handler(), and translate_dot_plus().

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

◆ GNUNET_GNSRECORD_zkey_to_pkey()

int GNUNET_GNSRECORD_zkey_to_pkey ( const char *  zkey,
struct GNUNET_IDENTITY_PublicKey pkey 
)

Convert an absolute domain name to the respective public key.

Parameters
zkeystring "X" where X is the public key in an encoding suitable for DNS labels.
pkeyset to a public key on the eliptic curve
Returns
GNUNET_SYSERR if zkey has the wrong syntax
Parameters
zkeystring encoding the coordinates of the public key in an encoding suitable for DNS labels.
pkeyset to a public key on the eliptic curve
Returns
GNUNET_SYSERR if zkey has the wrong syntax

Definition at line 257 of file gnsrecord_misc.c.

259 {
260  if (GNUNET_OK !=
262  pkey))
263  return GNUNET_SYSERR;
264  return GNUNET_OK;
265 }
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.

Referenced by GNS_find_tld(), handle_gns_redirect_result(), and recursive_gns2dns_resolution().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_query_from_private_key()

void GNUNET_GNSRECORD_query_from_private_key ( const struct GNUNET_IDENTITY_PrivateKey zone,
const char *  label,
struct GNUNET_HashCode query 
)

Calculate the DHT query for a given label in a given zone.

Parameters
zoneprivate key of the zone
labellabel of the record
queryhash to use for the query

Definition at line 1024 of file gnsrecord_crypto.c.

1028 {
1029  char *norm_label;
1031 
1032  norm_label = GNUNET_GNSRECORD_string_normalize (label);
1033  switch (ntohl (zone->type))
1034  {
1037 
1039  &pub);
1041  norm_label,
1042  query);
1043  break;
1044  default:
1045  GNUNET_assert (0);
1046  }
1047  GNUNET_free (norm_label);
1048 }
static char * zone
Name of the zone being managed.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
char * GNUNET_GNSRECORD_string_normalize(const char *src)
Normalize a UTF-8 string to a GNS name.
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
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:179
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_assert, GNUNET_free, GNUNET_GNSRECORD_query_from_public_key(), GNUNET_GNSRECORD_string_normalize(), GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_IDENTITY_key_get_public(), pub, and zone.

Referenced by initiate_put_from_pipe_trigger().

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

◆ GNUNET_GNSRECORD_query_from_public_key()

void GNUNET_GNSRECORD_query_from_public_key ( const struct GNUNET_IDENTITY_PublicKey pub,
const char *  label,
struct GNUNET_HashCode query 
)

Calculate the DHT query for a given label in a given zone.

FIXME: We may want to plugin-ize this at some point.

Parameters
pubpublic key of the zone
labellabel of the record
queryhash to use for the query

Definition at line 1052 of file gnsrecord_crypto.c.

1056 {
1057  char *norm_label;
1058  struct GNUNET_IDENTITY_PublicKey pd;
1059 
1060  norm_label = GNUNET_GNSRECORD_string_normalize (label);
1061 
1062  switch (ntohl (pub->type))
1063  {
1065  pd.type = pub->type;
1067  norm_label,
1068  "gns",
1069  &pd.ecdsa_key);
1070  GNUNET_CRYPTO_hash (&pd.ecdsa_key,
1071  sizeof (pd.ecdsa_key),
1072  query);
1073  break;
1075  pd.type = pub->type;
1077  norm_label,
1078  "gns",
1079  &(pd.eddsa_key));
1080  GNUNET_CRYPTO_hash (&pd.eddsa_key,
1081  sizeof (pd.eddsa_key),
1082  query);
1083  break;
1084  default:
1085  GNUNET_assert (0);
1086  }
1087  GNUNET_free (norm_label);
1088 }
void GNUNET_CRYPTO_ecdsa_public_key_derive(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EcdsaPublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_eddsa_public_key_derive(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPublicKey *result)
Derive a public key from a given public key and a label.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41

Referenced by GNUNET_GNSRECORD_query_from_private_key(), handle_namecache_block_response(), recursive_gns_resolution_namecache(), run(), run_edkey(), and run_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_calculate_size()

ssize_t GNUNET_GNSRECORD_block_calculate_size ( const struct GNUNET_IDENTITY_PrivateKey key,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

Get size of buffer for block creation.

Parameters
keythe zone key
rdrecord data
rd_countnumber of records
Returns
-1 on error (otherwise the length of the block)

Definition at line 512 of file gnsrecord_crypto.c.

516 {
518  ssize_t res = -1;
519 
521  &pkey);
522  switch (ntohl (key->type))
523  {
526  break;
529  break;
530  default:
531  GNUNET_assert (0);
532  }
533  return res;
534 
535 }
static ssize_t block_get_size_eddsa(const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
static ssize_t block_get_size_ecdsa(const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
static int res
struct GNUNET_HashCode key
The key used in the DHT.

◆ GNUNET_GNSRECORD_block_sign()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_sign ( const struct GNUNET_IDENTITY_PrivateKey key,
const char *  label,
struct GNUNET_GNSRECORD_Block block 
)

Sign a block create with GNUNET_GNSRECORD_block_create_unsigned.

Parameters
keythe private key
labelthe label of the block
blockthe unsigned block
Returns
GNUNET_OK on success

Definition at line 186 of file gnsrecord_crypto.c.

279 {
282  char *norm_label;
283 
285  &pkey);
286  norm_label = GNUNET_GNSRECORD_string_normalize (label);
287 
288  switch (ntohl (key->type))
289  {
291  res = block_sign_ecdsa (&key->ecdsa_key,
292  &pkey.ecdsa_key,
293  norm_label,
294  block);
295  break;
297  res = block_sign_eddsa (&key->eddsa_key,
298  &pkey.eddsa_key,
299  norm_label,
300  block);
301  break;
302  default:
303  GNUNET_assert (0);
304  }
305  GNUNET_free (norm_label);
306  return res;
307 }
enum GNUNET_GenericReturnValue block_sign_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
enum GNUNET_GenericReturnValue block_sign_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
GNUNET_GenericReturnValue
Named constants for return values.

Referenced by sign_worker().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create ( const struct GNUNET_IDENTITY_PrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Block **  block 
)

Sign name and records.

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
resultthe block buffer. Will be allocated.
Returns
GNUNET_OK on success

Definition at line 512 of file gnsrecord_crypto.c.

545 {
548  char *norm_label;
549 
551  &pkey);
552  norm_label = GNUNET_GNSRECORD_string_normalize (label);
553 
554  switch (ntohl (key->type))
555  {
557  res = block_create_ecdsa (&key->ecdsa_key,
558  &pkey.ecdsa_key,
559  expire,
560  norm_label,
561  rd,
562  rd_count,
563  result,
564  GNUNET_YES);
565  break;
567  res = block_create_eddsa (&key->eddsa_key,
568  &pkey.eddsa_key,
569  expire,
570  norm_label,
571  rd,
572  rd_count,
573  result,
574  GNUNET_YES);
575  break;
576  default:
577  GNUNET_assert (0);
578  }
579  GNUNET_free (norm_label);
580  return res;
581 }
enum GNUNET_GenericReturnValue block_create_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records (EDDSA version)
static enum GNUNET_GenericReturnValue block_create_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records.
static char * expire
DID Document expiration Date Attribut String.
Definition: gnunet-did.c:101
static int result
Global testing status.

Referenced by run_edkey(), and run_pkey().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create_unsigned()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create_unsigned ( const struct GNUNET_IDENTITY_PrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Block **  result 
)

Create name and records but do not sign! Sign later with GNUNET_GNSRECORD_block_sign().

Cache derived public key (also keeps the private key in static memory, so do not use this function if keeping the private key in the process'es RAM is a major issue).

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
resultthe block buffer. Will be allocated.
Returns
GNUNET_OK on success.

Definition at line 512 of file gnsrecord_crypto.c.

670 {
671  return block_create2 (pkey, expire, label, rd, rd_count, result, GNUNET_NO);
672 }
static enum GNUNET_GenericReturnValue block_create2(const struct GNUNET_IDENTITY_PrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count, struct GNUNET_GNSRECORD_Block **result, int sign)

Referenced by dispatch_job(), and dispatch_job_monitor().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create2()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_create2 ( const struct GNUNET_IDENTITY_PrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Block **  result 
)

Sign name and records, cache derived public key (also keeps the private key in static memory, so do not use this function if keeping the private key in the process'es RAM is a major issue).

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
resultthe block buffer. Will be allocated.
Returns
GNUNET_OK on success.

Definition at line 512 of file gnsrecord_crypto.c.

682 {
683  return block_create2 (pkey, expire, label, rd, rd_count, result, GNUNET_YES);
684 }

◆ GNUNET_GNSRECORD_block_verify()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_verify ( const struct GNUNET_GNSRECORD_Block block)

Check if a signature is valid.

This API is used by the GNS Block to validate signatures received from the network.

Parameters
blockblock to verify
Returns
GNUNET_OK if the signature is valid

Definition at line 512 of file gnsrecord_crypto.c.

696 {
697  struct GNRBlockPS *purp;
698  size_t payload_len = ntohl (block->size)
699  - sizeof (struct GNUNET_GNSRECORD_Block);
701  purp = GNUNET_malloc (sizeof (struct GNRBlockPS) + payload_len);
702  purp->purpose.size = htonl (sizeof (struct GNRBlockPS) + payload_len);
704  GNUNET_memcpy (&purp[1],
705  &block[1],
706  payload_len);
707  switch (ntohl (block->type))
708  {
713  &purp->purpose,
714  &block->ecdsa_block.signature,
715  &block->ecdsa_block.derived_key);
716  break;
721  &purp->purpose,
722  &block->eddsa_block.signature,
723  &block->eddsa_block.derived_key);
724  break;
725  default:
726  res = GNUNET_NO;
727  }
728  GNUNET_free (purp);
729  return res;
730 }
#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN
GNS record set signature (GNS)
enum GNUNET_GenericReturnValue 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:631
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:690
#define GNUNET_malloc(size)
Wrapper around malloc.
Information we have in an encrypted block with record data (i.e.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
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...
uint32_t type
The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block
struct GNUNET_GNSRECORD_EddsaBlock eddsa_block
uint32_t size
Size of the block.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_CRYPTO_EddsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EddsaSignature signature
Signature of the block.

Referenced by handle_lookup_block_response().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_decrypt()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt ( const struct GNUNET_GNSRECORD_Block block,
const struct GNUNET_IDENTITY_PublicKey zone_key,
const char *  label,
GNUNET_GNSRECORD_RecordCallback  proc,
void *  proc_cls 
)

Decrypt block.

Parameters
blockblock to decrypt
zone_keypublic key of the zone
labelthe name for the records
procfunction to call with the result
proc_clsclosure for proc
Returns
GNUNET_OK on success, GNUNET_SYSERR if the block was not well-formed

Definition at line 512 of file gnsrecord_crypto.c.

991 {
993  char *norm_label;
994 
995  norm_label = GNUNET_GNSRECORD_string_normalize (label);
996  switch (ntohl (zone_key->type))
997  {
999  res = block_decrypt_ecdsa (block,
1000  &zone_key->ecdsa_key, norm_label, proc,
1001  proc_cls);
1002  break;
1004  res = block_decrypt_eddsa (block,
1005  &zone_key->eddsa_key, norm_label, proc,
1006  proc_cls);
1007  break;
1008  default:
1009  res = GNUNET_SYSERR;
1010  }
1011  GNUNET_free (norm_label);
1012  return res;
1013 }
enum GNUNET_GenericReturnValue block_decrypt_eddsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EddsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
enum GNUNET_GenericReturnValue block_decrypt_ecdsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
static const struct GNUNET_IDENTITY_PrivateKey * zone_key
Private key of the zone.
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
@ GNUNET_IDENTITY_TYPE_EDDSA
EDDSA identity.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key
An ECDSA identity key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.

Referenced by handle_block(), handle_dht_response(), and handle_namecache_block_response().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_records_cmp()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_records_cmp ( const struct GNUNET_GNSRECORD_Data a,
const struct GNUNET_GNSRECORD_Data b 
)

Compares if two records are equal.

Parameters
aa record
banother record
Returns
GNUNET_YES if the records are equal, or GNUNET_NO if not.

Compares if two records are equal.

absolute expiration time).

Parameters
arecord
brecord
Returns
GNUNET_YES if the records are equal or GNUNET_NO if they are not

Definition at line 65 of file gnsrecord_misc.c.

96 {
98  "Comparing records\n");
99  if (a->record_type != b->record_type)
100  {
102  "Record type %u != %u\n", a->record_type, b->record_type);
103  return GNUNET_NO;
104  }
105  if ((a->expiration_time != b->expiration_time) &&
106  ((a->expiration_time != 0) && (b->expiration_time != 0)))
107  {
109  "Expiration time %llu != %llu\n",
110  (unsigned long long) a->expiration_time,
111  (unsigned long long) b->expiration_time);
112  return GNUNET_NO;
113  }
116  {
118  "Flags %u (%u) != %u (%u)\n", a->flags,
121  return GNUNET_NO;
122  }
123  if (a->data_size != b->data_size)
124  {
126  "Data size %lu != %lu\n",
127  a->data_size,
128  b->data_size);
129  return GNUNET_NO;
130  }
131  if (0 != memcmp (a->data, b->data, a->data_size))
132  {
134  "Data contents do not match\n");
135  return GNUNET_NO;
136  }
138  "Records are equal\n");
139  return GNUNET_YES;
140 }
#define LOG(kind,...)
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS
Include the record types generated from GANA.
const void * data
Binary value stored in the DNS record.

◆ GNUNET_GNSRECORD_record_get_expiration_time()

struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time ( unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd,
struct GNUNET_TIME_Absolute  min 
)

Returns the expiration time of the given block of records.

The block expiration time is the expiration time of the record with smallest expiration time.

Parameters
rd_countnumber of records given in rd
rdarray of records
minminimum expiration time
Returns
absolute expiration time

Definition at line 65 of file gnsrecord_misc.c.

148 {
150  struct GNUNET_TIME_Absolute at;
151  struct GNUNET_TIME_Relative rt;
152  struct GNUNET_TIME_Absolute at_shadow;
153  struct GNUNET_TIME_Relative rt_shadow;
154 
155  if (0 == rd_count)
158  for (unsigned int c = 0; c < rd_count; c++)
159  {
160  if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
161  {
162  rt.rel_value_us = rd[c].expiration_time;
164  }
165  else
166  {
167  at.abs_value_us = rd[c].expiration_time;
168  }
169 
170  for (unsigned int c2 = 0; c2 < rd_count; c2++)
171  {
172  /* Check for shadow record */
173  if ((c == c2) ||
174  (rd[c].record_type != rd[c2].record_type) ||
175  (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW)))
176  continue;
177  /* We have a shadow record */
178  if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
179  {
180  rt_shadow.rel_value_us = rd[c2].expiration_time;
181  at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
182  }
183  else
184  {
185  at_shadow.abs_value_us = rd[c2].expiration_time;
186  }
187  at = GNUNET_TIME_absolute_max (at,
188  at_shadow);
189  }
191  expire);
192  }
195  "Determined expiration time for block with %u records to be %s\n",
196  rd_count,
198  return expire;
199 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition: time.c:367
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:616
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two absolute time values.
Definition: time.c:359
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define min(x, y)
Time for relative time used by GNUnet, in microseconds.

References buf, end, GNUNET_break, and GNUNET_STRINGS_data_to_string().

Referenced by run_edkey(), and run_pkey().

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

◆ GNUNET_GNSRECORD_block_get_size()

size_t GNUNET_GNSRECORD_block_get_size ( const struct GNUNET_GNSRECORD_Block block)

Returns the length of this block in bytes.

Block length strongly depends on the zone type.

Parameters
blockthe block.
Returns
the length of this block in bytes

Definition at line 331 of file gnsrecord_misc.c.

332 {
333  return ntohl (block->size);
334 }

Referenced by dispatch_job(), dispatch_job_monitor(), GNUNET_NAMECACHE_block_cache(), handle_dht_response(), handle_lookup_block_it(), namecache_cache_block(), namecache_sqlite_cache_block(), and store_and_free_entries().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_get_expiration()

struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_block_get_expiration ( const struct GNUNET_GNSRECORD_Block block)

Returns the expiration of a block.

Parameters
blockthe block.
Returns
the block expiration.

Definition at line 331 of file gnsrecord_misc.c.

340 {
341 
342  switch (ntohl (block->type))
343  {
348  default:
349  GNUNET_break (0); /* Hopefully we never get here, but we might */
350  }
352 
353 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:142
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737

References GNUNET_GNSRECORD_Block::size.

Referenced by expire_blocks(), handle_dht_response(), handle_lookup_block_it(), handle_namecache_block_response(), and namecache_sqlite_cache_block().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_query_from_block()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_query_from_block ( const struct GNUNET_GNSRECORD_Block block,
struct GNUNET_HashCode query 
)

Builds the query hash from a block.

Parameters
blockthe block.
querywhere to write the query hash.
Returns
GNUNET_SYSERR on error.

Definition at line 331 of file gnsrecord_misc.c.

359 {
360  switch (ntohl (block->type))
361  {
364  sizeof (block->ecdsa_block.derived_key),
365  query);
366  return GNUNET_OK;
369  sizeof (block->eddsa_block.derived_key),
370  query);
371  return GNUNET_OK;
372  default:
373  return GNUNET_SYSERR;
374  }
375  return GNUNET_SYSERR;
376 
377 }

Referenced by namecache_cache_block(), and namecache_sqlite_cache_block().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_identity_from_data()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_identity_from_data ( const char *  data,
size_t  data_size,
uint32_t  type,
struct GNUNET_IDENTITY_PublicKey key 
)

Build a #GNUNET_GNSRECORD_PublicKey from zone delegation resource record data.

Parameters
datathe record data-
data_sizethe data size.
typethe record type
keythe identity key to store the data in (must be allocated).
Returns
GNUNET_OK if successful.

Definition at line 257 of file gnsrecord_misc.c.

273 {
275  return GNUNET_SYSERR;
276  switch (type)
277  {
279  if (data_size > sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))
280  return GNUNET_SYSERR;
281  memcpy (&key->ecdsa_key, data, data_size);
282  break;
284  if (data_size > sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))
285  return GNUNET_SYSERR;
286  memcpy (&key->eddsa_key, data, data_size);
287  break;
288  default:
289  return GNUNET_NO;
290  }
291  key->type = htonl (type);
292 
293  return GNUNET_YES;
294 }
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type(uint32_t type)
Check if this type is one of the supported GNS zone types.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...

Referenced by check_pkey(), gns_value_to_string(), handle_gns_resolution_result(), and recursive_pkey_resolution().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_data_from_identity()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity ( const struct GNUNET_IDENTITY_PublicKey key,
char **  data,
size_t *  data_size,
uint32_t *  type 
)

Create record data and size from an identity key.

Parameters
keythe identity key to use.
datathe record data (will be allocated)
data_sizethe allocated data size.
typethe resulting record type
Returns
GNUNET_OK if successful.

Definition at line 257 of file gnsrecord_misc.c.

303 {
304  char *tmp;
305  *type = ntohl (key->type);
307  if (0 == *data_size)
308  return GNUNET_SYSERR;
309  tmp = GNUNET_malloc (*data_size);
310  memcpy (tmp, ((char*) key) + sizeof (key->type), *data_size);
311  *data = tmp;
312  return GNUNET_OK;
313 }
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830

References GNUNET_IDENTITY_public_key_from_string(), GNUNET_OK, GNUNET_SYSERR, and pkey.

Referenced by gns_string_to_value(), and register_do_cb().

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

◆ GNUNET_GNSRECORD_is_zonekey_type()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_zonekey_type ( uint32_t  type)

Check if this type is one of the supported GNS zone types.

Parameters
typethe type to check
Returns
GNUNET_YES if it is one of the supported types.

Definition at line 257 of file gnsrecord_misc.c.

318 {
319  switch (type)
320  {
323  return GNUNET_YES;
324  default:
325  return GNUNET_NO;
326  }
327 }

Referenced by zone_to_name().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_is_critical()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_critical ( uint32_t  type)

Check if this type is a critical record.

Parameters
typethe type to check
Returns
GNUNET_YES if it is critical.

Definition at line 227 of file gnsrecord.c.

248 {
249  struct Plugin *plugin;
250 
252  return GNUNET_NO;
253  init ();
254  for (unsigned int i = 0; i < num_plugins; i++)
255  {
256  plugin = gns_plugins[i];
257  if (NULL == plugin->api->is_critical)
258  continue;
259  if (GNUNET_NO == plugin->api->is_critical (plugin->api->cls, type))
260  continue;
261  return GNUNET_YES;
262  }
263  return GNUNET_NO;
264 }

References TestcasePlugin::api, gns_plugins, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, ret, and type.

Referenced by handle_gns_resolution_result().

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

◆ GNUNET_GNSRECORD_normalize_record_set()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_normalize_record_set ( const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count,
struct GNUNET_GNSRECORD_Data rd_public,
unsigned int *  rd_count_public,
struct GNUNET_TIME_Absolute min_expiry,
enum GNUNET_GNSRECORD_Filter  filter,
char **  emsg 
)

Normalize namestore records: Check for consistency and expirations.

Purge expired records. Returns a "clean" record set. Also returns the minimum expiration time this block should be published under. Also checks rules with respect to labels (e.g. no delegations under the empty label)

Parameters
labelthe label under which this set (supposed to be) stored.
rdinput records
rd_countsize of the rd and rd_public arrays
rd_publicwhere to write the converted records
rd_count_publicnumber of records written to rd_public
min_expirythe minimum expiration of this set
filterthe record set filter, see GNUNET_GNSRECORD_Filter.
emsgthe error message if something went wrong
Returns
GNUNET_OK if set could be normalized and is consistent

Check for delegation and redirect consistency. Note that we check for consistency BEFORE we filter for private records ON PURPOSE. We also want consistent record sets in our local zone(s). The only exception is the tombstone (above) which we ignore for the consistency check(s). FIXME: What about shadow records? Should we ignore them?

Definition at line 331 of file gnsrecord_misc.c.

417 {
418  struct GNUNET_TIME_Absolute now;
419  struct GNUNET_TIME_Absolute minimum_expiration;
420  int have_zone_delegation = GNUNET_NO;
421  int have_gns2dns = GNUNET_NO;
422  int have_other = GNUNET_NO;
423  int have_redirect = GNUNET_NO;
424  int have_empty_label = (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, label));
425  unsigned int rd_count_tmp;
426 
427  minimum_expiration = GNUNET_TIME_UNIT_ZERO_ABS;
428  now = GNUNET_TIME_absolute_get ();
429  rd_count_tmp = 0;
430  for (unsigned int i = 0; i < rd_count; i++)
431  {
432  /* Ignore private records for public record set */
434  (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)))
435  {
437  "Filtering private record filter=%u...\n", filter);
438  continue;
439  }
440  /* Skip expired records */
441  if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
442  (rd[i].expiration_time < now.abs_value_us))
443  {
445  "Filtering expired record...\n");
446  continue; /* record already expired, skip it */
447  }
448  /* Ignore the tombstone unless filter permits explicitly.
449  * Remember expiration time. */
450  if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
451  {
452  minimum_expiration.abs_value_us = rd[i].expiration_time;
454  {
455  rd_public[rd_count_tmp] = rd[i];
456  rd_count_tmp++;
457  }
458  continue;
459  }
460  /* No NICK records unless empty label */
461  if (have_empty_label &&
462  (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type))
463  continue;
464 
474  if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type))
475  {
476  /* No delegation records under empty label*/
477  if (have_empty_label)
478  {
479  *emsg = GNUNET_strdup (_ (
480  "Zone delegation record not allowed in apex."));
481  return GNUNET_SYSERR;
482  }
483  if ((GNUNET_YES == have_other) ||
484  (GNUNET_YES == have_redirect) ||
485  (GNUNET_YES == have_gns2dns))
486  {
487  *emsg = GNUNET_strdup (_ (
488  "Zone delegation record set contains mutually exclusive records."));
489  return GNUNET_SYSERR;
490  }
491  have_zone_delegation = GNUNET_YES;
492  }
493  else if (GNUNET_GNSRECORD_TYPE_REDIRECT == rd[i].record_type)
494  {
495  if (GNUNET_YES == have_redirect)
496  {
497  *emsg = GNUNET_strdup (_ (
498  "Multiple REDIRECT records."));
499  return GNUNET_SYSERR;
500 
501  }
502  if ((GNUNET_YES == have_other) ||
503  (GNUNET_YES == have_zone_delegation) ||
504  (GNUNET_YES == have_gns2dns))
505  {
506  *emsg = GNUNET_strdup (_ (
507  "Redirection record set contains mutually exclusive records."));
508  return GNUNET_SYSERR;
509  }
510  /* No redirection records under empty label*/
511  if (have_empty_label)
512  {
513  *emsg = GNUNET_strdup (_ (
514  "Redirection records not allowed in apex."));
515  return GNUNET_SYSERR;
516  }
517  have_redirect = GNUNET_YES;
518  }
519  else if (GNUNET_GNSRECORD_TYPE_GNS2DNS == rd[i].record_type)
520  {
521  /* No gns2dns records under empty label*/
522  if (have_empty_label)
523  {
524  *emsg = GNUNET_strdup (_ (
525  "Redirection records not allowed in apex.."));
526  return GNUNET_SYSERR;
527  }
528  if ((GNUNET_YES == have_other) ||
529  (GNUNET_YES == have_redirect) ||
530  (GNUNET_YES == have_zone_delegation))
531  {
532  *emsg = GNUNET_strdup (_ (
533  "Redirection record set contains mutually exclusive records."));
534  return GNUNET_SYSERR;
535  }
536  have_gns2dns = GNUNET_YES;
537  }
538  else
539  {
540  /* Some other record.
541  * Not allowed for zone delegations or redirections */
542  if ((GNUNET_YES == have_zone_delegation) ||
543  (GNUNET_YES == have_redirect) ||
544  (GNUNET_YES == have_gns2dns))
545  {
546  *emsg = GNUNET_strdup (_ (
547  "Mutually exclusive records."));
548  return GNUNET_SYSERR;
549  }
550  have_other = GNUNET_YES;
551  }
552 
553  rd_public[rd_count_tmp] = rd[i];
554  /* Make sure critical record types are marked as such */
555  if (GNUNET_YES == GNUNET_GNSRECORD_is_critical (rd[i].record_type))
556  rd_public[rd_count_tmp].flags |= GNUNET_GNSRECORD_RF_CRITICAL;
557  rd_count_tmp++;
558  }
559 
560  *expiry = GNUNET_GNSRECORD_record_get_expiration_time (rd_count_tmp,
561  rd_public,
562  minimum_expiration);
563  *rd_count_public = rd_count_tmp;
564  return GNUNET_OK;
565 }
#define GNUNET_GNSRECORD_TYPE_NICK
GNS zone nickname.
#define GNUNET_GNSRECORD_TYPE_TOMBSTONE
Record type to indicate a previously delete record (PRIVATE only)
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Delegation to DNS.
#define GNUNET_GNSRECORD_TYPE_REDIRECT
Redirection record.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute min)
Returns the expiration time of the given block of records.
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_is_critical(uint32_t type)
Check if this type is a critical record.
Definition: gnsrecord.c:247
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

Referenced by dispatch_job(), dispatch_job_monitor(), get_existing_rd_exp(), lookup_it(), and send_lookup_response_with_filter().

Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_label_check()

enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_label_check ( const char *  label,
char **  emsg 
)

Check label for invalid characters.

Parameters
labelthe label to check
emsgan error message (NULL if label is valid). Will be allocated.
Returns
GNUNET_OK if label is valid.

Definition at line 40 of file gnsrecord_misc.c.

49 {
50  if (NULL == label)
51  {
52  *emsg = GNUNET_strdup (_ ("Label is NULL which is not allowed\n"));
53  return GNUNET_NO;
54  }
55  if (0 != strchr (label, '.'))
56  {
57  *emsg = GNUNET_strdup (_ ("Label contains `.' which is not allowed\n"));
58  return GNUNET_NO;
59  }
60  return GNUNET_OK;
61 }

References GNUNET_STRINGS_utf8_normalize().

Here is the call graph for this function: