GNUnet  0.11.x
Macros | Functions
gnunet-gnsrecord-tvg.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_signatures.h"
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_testing_lib.h"
#include <inttypes.h>
Include dependency graph for gnunet-gnsrecord-tvg.c:

Go to the source code of this file.


#define TEST_RECORD_LABEL   "test"
#define TEST_RECORD_A   ""
#define TEST_RRCOUNT   2


static void print_bytes (void *buf, size_t buf_len, int fold)
static void print_record (const struct GNUNET_GNSRECORD_Data *rd)
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run. More...
int main (int argc, char *const *argv)
 The main function of the test vector generation tool. More...

Macro Definition Documentation


#define TEST_RECORD_LABEL   "test"

Definition at line 35 of file gnunet-gnsrecord-tvg.c.

Referenced by run().


#define TEST_RECORD_A   ""

Definition at line 36 of file gnunet-gnsrecord-tvg.c.

Referenced by run().


#define TEST_RRCOUNT   2

Definition at line 37 of file gnunet-gnsrecord-tvg.c.

Referenced by run().

Function Documentation

◆ print_bytes()

static void print_bytes ( void *  buf,
size_t  buf_len,
int  fold 

Definition at line 40 of file gnunet-gnsrecord-tvg.c.

Referenced by print_record(), and run().

43 {
44  int i;
46  for (i = 0; i < buf_len; i++)
47  {
48  if ((0 != i) && (0 != fold) && (i % fold == 0))
49  printf ("\n");
50  printf ("%02x", ((unsigned char*) buf)[i]);
51  }
52  printf ("\n");
53 }
static char buf[2048]
Here is the caller graph for this function:

◆ print_record()

static void print_record ( const struct GNUNET_GNSRECORD_Data rd)

Definition at line 57 of file gnunet-gnsrecord-tvg.c.

References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, print_bytes(), and GNUNET_GNSRECORD_Data::record_type.

Referenced by run().

58 {
60  fprintf (stdout,
61  "EXPIRATION: %" PRIu64 "\n", rd->expiration_time);
62  fprintf (stdout,
63  "DATA_SIZE: %zu\n", rd->data_size);
64  fprintf (stdout,
65  "TYPE: %d\n", rd->record_type);
66  fprintf (stdout,
67  "FLAGS: %d\n", rd->flags);
68  fprintf (stdout,
69  "DATA:\n");
70  print_bytes ((char*) rd->data, rd->data_size, 8);
71  fprintf (stdout, "\n");
72 }
size_t data_size
Number of bytes in data.
static void print_bytes(void *buf, size_t buf_len, int fold)
const void * data
Binary value stored in the DNS record.
uint64_t expiration_time
Expiration time for the DNS record.
uint32_t record_type
Type of the GNS/DNS record.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 

Main function that will be run.

argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)

Definition at line 84 of file gnunet-gnsrecord-tvg.c.

References GNUNET_TIME_Absolute::abs_value_us, data, GNUNET_GNSRECORD_Data::data, data_size, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Block::ecdsa_block, GNUNET_IDENTITY_PrivateKey::ecdsa_key, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_assert, GNUNET_CRYPTO_ecdsa_key_create(), GNUNET_DNSPARSER_TYPE_A, GNUNET_GNSRECORD_block_create(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_string_to_value(), GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_IDENTITY_key_get_length(), GNUNET_IDENTITY_key_get_public(), GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_data_to_string(), GNUNET_TIME_absolute_get(), print_bytes(), print_record(), GNUNET_GNSRECORD_EcdsaBlock::purpose, GNUNET_GNSRECORD_Data::record_type, GNUNET_CRYPTO_EccSignaturePurpose::size, TEST_RECORD_A, TEST_RECORD_LABEL, TEST_RRCOUNT, and GNUNET_IDENTITY_PrivateKey::type.

Referenced by main().

88 {
89  struct GNUNET_GNSRECORD_Data rd[2];
91  struct GNUNET_GNSRECORD_Block *rrblock;
92  char *bdata;
93  struct GNUNET_IDENTITY_PrivateKey id_priv;
94  struct GNUNET_IDENTITY_PublicKey id_pub;
95  struct GNUNET_IDENTITY_PrivateKey pkey_data_p;
96  struct GNUNET_IDENTITY_PublicKey pkey_data;
97  void *data;
98  size_t data_size;
99  char *rdata;
100  size_t rdata_size;
101  char ztld[128];
103  id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
104  GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key);
106  &id_pub);
107  fprintf (stdout, "Zone private key (d, little-endian, with ztype prepended):\n");
108  print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); //FIXME length for privkey?
109  fprintf (stdout, "\n");
110  fprintf (stdout, "Zone identifier (zid):\n");
111  print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
114  ztld,
115  sizeof (ztld));
116  fprintf (stdout, "\n");
117  fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n");
118  fprintf (stdout, "%s\n", ztld);
119  fprintf (stdout, "\n");
121  pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
122  GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p.ecdsa_key);
123  GNUNET_IDENTITY_key_get_public (&pkey_data_p,
124  &pkey_data);
125  fprintf (stdout,
126  "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT);
127  memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2);
129  GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size));
130  rd[0].data = data;
131  rd[0].data_size = data_size;
132  rd[0].expiration_time = exp_abs.abs_value_us;
133  rd[0].record_type = GNUNET_DNSPARSER_TYPE_A;
134  fprintf (stdout, "Record #0\n");
135  print_record (&rd[0]);
137  rd[1].data = &pkey_data;
138  rd[1].data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
139  rd[1].expiration_time = exp_abs.abs_value_us;
140  rd[1].record_type = GNUNET_GNSRECORD_TYPE_PKEY;
142  fprintf (stdout, "Record #1\n");
143  print_record (&rd[1]);
145  rdata_size = GNUNET_GNSRECORD_records_get_size (2,
146  rd);
147  rdata = GNUNET_malloc (rdata_size);
149  rd,
150  rdata_size,
151  rdata);
152  fprintf (stdout, "RDATA:\n");
153  print_bytes (rdata, rdata_size, 8);
154  fprintf (stdout, "\n");
155  rrblock = GNUNET_GNSRECORD_block_create (&id_priv,
156  exp_abs,
158  rd,
160  size_t bdata_size = ntohl (rrblock->ecdsa_block.purpose.size)
161  - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
162  - sizeof(struct GNUNET_TIME_AbsoluteNBO);
163  size_t ecblock_size = ntohl (rrblock->ecdsa_block.purpose.size)
164  + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
165  + sizeof(struct GNUNET_CRYPTO_EcdsaSignature);
166  size_t block_size = ecblock_size + sizeof (uint32_t);
168  bdata = (char*) &(&rrblock->ecdsa_block)[1];
169  fprintf (stdout, "BDATA:\n");
170  print_bytes (bdata, bdata_size, 8);
171  fprintf (stdout, "\n");
172  fprintf (stdout, "RRBLOCK:\n");
173  print_bytes (rrblock, block_size, 8);
174  fprintf (stdout, "\n");
176 }
GNUNET_NETWORK_STRUCT_END 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.
struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block
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.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
ssize_t GNUNET_IDENTITY_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:976
static void print_record(const struct GNUNET_GNSRECORD_Data *rd)
A private key for an identity as per LSD0001.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
struct GNUNET_GNSRECORD_Block * 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)
Sign name and records.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
static void print_bytes(void *buf, size_t buf_len, int fold)
Record type for GNS zone transfer ("PKEY").
an ECC signature using ECDSA
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:175
This is a private record of this peer and it should thus not be handed out to other peers...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a &#39;value&#39; of a record to the binary representation.
Definition: gnsrecord.c:191
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
An identity key as per LSD0001.
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:430
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
Time for absolute times used by GNUnet, in microseconds.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
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:872
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 

The main function of the test vector generation tool.

argcnumber of arguments from the command line
argvcommand line arguments
0 ok, 1 on error

Definition at line 187 of file gnunet-gnsrecord-tvg.c.

References GNUNET_assert, GNUNET_GETOPT_OPTION_END, GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), and run().

189 {
190  const struct GNUNET_GETOPT_CommandLineOption options[] = {
192  };
195  GNUNET_log_setup ("gnunet-gns-tvg",
196  "INFO",
197  NULL));
198  if (GNUNET_OK !=
199  GNUNET_PROGRAM_run (argc, argv,
200  "gnunet-gns-tvg",
201  "Generate test vectors for GNS",
202  options,
203  &run, NULL))
204  return 1;
205  return 0;
206 }
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:363
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Definition of a command line option.
Definition: 002.c:13
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
Here is the call graph for this function: