GNUnet 0.22.0
hello-ng.c File Reference

helper library for handling HELLOs More...

#include "platform.h"
#include "gnunet_signatures.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
Include dependency graph for hello-ng.c:

Go to the source code of this file.

Data Structures

struct  SignedAddress
 Binary block we sign when we sign an address. More...
 

Functions

GNUNET_NETWORK_STRUCT_END void GNUNET_HELLO_sign_address (const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Absolute mono_time, const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, void **result, size_t *result_size)
 Build address record by signing raw information with private key. More...
 
char * GNUNET_HELLO_extract_address (const void *raw, size_t raw_size, const struct GNUNET_PeerIdentity *pid, enum GNUNET_NetworkType *nt, struct GNUNET_TIME_Absolute *mono_time)
 Check signature and extract address record. More...
 
char * GNUNET_HELLO_address_to_prefix (const char *address)
 Given an address as a string, extract the prefix that identifies the communicator offering transmissions to that address. More...
 

Detailed Description

helper library for handling HELLOs

Author
Christian Grothoff

Definition in file hello-ng.c.

Function Documentation

◆ GNUNET_HELLO_extract_address()

char * GNUNET_HELLO_extract_address ( const void *  raw,
size_t  raw_size,
const struct GNUNET_PeerIdentity pid,
enum GNUNET_NetworkType nt,
struct GNUNET_TIME_Absolute mono_time 
)

Check signature and extract address record.

Parameters
rawraw signed address
raw_sizesize of raw
pidpublic key to use for signature verification
nt[out]set to network type
mono_time[out]when was the address generated
Returns
NULL on error, otherwise the address

Definition at line 107 of file hello-ng.c.

112{
113 const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key;
114 const char *raws = raw;
115 unsigned long long raw_us = 0;
116 unsigned int raw_nt = 0;
117 const char *sc;
118 const char *sc2;
119 const char *sc3;
120 const char *raw_addr;
121 char *data = NULL;
122 struct GNUNET_TIME_Absolute raw_mono_time;
123 struct SignedAddress sa;
125
126 if ('\0' != raws[raw_size-1])
127 {
128 GNUNET_break_op (0);
129 return NULL;
130 }
131 if (NULL == (sc = strchr (raws, ';')))
132 {
133 GNUNET_break_op (0);
134 return NULL;
135 }
136 if (NULL == (sc2 = strchr (sc + 1, ';')))
137 {
138 GNUNET_break_op (0);
139 return NULL;
140 }
141 if (NULL == (sc3 = strchr (sc2 + 1, ';')))
142 {
143 GNUNET_break_op (0);
144 return NULL;
145 }
146 if (2 != sscanf (sc + 1, "%llu;%u;%*s", &raw_us, &raw_nt))
147 {
148 GNUNET_break_op (0);
149 return NULL;
150 }
151 raw_addr = sc3 + 1;
152 raw_mono_time.abs_value_us = raw_us;
153 if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) !=
154 GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &data))
155 {
156 GNUNET_break_op (0);
158 return NULL;
159 }
160 sig = (struct GNUNET_CRYPTO_EddsaSignature*) data;
161 sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
162 sa.purpose.size = htonl (sizeof(sa));
163 sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time);
164 GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.addr_hash);
165 if (GNUNET_YES !=
167 &sa,
168 sig,
169 public_key))
170 {
172 GNUNET_break_op (0);
173 return NULL;
174 }
176 *mono_time = raw_mono_time;
177 *nt = raw_nt;
178 return GNUNET_strdup (raw_addr);
179}
static char * data
The data to insert into the dht.
static int raw
raw output
Definition: gnunet-gns.c:78
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
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
@ GNUNET_YES
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1747
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses for the given time period.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using EdDSA.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Time for absolute times used by GNUnet, in microseconds.
Binary block we sign when we sign an address.
Definition: hello-ng.c:37

References GNUNET_TIME_Absolute::abs_value_us, SignedAddress::addr_hash, data, GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify, GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, GNUNET_strdup, GNUNET_STRINGS_base64_decode(), GNUNET_TIME_absolute_hton(), GNUNET_YES, SignedAddress::mono_time, nt, pid, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, SignedAddress::purpose, raw, sc, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Here is the call graph for this function: