diff options
Diffstat (limited to 'src/hello/hello-ng.c')
-rw-r--r-- | src/hello/hello-ng.c | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/src/hello/hello-ng.c b/src/hello/hello-ng.c deleted file mode 100644 index 96856a692..000000000 --- a/src/hello/hello-ng.c +++ /dev/null | |||
@@ -1,197 +0,0 @@ | |||
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 | |||
21 | /** | ||
22 | * @file hello/hello-ng.c | ||
23 | * @brief helper library for handling HELLOs | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
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 | #include "gnunet_ats_service.h" | ||
32 | |||
33 | GNUNET_NETWORK_STRUCT_BEGIN | ||
34 | /** | ||
35 | * Binary block we sign when we sign an address. | ||
36 | */ | ||
37 | struct SignedAddress | ||
38 | { | ||
39 | /** | ||
40 | * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS | ||
41 | */ | ||
42 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
43 | |||
44 | /** | ||
45 | * When was the address generated. | ||
46 | */ | ||
47 | struct GNUNET_TIME_AbsoluteNBO mono_time; | ||
48 | |||
49 | /** | ||
50 | * Hash of the address. | ||
51 | */ | ||
52 | struct GNUNET_HashCode addr_hash GNUNET_PACKED; | ||
53 | }; | ||
54 | GNUNET_NETWORK_STRUCT_END | ||
55 | |||
56 | /** | ||
57 | * Build address record by signing raw information with private key. | ||
58 | * | ||
59 | * @param address text address at @a communicator to sign | ||
60 | * @param nt network type of @a address | ||
61 | * @param mono_time monotonic time at which @a address was valid | ||
62 | * @param private_key signing key to use | ||
63 | * @param result[out] where to write address record (allocated) | ||
64 | * @param result_size[out] set to size of @a result | ||
65 | */ | ||
66 | void | ||
67 | GNUNET_HELLO_sign_address ( | ||
68 | const char *address, | ||
69 | enum GNUNET_NetworkType nt, | ||
70 | struct GNUNET_TIME_Absolute mono_time, | ||
71 | const struct GNUNET_CRYPTO_EddsaPrivateKey *private_key, | ||
72 | void **result, | ||
73 | size_t *result_size) | ||
74 | { | ||
75 | struct SignedAddress sa; | ||
76 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
77 | char *sig_str; | ||
78 | |||
79 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | ||
80 | sa.purpose.size = htonl (sizeof(sa)); | ||
81 | sa.mono_time = GNUNET_TIME_absolute_hton (mono_time); | ||
82 | GNUNET_CRYPTO_hash (address, strlen (address), &sa.addr_hash); | ||
83 | GNUNET_CRYPTO_eddsa_sign (private_key, &sa, &sig); | ||
84 | sig_str = NULL; | ||
85 | (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str); | ||
86 | *result_size = | ||
87 | 1 + GNUNET_asprintf ((char **) result, | ||
88 | "%s;%llu;%u;%s", | ||
89 | sig_str, | ||
90 | (unsigned long long) mono_time.abs_value_us, | ||
91 | (unsigned int) nt, | ||
92 | address); | ||
93 | GNUNET_free (sig_str); | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Check signature and extract address record. | ||
99 | * | ||
100 | * @param raw raw signed address | ||
101 | * @param raw_size size of @a raw | ||
102 | * @param pid public key to use for signature verification | ||
103 | * @param nt[out] set to network type | ||
104 | * @param mono_time[out] when was the address generated | ||
105 | * @return NULL on error, otherwise the address | ||
106 | */ | ||
107 | char * | ||
108 | GNUNET_HELLO_extract_address (const void *raw, | ||
109 | size_t raw_size, | ||
110 | const struct GNUNET_PeerIdentity *pid, | ||
111 | enum GNUNET_NetworkType *nt, | ||
112 | struct GNUNET_TIME_Absolute *mono_time) | ||
113 | { | ||
114 | const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; | ||
115 | const char *raws = raw; | ||
116 | unsigned long long raw_us = 0; | ||
117 | unsigned int raw_nt = 0; | ||
118 | const char *sc; | ||
119 | const char *sc2; | ||
120 | const char *sc3; | ||
121 | const char *raw_addr; | ||
122 | char *data = NULL; | ||
123 | struct GNUNET_TIME_Absolute raw_mono_time; | ||
124 | struct SignedAddress sa; | ||
125 | struct GNUNET_CRYPTO_EddsaSignature *sig; | ||
126 | |||
127 | if ('\0' != raws[raw_size-1]) | ||
128 | { | ||
129 | GNUNET_break_op (0); | ||
130 | return NULL; | ||
131 | } | ||
132 | if (NULL == (sc = strchr (raws, ';'))) | ||
133 | { | ||
134 | GNUNET_break_op (0); | ||
135 | return NULL; | ||
136 | } | ||
137 | if (NULL == (sc2 = strchr (sc + 1, ';'))) | ||
138 | { | ||
139 | GNUNET_break_op (0); | ||
140 | return NULL; | ||
141 | } | ||
142 | if (NULL == (sc3 = strchr (sc2 + 1, ';'))) | ||
143 | { | ||
144 | GNUNET_break_op (0); | ||
145 | return NULL; | ||
146 | } | ||
147 | if (2 != sscanf (sc + 1, "%llu;%u;%*s", &raw_us, &raw_nt)) | ||
148 | { | ||
149 | GNUNET_break_op (0); | ||
150 | return NULL; | ||
151 | } | ||
152 | raw_addr = sc3 + 1; | ||
153 | raw_mono_time.abs_value_us = raw_us; | ||
154 | if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) != | ||
155 | GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &data)) | ||
156 | { | ||
157 | GNUNET_break_op (0); | ||
158 | GNUNET_free (data); | ||
159 | return NULL; | ||
160 | } | ||
161 | sig = (struct GNUNET_CRYPTO_EddsaSignature*) data; | ||
162 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | ||
163 | sa.purpose.size = htonl (sizeof(sa)); | ||
164 | sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time); | ||
165 | GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.addr_hash); | ||
166 | if (GNUNET_YES != | ||
167 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, | ||
168 | &sa, | ||
169 | sig, | ||
170 | public_key)) | ||
171 | { | ||
172 | GNUNET_break_op (0); | ||
173 | return NULL; | ||
174 | } | ||
175 | *mono_time = raw_mono_time; | ||
176 | *nt = raw_nt; | ||
177 | return GNUNET_strdup (raw_addr); | ||
178 | } | ||
179 | |||
180 | |||
181 | /** | ||
182 | * Given an address as a string, extract the prefix that identifies | ||
183 | * the communicator offering transmissions to that address. | ||
184 | * | ||
185 | * @param address a peer's address | ||
186 | * @return NULL if the address is mal-formed, otherwise the prefix | ||
187 | */ | ||
188 | char * | ||
189 | GNUNET_HELLO_address_to_prefix (const char *address) | ||
190 | { | ||
191 | const char *dash; | ||
192 | |||
193 | dash = strchr (address, '-'); | ||
194 | if (NULL == dash) | ||
195 | return NULL; | ||
196 | return GNUNET_strndup (address, dash - address); | ||
197 | } | ||