GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions | Variables
GNS Record library

Manipulate GNS record data. More...

Data Structures

struct  GNUNET_GNSRECORD_Data
 A GNS record. More...
 
struct  GNUNET_GNSRECORD_PlaceData
 Data stored in a PLACE record. More...
 
struct  GNUNET_GNSRECORD_Block
 Information we have in an encrypted block with record data (i.e. More...
 
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_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_TYPE_PKEY   65536
 Record type for GNS zone transfer ("PKEY"). More...
 
#define GNUNET_GNSRECORD_TYPE_NICK   65537
 Record type for GNS nick names ("NICK"). More...
 
#define GNUNET_GNSRECORD_TYPE_LEHO   65538
 Record type for GNS legacy hostnames ("LEHO"). More...
 
#define GNUNET_GNSRECORD_TYPE_VPN   65539
 Record type for VPN resolution. More...
 
#define GNUNET_GNSRECORD_TYPE_GNS2DNS   65540
 Record type for delegation to DNS. More...
 
#define GNUNET_GNSRECORD_TYPE_BOX   65541
 Record type for a boxed record (see TLSA/SRV handling in GNS). More...
 
#define GNUNET_GNSRECORD_TYPE_PLACE   65542
 Record type for a social place. More...
 
#define GNUNET_GNSRECORD_TYPE_PHONE   65543
 Record type for a phone (of CONVERSATION). More...
 
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR   65544
 Record type for identity attributes (of RECLAIM). More...
 
#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET   65545
 Record type for local ticket references. More...
 
#define GNUNET_GNSRECORD_TYPE_CREDENTIAL   65547
 65546 reserved More...
 
#define GNUNET_GNSRECORD_TYPE_POLICY   65548
 Record type for policies. More...
 
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE   65549
 Record type for reverse lookups. More...
 
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF   65550
 Record type for reclaim records. More...
 
#define GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER   65551
 Record type for RECLAIM master. More...
 
#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT   65552
 Record type for reclaim OIDC clients. More...
 
#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT   65553
 Record type for reclaim OIDC redirect URIs. More...
 

Enumerations

enum  GNUNET_GNSRECORD_Flags { GNUNET_GNSRECORD_RF_NONE = 0, GNUNET_GNSRECORD_RF_PRIVATE = 2, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 8, GNUNET_GNSRECORD_RF_SHADOW_RECORD }
 Flags that can be set for a record. More...
 

Functions

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 (i.e. More...
 
const char * GNUNET_GNSRECORD_number_to_typename (uint32_t type)
 Convert a type number (i.e. 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...
 
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_to_lowercase (const char *src)
 Convert a UTF-8 string to UTF-8 lowercase. More...
 
const char * GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z)
 Convert a zone to a string (for printing debug messages). More...
 
const char * GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *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_CRYPTO_EcdsaPublicKey *pkey)
 Convert an absolute domain name to the respective public key. More...
 
void GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *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_CRYPTO_EcdsaPublicKey *pub, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone. More...
 
struct GNUNET_GNSRECORD_BlockGNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Sign name and records. More...
 
struct GNUNET_GNSRECORD_BlockGNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, struct GNUNET_TIME_Absolute expire, const char *label, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 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...
 
int GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
 Check if a signature is valid. More...
 
int GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 Decrypt block. More...
 
int 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)
 Returns the expiration time of the given block of records. More...
 

Variables

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

Detailed Description

Manipulate GNS record data.

See also
Documentation

Macro Definition Documentation

◆ 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 47 of file gnunet_gnsrecord_lib.h.

Referenced by block_create().

◆ GNUNET_GNSRECORD_TYPE_ANY

#define GNUNET_GNSRECORD_TYPE_ANY   0

◆ GNUNET_GNSRECORD_TYPE_PKEY

#define GNUNET_GNSRECORD_TYPE_PKEY   65536

◆ GNUNET_GNSRECORD_TYPE_NICK

#define GNUNET_GNSRECORD_TYPE_NICK   65537

◆ GNUNET_GNSRECORD_TYPE_LEHO

#define GNUNET_GNSRECORD_TYPE_LEHO   65538

Record type for GNS legacy hostnames ("LEHO").

Definition at line 68 of file gnunet_gnsrecord_lib.h.

Referenced by dns_result_parser(), gns_string_to_value(), gns_value_to_string(), and handle_gns_result().

◆ GNUNET_GNSRECORD_TYPE_VPN

#define GNUNET_GNSRECORD_TYPE_VPN   65539

◆ GNUNET_GNSRECORD_TYPE_GNS2DNS

#define GNUNET_GNSRECORD_TYPE_GNS2DNS   65540

◆ GNUNET_GNSRECORD_TYPE_BOX

#define GNUNET_GNSRECORD_TYPE_BOX   65541

Record type for a boxed record (see TLSA/SRV handling in GNS).

Definition at line 83 of file gnunet_gnsrecord_lib.h.

Referenced by gns_string_to_value(), gns_value_to_string(), handle_gns_resolution_result(), and handle_gns_result().

◆ GNUNET_GNSRECORD_TYPE_PLACE

#define GNUNET_GNSRECORD_TYPE_PLACE   65542

Record type for a social place.

Definition at line 88 of file gnunet_gnsrecord_lib.h.

◆ GNUNET_GNSRECORD_TYPE_PHONE

#define GNUNET_GNSRECORD_TYPE_PHONE   65543

◆ GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR

#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR   65544

Record type for identity attributes (of RECLAIM).

Definition at line 98 of file gnunet_gnsrecord_lib.h.

Referenced by attr_iter_cb(), attr_store_task(), lookup_authz_cb(), process_parallel_lookup_result(), string_to_value(), and value_to_string().

◆ GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET

#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET   65545

Record type for local ticket references.

Definition at line 103 of file gnunet_gnsrecord_lib.h.

Referenced by collect_tickets_cb(), filter_tickets_cb(), issue_ticket(), string_to_value(), and value_to_string().

◆ GNUNET_GNSRECORD_TYPE_CREDENTIAL

#define GNUNET_GNSRECORD_TYPE_CREDENTIAL   65547

65546 reserved

Record type for credential

Definition at line 112 of file gnunet_gnsrecord_lib.h.

Referenced by credential_string_to_value(), credential_value_to_string(), and handle_cred_collection_cb().

◆ GNUNET_GNSRECORD_TYPE_POLICY

#define GNUNET_GNSRECORD_TYPE_POLICY   65548

Record type for policies.

Definition at line 117 of file gnunet_gnsrecord_lib.h.

Referenced by credential_string_to_value(), and credential_value_to_string().

◆ GNUNET_GNSRECORD_TYPE_ATTRIBUTE

#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE   65549

◆ GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF

#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF   65550

◆ GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER

#define GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER   65551

Record type for RECLAIM master.

Definition at line 132 of file gnunet_gnsrecord_lib.h.

Referenced by string_to_value(), and value_to_string().

◆ GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT

#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT   65552

Record type for reclaim OIDC clients.

Definition at line 137 of file gnunet_gnsrecord_lib.h.

Referenced by string_to_value(), and value_to_string().

◆ GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT

#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT   65553

Record type for reclaim OIDC redirect URIs.

Definition at line 142 of file gnunet_gnsrecord_lib.h.

Referenced by client_redirect(), lookup_redirect_uri_result(), string_to_value(), and value_to_string().

Enumeration Type Documentation

◆ GNUNET_GNSRECORD_Flags

Flags that can be set for a record.

Enumerator
GNUNET_GNSRECORD_RF_NONE 

No special options.

GNUNET_GNSRECORD_RF_PRIVATE 

This is a private record of this peer and it should thus not be handed out to other peers.

GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION 

This flag is currently unused; former RF_PENDING flag.

GNUNET_GNSRECORD_RF_UNUSED = 4, This expiration time of the record is a relative time (not an absolute time).

GNUNET_GNSRECORD_RF_SHADOW_RECORD 

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

Definition at line 147 of file gnunet_gnsrecord_lib.h.

147  {
148 
153 
159 
171 
177 
189 #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
190 };
This record should not be used unless all (other) records with an absolute expiration time have expir...
This is a private record of this peer and it should thus not be handed out to other peers...
This flag is currently unused; former RF_PENDING flag.

Function Documentation

◆ 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 143 of file gnsrecord.c.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, init(), num_plugins, plugin, and ret.

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

146 {
147  struct Plugin *plugin;
148  char *ret;
149 
150  init ();
151  for (unsigned int i = 0; i < num_plugins; i++)
152  {
153  plugin = gns_plugins[i];
154  if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
155  type,
156  data,
157  data_size)))
158  return ret;
159  }
160  return NULL;
161 }
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:100
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static unsigned int num_plugins
Size of the &#39;plugins&#39; array.
Definition: gnsrecord.c:63
Handle for a plugin.
Definition: block.c:37
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:58
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
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

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 175 of file gnsrecord.c.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_OK, GNUNET_SYSERR, init(), num_plugins, and plugin.

Referenced by gns_string_to_value(), multirecord_process(), parse_record(), and run_with_zone_pkey().

179 {
180  struct Plugin *plugin;
181 
182  init ();
183  for (unsigned int i = 0; i < num_plugins; i++)
184  {
185  plugin = gns_plugins[i];
186  if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
187  type,
188  s,
189  data,
190  data_size))
191  return GNUNET_OK;
192  }
193  return GNUNET_SYSERR;
194 }
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:100
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static unsigned int num_plugins
Size of the &#39;plugins&#39; array.
Definition: gnsrecord.c:63
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Handle for a plugin.
Definition: block.c:37
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:58
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
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 (i.e.

"AAAA") to the corresponding number.

Parameters
dns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 204 of file gnsrecord.c.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, and ret.

Referenced by del_monitor(), display_record(), get_gns_cont(), multirecord_process(), parse_record(), run(), and run_with_zone_pkey().

205 {
206  struct Plugin *plugin;
207  uint32_t ret;
208 
209  if (0 == strcasecmp (dns_typename,
210  "ANY"))
212  init ();
213  for (unsigned int i = 0; i < num_plugins; i++)
214  {
215  plugin = gns_plugins[i];
216  if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
217  dns_typename)))
218  return ret;
219  }
220  return UINT32_MAX;
221 }
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:100
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static unsigned int num_plugins
Size of the &#39;plugins&#39; array.
Definition: gnsrecord.c:63
Handle for a plugin.
Definition: block.c:37
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:58
void * cls
Closure for all of the callbacks.
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 (i.e.

1) to the corresponding type string (i.e. "A")

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

Definition at line 231 of file gnsrecord.c.

References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_GNSRECORD_TYPE_ANY, init(), num_plugins, plugin, and ret.

Referenced by display_record(), display_records_from_block(), GNUNET_JSON_from_gnsrecord(), multirecord_process(), and process_lookup_result().

232 {
233  struct Plugin *plugin;
234  const char * ret;
235 
237  return "ANY";
238  init ();
239  for (unsigned int i = 0; i < num_plugins; i++)
240  {
241  plugin = gns_plugins[i];
242  if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
243  type)))
244  return ret;
245  }
246  return NULL;
247 }
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
static void init()
Loads all plugins (lazy initialization).
Definition: gnsrecord.c:100
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static unsigned int num_plugins
Size of the &#39;plugins&#39; array.
Definition: gnsrecord.c:63
Handle for a plugin.
Definition: block.c:37
static struct Plugin ** gns_plugins
Array of our plugins.
Definition: gnsrecord.c:58
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
void * cls
Closure for all of the callbacks.
Here is the call graph for this function:
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
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 90 of file gnsrecord_serialization.c.

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

Referenced by block_create(), GNUNET_NAMESTORE_records_store(), handle_gns_resolution_result(), handle_zone_to_name_it(), lookup_it(), namestore_postgres_store_records(), namestore_sqlite_store_records(), rvk_ticket_update(), send_lookup_response(), store_and_free_entries(), and ticket_iter().

92 {
93  size_t ret;
94 
95  if (0 == rd_count)
96  return 0;
97 
98  ret = sizeof (struct NetworkRecord) * rd_count;
99  for (unsigned int i=0;i<rd_count;i++)
100  {
101  if ((ret + rd[i].data_size) < ret)
102  {
103  GNUNET_break (0);
104  return -1;
105  }
106  ret += rd[i].data_size;
107 #if DEBUG_GNSRECORDS
108  {
109  char *str;
110 
112  rd[i].data,
113  rd[i].data_size);
114  if (NULL == str)
115  {
116  GNUNET_break_op (0);
117  return -1;
118  }
119  GNUNET_free (str);
120  }
121 #endif
122  }
123  if (ret > SSIZE_MAX)
124  {
125  GNUNET_break (0);
126  return -1;
127  }
128  //Do not pad PKEY
130  return ret;
136  ret--;
137  ret |= ret >> 1;
138  ret |= ret >> 2;
139  ret |= ret >> 4;
140  ret |= ret >> 8;
141  ret |= ret >> 16;
142  ret++;
143  return (ssize_t) ret;
144 }
size_t data_size
Number of bytes in data.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
#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.
uint32_t record_type
Type of the GNS/DNS record, network byte order.
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
static size_t data_size
Number of bytes in data.
Internal format of a record in the serialized form.
#define GNUNET_free(ptr)
Wrapper around free.
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
Parameters
rd_countnumber of records in the rd array
rdarray of GNUNET_GNSRECORD_Data with rd_count elements
dest_sizesize of the destination array
destwhere to write the result
Returns
the size of serialized records, -1 if records do not fit

Definition at line 157 of file gnsrecord_serialization.c.

References data, NetworkRecord::data_size, GNUNET_GNSRECORD_Data::data_size, 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, and NetworkRecord::record_type.

Referenced by block_create(), GNUNET_NAMESTORE_records_store(), handle_gns_resolution_result(), handle_zone_to_name_it(), lookup_it(), namestore_postgres_store_records(), namestore_sqlite_store_records(), rvk_ticket_update(), send_lookup_response(), store_and_free_entries(), and ticket_iter().

161 {
162  struct NetworkRecord rec;
163  size_t off;
164 
165  off = 0;
166  for (unsigned int i=0;i<rd_count;i++)
167  {
169  "Serializing record %u with flags %d and expiration time %llu\n",
170  i,
171  rd[i].flags,
172  (unsigned long long) rd[i].expiration_time);
173  rec.expiration_time = GNUNET_htonll (rd[i].expiration_time);
174  rec.data_size = htonl ((uint32_t) rd[i].data_size);
175  rec.record_type = htonl (rd[i].record_type);
176  rec.flags = htonl (rd[i].flags);
177  if ( (off + sizeof (rec) > dest_size) ||
178  (off + sizeof (rec) < off) )
179  {
180  GNUNET_break (0);
181  return -1;
182  }
183  GNUNET_memcpy (&dest[off],
184  &rec,
185  sizeof (rec));
186  off += sizeof (rec);
187  if ( (off + rd[i].data_size > dest_size) ||
188  (off + rd[i].data_size < off) )
189  {
190  GNUNET_break (0);
191  return -1;
192  }
193  GNUNET_memcpy (&dest[off],
194  rd[i].data,
195  rd[i].data_size);
196  off += rd[i].data_size;
197 #if DEBUG_GNSRECORDS
198  {
199  char *str;
200 
202  rd[i].data,
203  rd[i].data_size);
204  if (NULL == str)
205  {
206  GNUNET_break_op (0);
207  return -1;
208  }
209  GNUNET_free (str);
210  }
211 #endif
212  }
213  memset (&dest[off],
214  0,
215  dest_size-off);
216  return dest_size;
217 }
uint32_t flags
Flags for the record, network byte order.
size_t data_size
Number of bytes in data.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_memcpy(dst, src, n)
#define LOG(kind,...)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint64_t expiration_time
Expiration time for the DNS record; relative or absolute depends on flags, network byte order...
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
uint32_t record_type
Type of the GNS/DNS record, network byte order.
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
static size_t data_size
Number of bytes in data.
Internal format of a record in the serialized form.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 in the rd array
destwhere to put the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 230 of file gnsrecord_serialization.c.

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

Referenced by check_rd(), check_result(), continue_store_activity(), database_setup(), get_records_and_call_iterator(), GNUNET_GNSRECORD_block_decrypt(), handle_lookup_result(), handle_record_result(), handle_record_store(), handle_result(), handle_zone_to_name_response(), parse_result_call_iterator(), process_tickets(), update_tickets(), and vpn_allocation_cb().

234 {
235  struct NetworkRecord rec;
236  size_t off;
237 
238  off = 0;
239  for (unsigned int i=0;i<rd_count;i++)
240  {
241  if ( (off + sizeof (rec) > len) ||
242  (off + sizeof (rec) < off) )
243  {
244  GNUNET_break_op (0);
245  return GNUNET_SYSERR;
246  }
247  GNUNET_memcpy (&rec,
248  &src[off],
249  sizeof (rec));
250  dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
251  dest[i].data_size = ntohl ((uint32_t) rec.data_size);
252  dest[i].record_type = ntohl (rec.record_type);
253  dest[i].flags = ntohl (rec.flags);
254  off += sizeof (rec);
255  if ( (off + dest[i].data_size > len) ||
256  (off + dest[i].data_size < off) )
257  {
258  GNUNET_break_op (0);
259  return GNUNET_SYSERR;
260  }
261  dest[i].data = &src[off];
262  off += dest[i].data_size;
263 #if GNUNET_EXTRA_LOGGING
264  {
265  char *str;
266 
268  dest[i].data,
269  dest[i].data_size);
270  if (NULL == str)
271  {
272  GNUNET_break_op (0);
273  return GNUNET_SYSERR;
274  }
275  GNUNET_free (str);
276  }
277 #endif
279  "Deserialized record %u with flags %d and expiration time %llu\n",
280  i,
281  dest[i].flags,
282  (unsigned long long) dest[i].expiration_time);
283  }
284  return GNUNET_OK;
285 }
uint32_t flags
Flags for the record, network byte order.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
size_t data_size
Number of bytes in data.
#define GNUNET_memcpy(dst, src, n)
const void * data
Binary value stored in the DNS record.
#define LOG(kind,...)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint64_t expiration_time
Expiration time for the DNS record.
uint64_t expiration_time
Expiration time for the DNS record; relative or absolute depends on flags, network byte order...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t record_type
Type of the GNS/DNS record.
uint32_t record_type
Type of the GNS/DNS record, network byte order.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
static size_t data_size
Number of bytes in data.
Internal format of a record in the serialized form.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 214 of file gnsrecord_misc.c.

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(), and GNUNET_YES.

215 {
216  struct GNUNET_TIME_Absolute at;
217 
219  return GNUNET_NO;
220  at.abs_value_us = rd->expiration_time;
221  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ? GNUNET_YES : GNUNET_NO;
222 }
#define GNUNET_NO
Definition: gnunet_common.h:81
uint64_t expiration_time
Expiration time for the DNS record.
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:331
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
This flag is currently unused; former RF_PENDING flag.
Here is the call graph for this function:

◆ GNUNET_GNSRECORD_string_to_lowercase()

char* GNUNET_GNSRECORD_string_to_lowercase ( const char *  src)

Convert a UTF-8 string to UTF-8 lowercase.

Parameters
srcsource string
Returns
converted result

Definition at line 46 of file gnsrecord_misc.c.

References GNUNET_strdup, GNUNET_STRINGS_utf8_tolower(), and res.

Referenced by handle_record_lookup(), and handle_record_store().

47 {
48  char *res;
49 
50  res = GNUNET_strdup (src);
51  GNUNET_STRINGS_utf8_tolower (src, res);
52  return res;
53 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static int res
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:558
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_z2s()

const char* GNUNET_GNSRECORD_z2s ( const struct GNUNET_CRYPTO_EcdsaPublicKey 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.

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
zthe zone key
Returns
string form; will be overwritten by next call to GNUNET_GNSRECORD_z2s

Definition at line 65 of file gnsrecord_misc.c.

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

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

66 {
67  static char buf[sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) * 8];
68  char *end;
69 
70  end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
71  sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
72  buf, sizeof (buf));
73  if (NULL == end)
74  {
75  GNUNET_break (0);
76  return NULL;
77  }
78  *end = '\0';
79  return buf;
80 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char buf[2048]
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
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:924
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_pkey_to_zkey()

const char* GNUNET_GNSRECORD_pkey_to_zkey ( const struct GNUNET_CRYPTO_EcdsaPublicKey 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 236 of file gnsrecord_misc.c.

References GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_free, GNUNET_snprintf(), 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().

237 {
238  static char ret[128];
239  char *pkeys;
240 
242  GNUNET_snprintf (ret,
243  sizeof (ret),
244  "%s",
245  pkeys);
246  GNUNET_free (pkeys);
247  return ret;
248 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static int ret
Final status code.
Definition: gnunet-arm.c:89
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:334
#define GNUNET_free(ptr)
Wrapper around free.
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_CRYPTO_EcdsaPublicKey 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 261 of file gnsrecord_misc.c.

References GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNS_find_tld(), and recursive_gns2dns_resolution().

263 {
264  if (GNUNET_OK !=
266  strlen (zkey),
267  pkey))
268  return GNUNET_SYSERR;
269  return GNUNET_OK;
270 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:468
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_query_from_private_key()

void GNUNET_GNSRECORD_query_from_private_key ( const struct GNUNET_CRYPTO_EcdsaPrivateKey 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 432 of file gnsrecord_crypto.c.

References GNUNET_CRYPTO_ecdsa_key_get_public(), and GNUNET_GNSRECORD_query_from_public_key().

Referenced by perform_dht_put().

435 {
437 
439  &pub);
441  label,
442  query);
443 }
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:241
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
void GNUNET_GNSRECORD_query_from_public_key(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, struct GNUNET_HashCode *query)
Calculate the DHT query for a given label in a given zone.
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_CRYPTO_EcdsaPublicKey pub,
const char *  label,
struct GNUNET_HashCode query 
)

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

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

Definition at line 454 of file gnsrecord_crypto.c.

References GNUNET_CRYPTO_ecdsa_public_key_derive(), and GNUNET_CRYPTO_hash().

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

457 {
459 
461  label,
462  "gns",
463  &pd);
464  GNUNET_CRYPTO_hash (&pd,
465  sizeof (pd),
466  query);
467 }
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.
Definition: crypto_ecc.c:1339
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create()

struct GNUNET_GNSRECORD_Block* GNUNET_GNSRECORD_block_create ( const struct GNUNET_CRYPTO_EcdsaPrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

Sign name and records.

Parameters
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records in rd
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records
Returns
NULL on error (block too large)

Definition at line 190 of file gnsrecord_crypto.c.

References block_create(), and GNUNET_CRYPTO_ecdsa_key_get_public().

Referenced by perform_dht_put(), and refresh_block().

195 {
197 
199  &pkey);
200  return block_create (key,
201  &pkey,
202  expire,
203  label,
204  rd,
205  rd_count);
206 }
static char * pkey
Public key of the zone to look in, in ASCII.
struct GNUNET_GNSRECORD_Block * block_create(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)
Sign name and records.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:241
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_create2()

struct GNUNET_GNSRECORD_Block* GNUNET_GNSRECORD_block_create2 ( const struct GNUNET_CRYPTO_EcdsaPrivateKey key,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

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
keythe private key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records
Returns
NULL on error (block too large)

Definition at line 240 of file gnsrecord_crypto.c.

References block_create(), CSIZE, GNUNET_CRYPTO_ecdsa_key_get_public(), KeyCacheLine::key, line, and KeyCacheLine::pkey.

Referenced by perform_dht_put(), and refresh_block().

245 {
246 #define CSIZE 64
247  static struct KeyCacheLine cache[CSIZE];
248  struct KeyCacheLine *line;
249 
250  line = &cache[(*(unsigned int *) key) % CSIZE];
251  if (0 != memcmp (&line->key,
252  key,
253  sizeof (*key)))
254  {
255  /* cache miss, recompute */
256  line->key = *key;
258  &line->pkey);
259  }
260 #undef CSIZE
261  return block_create (key,
262  &line->pkey,
263  expire,
264  label,
265  rd,
266  rd_count);
267 }
struct GNUNET_GNSRECORD_Block * block_create(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)
Sign name and records.
static char * line
Desired phone line (string to be converted to a hash).
#define CSIZE
struct GNUNET_HashCode key
The key used in the DHT.
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:241
static struct GNUNET_CONTAINER_MultiHashMap32 * cache
Hashmap to maintain cache.
Line in cache mapping private keys to public keys.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_verify()

int 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 279 of file gnsrecord_crypto.c.

References GNUNET_GNSRECORD_Block::derived_key, GNUNET_CRYPTO_ecdsa_verify(), GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, GNUNET_GNSRECORD_Block::purpose, and GNUNET_GNSRECORD_Block::signature.

Referenced by block_plugin_gns_evaluate(), and handle_lookup_block_response().

280 {
282  &block->purpose,
283  &block->signature,
284  &block->derived_key);
285 }
int 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:1048
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN
Signature of a gnunet naming system record block.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_block_decrypt()

int GNUNET_GNSRECORD_block_decrypt ( const struct GNUNET_GNSRECORD_Block block,
const struct GNUNET_CRYPTO_EcdsaPublicKey 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
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 300 of file gnsrecord_crypto.c.

References GNUNET_TIME_Absolute::abs_value_us, derive_block_aes_key(), GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_break, GNUNET_break_op, GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_ERROR_TYPE_INFO, GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW_RECORD, GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, payload, GNUNET_GNSRECORD_Block::purpose, and GNUNET_CRYPTO_EccSignaturePurpose::size.

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

305 {
306  size_t payload_len = ntohl (block->purpose.size) -
307  sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) -
308  sizeof (struct GNUNET_TIME_AbsoluteNBO);
311 
312  if (ntohl (block->purpose.size) <
313  sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
314  sizeof (struct GNUNET_TIME_AbsoluteNBO))
315  {
316  GNUNET_break_op (0);
317  return GNUNET_SYSERR;
318  }
320  &skey,
321  label,
322  zone_key);
323  {
324  char payload[payload_len];
325  uint32_t rd_count;
326 
327  GNUNET_break (payload_len ==
328  GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len,
329  &skey, &iv,
330  payload));
331  GNUNET_memcpy (&rd_count,
332  payload,
333  sizeof (uint32_t));
334  rd_count = ntohl (rd_count);
335  if (rd_count > 2048)
336  {
337  /* limit to sane value */
338  GNUNET_break_op (0);
339  return GNUNET_SYSERR;
340  }
341  {
342  struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
343  unsigned int j;
344  struct GNUNET_TIME_Absolute now;
345 
346  if (GNUNET_OK !=
347  GNUNET_GNSRECORD_records_deserialize (payload_len - sizeof (uint32_t),
348  &payload[sizeof (uint32_t)],
349  rd_count,
350  rd))
351  {
352  GNUNET_break_op (0);
353  return GNUNET_SYSERR;
354  }
355  /* hide expired records */
356  now = GNUNET_TIME_absolute_get ();
357  j = 0;
358  for (unsigned int i=0;i<rd_count;i++)
359  {
360  if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
361  {
362  /* encrypted blocks must never have relative expiration times, skip! */
363  GNUNET_break_op (0);
364  continue;
365  }
366 
367  if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD))
368  {
369  int include_record = GNUNET_YES;
370  /* Shadow record, figure out if we have a not expired active record */
371  for (unsigned int k=0;k<rd_count;k++)
372  {
373  if (k == i)
374  continue;
375  if (rd[i].expiration_time < now.abs_value_us)
376  include_record = GNUNET_NO; /* Shadow record is expired */
377  if ( (rd[k].record_type == rd[i].record_type) &&
378  (rd[k].expiration_time >= now.abs_value_us) &&
379  (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
380  {
381  include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
383  "Ignoring shadow record\n");
384  break;
385  }
386  }
387  if (GNUNET_YES == include_record)
388  {
389  rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW_RECORD; /* Remove Flag */
390  if (j != i)
391  rd[j] = rd[i];
392  j++;
393  }
394  }
395  else if (rd[i].expiration_time >= now.abs_value_us)
396  {
397  /* Include this record */
398  if (j != i)
399  rd[j] = rd[i];
400  j++;
401  }
402  else
403  {
404  struct GNUNET_TIME_Absolute at;
405 
406  at.abs_value_us = rd[i].expiration_time;
408  "Excluding record that expired %s (%llu ago)\n",
410  (unsigned long long) rd[i].expiration_time - now.abs_value_us);
411  }
412  }
413  rd_count = j;
414  if (NULL != proc)
415  proc (proc_cls,
416  rd_count,
417  (0 != rd_count) ? rd : NULL);
418  }
419  }
420  return GNUNET_OK;
421 }
This record should not be used unless all (other) records with an absolute expiration time have expir...
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned long long payload
How much data are we currently storing in the database?
static void derive_block_aes_key(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const char *label, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive session key and iv from label and public key.
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
This flag is currently unused; former RF_PENDING flag.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_GNSRECORD_records_cmp()

int 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 93 of file gnsrecord_misc.c.

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_RF_RCMP_FLAGS, GNUNET_NO, GNUNET_YES, LOG, and GNUNET_GNSRECORD_Data::record_type.

95 {
97  "Comparing records\n");
98  if (a->record_type != b->record_type)
99  {
101  "Record type %lu != %lu\n", a->record_type, b->record_type);
102  return GNUNET_NO;
103  }
104  if ((a->expiration_time != b->expiration_time) &&
105  ((a->expiration_time != 0) && (b->expiration_time != 0)))
106  {
108  "Expiration time %llu != %llu\n",
109  a->expiration_time,
110  b->expiration_time);
111  return GNUNET_NO;
112  }
115  {
117  "Flags %lu (%lu) != %lu (%lu)\n", a->flags,
120  return GNUNET_NO;
121  }
122  if (a->data_size != b->data_size)
123  {
125  "Data size %lu != %lu\n",
126  a->data_size,
127  b->data_size);
128  return GNUNET_NO;
129  }
130  if (0 != memcmp (a->data, b->data, a->data_size))
131  {
133  "Data contents do not match\n");
134  return GNUNET_NO;
135  }
137  "Records are equal\n");
138  return GNUNET_YES;
139 }
#define GNUNET_NO
Definition: gnunet_common.h:81
size_t data_size
Number of bytes in data.
const void * data
Binary value stored in the DNS record.
#define LOG(kind,...)
uint64_t expiration_time
Expiration time for the DNS record.
#define GNUNET_GNSRECORD_RF_RCMP_FLAGS
uint32_t record_type
Type of the GNS/DNS record.
#define GNUNET_YES
Definition: gnunet_common.h:80
enum GNUNET_GNSRECORD_Flags flags
Flags for the 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 
)

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
Returns
absolute expiration time

Definition at line 152 of file gnsrecord_misc.c.

References GNUNET_TIME_Absolute::abs_value_us, expire(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW_RECORD, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_max(), GNUNET_TIME_absolute_min(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_ZERO_ABS, LOG, and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_JSON_from_gnsrecord(), perform_dht_put(), and refresh_block().

154 {
156  struct GNUNET_TIME_Absolute at;
157  struct GNUNET_TIME_Relative rt;
158  struct GNUNET_TIME_Absolute at_shadow;
159  struct GNUNET_TIME_Relative rt_shadow;
160 
161  if (NULL == rd)
164  for (unsigned int c = 0; c < rd_count; c++)
165  {
166  if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
167  {
168  rt.rel_value_us = rd[c].expiration_time;
170  }
171  else
172  {
173  at.abs_value_us = rd[c].expiration_time;
174  }
175 
176  for (unsigned int c2 = 0; c2 < rd_count; c2++)
177  {
178  /* Check for shadow record */
179  if ( (c == c2) ||
180  (rd[c].record_type != rd[c2].record_type) ||
181  (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
182  continue;
183  /* We have a shadow record */
184  if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
185  {
186  rt_shadow.rel_value_us = rd[c2].expiration_time;
187  at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
188  }
189  else
190  {
191  at_shadow.abs_value_us = rd[c2].expiration_time;
192  }
193  at = GNUNET_TIME_absolute_max (at,
194  at_shadow);
195  }
197  expire);
198  }
200  "Determined expiration time for block with %u records to be %s\n",
201  rd_count,
203  return expire;
204 }
This record should not be used unless all (other) records with an absolute expiration time have expir...
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static void expire(void *cls)
Expire a PooledConnection object.
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:245
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define LOG(kind,...)
uint64_t expiration_time
Expiration time for the DNS record.
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:317
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:302
Time for absolute times used by GNUnet, in microseconds.
This flag is currently unused; former RF_PENDING flag.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ GNUNET_GNSRECORD_RecordCallback

GNUNET_NETWORK_STRUCT_END 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 346 of file gnunet_gnsrecord_lib.h.