GNUnet 0.21.1
hello-ng.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_signatures.h"
28#include "gnunet_hello_lib.h"
29#include "gnunet_protocols.h"
30#include "gnunet_util_lib.h"
31
37{
42
47
52};
54
65void
67 const char *address,
69 struct GNUNET_TIME_Absolute mono_time,
70 const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key,
71 void **result,
72 size_t *result_size)
73{
74 struct SignedAddress sa;
76 char *sig_str;
77
79 sa.purpose.size = htonl (sizeof(sa));
80 sa.mono_time = GNUNET_TIME_absolute_hton (mono_time);
82 GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig);
83 sig_str = NULL;
84 (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
85 *result_size =
86 1 + GNUNET_asprintf ((char **) result,
87 "%s;%llu;%u;%s",
88 sig_str,
89 (unsigned long long) mono_time.abs_value_us,
90 (unsigned int) nt,
91 address);
92 GNUNET_free (sig_str);
93}
94
95
106char *
108 size_t raw_size,
109 const struct GNUNET_PeerIdentity *pid,
111 struct GNUNET_TIME_Absolute *mono_time)
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;
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}
180
181
189char *
191{
192 const char *dash;
193
194 dash = strchr (address, '-');
195 if (NULL == dash)
196 return NULL;
197 return GNUNET_strndup (address, dash - address);
198}
static char * address
GNS address for this phone.
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 int result
Global testing status.
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.
Constants for network protocols.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
#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_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.
Definition: hello-ng.c:66
char * GNUNET_HELLO_address_to_prefix(const char *address)
Given an address as a string, extract the prefix that identifies the communicator offering transmissi...
Definition: hello-ng.c:190
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_YES
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:44
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1724
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1622
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
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.
Definition: hello-ng.c:107
#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
Signature by a peer affirming that this is one of its addresses for the given time period.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
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...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
an ECC signature using EdDSA.
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Binary block we sign when we sign an address.
Definition: hello-ng.c:37
struct GNUNET_HashCode addr_hash
Hash of the address.
Definition: hello-ng.c:51
struct GNUNET_TIME_AbsoluteNBO mono_time
When was the address generated.
Definition: hello-ng.c:46
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS.
Definition: hello-ng.c:41