diff options
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/.gitignore | 1 | ||||
-rw-r--r-- | src/gnsrecord/Makefile.am | 12 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord.c | 36 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_crypto.c | 142 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 18 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_serialization.c | 158 | ||||
-rw-r--r-- | src/gnsrecord/perf_gnsrecord_crypto.c | 135 | ||||
-rw-r--r-- | src/gnsrecord/plugin_gnsrecord_dns.c | 18 | ||||
-rw-r--r-- | src/gnsrecord/test_gnsrecord_block_expiration.c | 18 | ||||
-rw-r--r-- | src/gnsrecord/test_gnsrecord_crypto.c | 27 | ||||
-rw-r--r-- | src/gnsrecord/test_gnsrecord_serialization.c | 124 |
11 files changed, 472 insertions, 217 deletions
diff --git a/src/gnsrecord/.gitignore b/src/gnsrecord/.gitignore index 374abdb60..53d3bb22d 100644 --- a/src/gnsrecord/.gitignore +++ b/src/gnsrecord/.gitignore | |||
@@ -2,3 +2,4 @@ test_gnsrecord_block_expiration | |||
2 | test_gnsrecord_crypto | 2 | test_gnsrecord_crypto |
3 | test_gnsrecord_serialization | 3 | test_gnsrecord_serialization |
4 | zonefiles | 4 | zonefiles |
5 | perf_gnsrecord_crypto | ||
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am index 2fb427c69..f840a31a4 100644 --- a/src/gnsrecord/Makefile.am +++ b/src/gnsrecord/Makefile.am | |||
@@ -19,7 +19,8 @@ endif | |||
19 | check_PROGRAMS = \ | 19 | check_PROGRAMS = \ |
20 | test_gnsrecord_crypto \ | 20 | test_gnsrecord_crypto \ |
21 | test_gnsrecord_serialization \ | 21 | test_gnsrecord_serialization \ |
22 | test_gnsrecord_block_expiration | 22 | test_gnsrecord_block_expiration \ |
23 | perf_gnsrecord_crypto | ||
23 | 24 | ||
24 | if ENABLE_TEST_RUN | 25 | if ENABLE_TEST_RUN |
25 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 26 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
@@ -37,7 +38,6 @@ libgnunetgnsrecord_la_SOURCES = \ | |||
37 | gnsrecord_crypto.c \ | 38 | gnsrecord_crypto.c \ |
38 | gnsrecord_misc.c | 39 | gnsrecord_misc.c |
39 | libgnunetgnsrecord_la_LIBADD = \ | 40 | libgnunetgnsrecord_la_LIBADD = \ |
40 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ | ||
41 | $(top_builddir)/src/util/libgnunetutil.la \ | 41 | $(top_builddir)/src/util/libgnunetutil.la \ |
42 | $(GN_LIBINTL) | 42 | $(GN_LIBINTL) |
43 | libgnunetgnsrecord_la_LDFLAGS = \ | 43 | libgnunetgnsrecord_la_LDFLAGS = \ |
@@ -52,7 +52,6 @@ plugin_LTLIBRARIES = \ | |||
52 | libgnunet_plugin_gnsrecord_dns_la_SOURCES = \ | 52 | libgnunet_plugin_gnsrecord_dns_la_SOURCES = \ |
53 | plugin_gnsrecord_dns.c | 53 | plugin_gnsrecord_dns.c |
54 | libgnunet_plugin_gnsrecord_dns_la_LIBADD = \ | 54 | libgnunet_plugin_gnsrecord_dns_la_LIBADD = \ |
55 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ | ||
56 | $(top_builddir)/src/util/libgnunetutil.la \ | 55 | $(top_builddir)/src/util/libgnunetutil.la \ |
57 | $(LTLIBINTL) | 56 | $(LTLIBINTL) |
58 | libgnunet_plugin_gnsrecord_dns_la_LDFLAGS = \ | 57 | libgnunet_plugin_gnsrecord_dns_la_LDFLAGS = \ |
@@ -85,3 +84,10 @@ test_gnsrecord_crypto_LDADD = \ | |||
85 | libgnunetgnsrecord.la \ | 84 | libgnunetgnsrecord.la \ |
86 | $(top_builddir)/src/util/libgnunetutil.la | 85 | $(top_builddir)/src/util/libgnunetutil.la |
87 | 86 | ||
87 | |||
88 | perf_gnsrecord_crypto_SOURCES = \ | ||
89 | perf_gnsrecord_crypto.c | ||
90 | perf_gnsrecord_crypto_LDADD = \ | ||
91 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
92 | libgnunetgnsrecord.la \ | ||
93 | $(top_builddir)/src/util/libgnunetutil.la | ||
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c index 35005b5ca..b80d86073 100644 --- a/src/gnsrecord/gnsrecord.c +++ b/src/gnsrecord/gnsrecord.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -30,7 +28,9 @@ | |||
30 | #include "gnunet_constants.h" | 28 | #include "gnunet_constants.h" |
31 | #include "gnunet_gnsrecord_lib.h" | 29 | #include "gnunet_gnsrecord_lib.h" |
32 | #include "gnunet_gnsrecord_plugin.h" | 30 | #include "gnunet_gnsrecord_plugin.h" |
31 | #include "gnunet_json_lib.h" | ||
33 | #include "gnunet_tun_lib.h" | 32 | #include "gnunet_tun_lib.h" |
33 | #include <jansson.h> | ||
34 | 34 | ||
35 | 35 | ||
36 | #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) | 36 | #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) |
@@ -114,10 +114,9 @@ init () | |||
114 | void __attribute__ ((destructor)) | 114 | void __attribute__ ((destructor)) |
115 | GNSRECORD_fini () | 115 | GNSRECORD_fini () |
116 | { | 116 | { |
117 | unsigned int i; | ||
118 | struct Plugin *plugin; | 117 | struct Plugin *plugin; |
119 | 118 | ||
120 | for (i = 0; i < num_plugins; i++) | 119 | for (unsigned int i = 0; i < num_plugins; i++) |
121 | { | 120 | { |
122 | plugin = gns_plugins[i]; | 121 | plugin = gns_plugins[i]; |
123 | GNUNET_break (NULL == | 122 | GNUNET_break (NULL == |
@@ -146,12 +145,11 @@ GNUNET_GNSRECORD_value_to_string (uint32_t type, | |||
146 | const void *data, | 145 | const void *data, |
147 | size_t data_size) | 146 | size_t data_size) |
148 | { | 147 | { |
149 | unsigned int i; | ||
150 | struct Plugin *plugin; | 148 | struct Plugin *plugin; |
151 | char *ret; | 149 | char *ret; |
152 | 150 | ||
153 | init (); | 151 | init (); |
154 | for (i = 0; i < num_plugins; i++) | 152 | for (unsigned int i = 0; i < num_plugins; i++) |
155 | { | 153 | { |
156 | plugin = gns_plugins[i]; | 154 | plugin = gns_plugins[i]; |
157 | if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, | 155 | if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, |
@@ -180,11 +178,10 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type, | |||
180 | void **data, | 178 | void **data, |
181 | size_t *data_size) | 179 | size_t *data_size) |
182 | { | 180 | { |
183 | unsigned int i; | ||
184 | struct Plugin *plugin; | 181 | struct Plugin *plugin; |
185 | 182 | ||
186 | init (); | 183 | init (); |
187 | for (i = 0; i < num_plugins; i++) | 184 | for (unsigned int i = 0; i < num_plugins; i++) |
188 | { | 185 | { |
189 | plugin = gns_plugins[i]; | 186 | plugin = gns_plugins[i]; |
190 | if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, | 187 | if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, |
@@ -207,7 +204,6 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type, | |||
207 | uint32_t | 204 | uint32_t |
208 | GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) | 205 | GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) |
209 | { | 206 | { |
210 | unsigned int i; | ||
211 | struct Plugin *plugin; | 207 | struct Plugin *plugin; |
212 | uint32_t ret; | 208 | uint32_t ret; |
213 | 209 | ||
@@ -215,7 +211,7 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) | |||
215 | "ANY")) | 211 | "ANY")) |
216 | return GNUNET_GNSRECORD_TYPE_ANY; | 212 | return GNUNET_GNSRECORD_TYPE_ANY; |
217 | init (); | 213 | init (); |
218 | for (i = 0; i < num_plugins; i++) | 214 | for (unsigned int i = 0; i < num_plugins; i++) |
219 | { | 215 | { |
220 | plugin = gns_plugins[i]; | 216 | plugin = gns_plugins[i]; |
221 | if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, | 217 | if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, |
@@ -235,14 +231,13 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) | |||
235 | const char * | 231 | const char * |
236 | GNUNET_GNSRECORD_number_to_typename (uint32_t type) | 232 | GNUNET_GNSRECORD_number_to_typename (uint32_t type) |
237 | { | 233 | { |
238 | unsigned int i; | ||
239 | struct Plugin *plugin; | 234 | struct Plugin *plugin; |
240 | const char * ret; | 235 | const char * ret; |
241 | 236 | ||
242 | if (GNUNET_GNSRECORD_TYPE_ANY == type) | 237 | if (GNUNET_GNSRECORD_TYPE_ANY == type) |
243 | return "ANY"; | 238 | return "ANY"; |
244 | init (); | 239 | init (); |
245 | for (i = 0; i < num_plugins; i++) | 240 | for (unsigned int i = 0; i < num_plugins; i++) |
246 | { | 241 | { |
247 | plugin = gns_plugins[i]; | 242 | plugin = gns_plugins[i]; |
248 | if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, | 243 | if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, |
@@ -252,5 +247,4 @@ GNUNET_GNSRECORD_number_to_typename (uint32_t type) | |||
252 | return NULL; | 247 | return NULL; |
253 | } | 248 | } |
254 | 249 | ||
255 | |||
256 | /* end of gnsrecord.c */ | 250 | /* end of gnsrecord.c */ |
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index cebc842f3..295d31100 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -1,21 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2013, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -87,19 +85,26 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
87 | const struct GNUNET_GNSRECORD_Data *rd, | 85 | const struct GNUNET_GNSRECORD_Data *rd, |
88 | unsigned int rd_count) | 86 | unsigned int rd_count) |
89 | { | 87 | { |
90 | size_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, | 88 | ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, |
91 | rd); | 89 | rd); |
92 | char payload[sizeof (uint32_t) + payload_len]; | ||
93 | struct GNUNET_GNSRECORD_Block *block; | 90 | struct GNUNET_GNSRECORD_Block *block; |
94 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; | 91 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; |
95 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 92 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
96 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 93 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
97 | struct GNUNET_GNSRECORD_Data rdc[rd_count]; | 94 | struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL(rd_count)]; |
98 | uint32_t rd_count_nbo; | 95 | uint32_t rd_count_nbo; |
99 | struct GNUNET_TIME_Absolute now; | 96 | struct GNUNET_TIME_Absolute now; |
100 | 97 | ||
98 | if (payload_len < 0) | ||
99 | { | ||
100 | GNUNET_break (0); | ||
101 | return NULL; | ||
102 | } | ||
101 | if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) | 103 | if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) |
104 | { | ||
105 | GNUNET_break (0); | ||
102 | return NULL; | 106 | return NULL; |
107 | } | ||
103 | /* convert relative to absolute times */ | 108 | /* convert relative to absolute times */ |
104 | now = GNUNET_TIME_absolute_get (); | 109 | now = GNUNET_TIME_absolute_get (); |
105 | for (unsigned int i=0;i<rd_count;i++) | 110 | for (unsigned int i=0;i<rd_count;i++) |
@@ -117,39 +122,43 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
117 | } | 122 | } |
118 | /* serialize */ | 123 | /* serialize */ |
119 | rd_count_nbo = htonl (rd_count); | 124 | rd_count_nbo = htonl (rd_count); |
120 | GNUNET_memcpy (payload, | 125 | { |
121 | &rd_count_nbo, | 126 | char payload[sizeof (uint32_t) + payload_len]; |
122 | sizeof (uint32_t)); | 127 | |
123 | GNUNET_assert (payload_len == | 128 | GNUNET_memcpy (payload, |
124 | GNUNET_GNSRECORD_records_serialize (rd_count, | 129 | &rd_count_nbo, |
125 | rdc, | 130 | sizeof (uint32_t)); |
126 | payload_len, | 131 | GNUNET_assert (payload_len == |
127 | &payload[sizeof (uint32_t)])); | 132 | GNUNET_GNSRECORD_records_serialize (rd_count, |
128 | block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + | 133 | rdc, |
129 | sizeof (uint32_t) + | 134 | payload_len, |
130 | payload_len); | 135 | &payload[sizeof (uint32_t)])); |
131 | block->purpose.size = htonl (sizeof (uint32_t) + | 136 | block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + |
132 | payload_len + | 137 | sizeof (uint32_t) + |
133 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 138 | payload_len); |
134 | sizeof (struct GNUNET_TIME_AbsoluteNBO)); | 139 | block->purpose.size = htonl (sizeof (uint32_t) + |
135 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | 140 | payload_len + |
136 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); | 141 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
137 | /* encrypt and sign */ | 142 | sizeof (struct GNUNET_TIME_AbsoluteNBO)); |
138 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, | 143 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); |
139 | label, | 144 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); |
140 | "gns"); | 145 | /* encrypt and sign */ |
141 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, | 146 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, |
142 | &block->derived_key); | 147 | label, |
143 | derive_block_aes_key (&iv, | 148 | "gns"); |
144 | &skey, | 149 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, |
145 | label, | 150 | &block->derived_key); |
146 | pkey); | 151 | derive_block_aes_key (&iv, |
147 | GNUNET_break (payload_len + sizeof (uint32_t) == | 152 | &skey, |
148 | GNUNET_CRYPTO_symmetric_encrypt (payload, | 153 | label, |
149 | payload_len + sizeof (uint32_t), | 154 | pkey); |
150 | &skey, | 155 | GNUNET_break (payload_len + sizeof (uint32_t) == |
151 | &iv, | 156 | GNUNET_CRYPTO_symmetric_encrypt (payload, |
152 | &block[1])); | 157 | payload_len + sizeof (uint32_t), |
158 | &skey, | ||
159 | &iv, | ||
160 | &block[1])); | ||
161 | } | ||
153 | if (GNUNET_OK != | 162 | if (GNUNET_OK != |
154 | GNUNET_CRYPTO_ecdsa_sign (dkey, | 163 | GNUNET_CRYPTO_ecdsa_sign (dkey, |
155 | &block->purpose, | 164 | &block->purpose, |
@@ -246,6 +255,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
246 | GNUNET_CRYPTO_ecdsa_key_get_public (key, | 255 | GNUNET_CRYPTO_ecdsa_key_get_public (key, |
247 | &line->pkey); | 256 | &line->pkey); |
248 | } | 257 | } |
258 | #undef CSIZE | ||
249 | return block_create (key, | 259 | return block_create (key, |
250 | &line->pkey, | 260 | &line->pkey, |
251 | expire, | 261 | expire, |
@@ -304,18 +314,21 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
304 | GNUNET_break_op (0); | 314 | GNUNET_break_op (0); |
305 | return GNUNET_SYSERR; | 315 | return GNUNET_SYSERR; |
306 | } | 316 | } |
307 | derive_block_aes_key (&iv, &skey, label, zone_key); | 317 | derive_block_aes_key (&iv, |
318 | &skey, | ||
319 | label, | ||
320 | zone_key); | ||
308 | { | 321 | { |
309 | char payload[payload_len]; | 322 | char payload[payload_len]; |
310 | uint32_t rd_count; | 323 | uint32_t rd_count; |
311 | 324 | ||
312 | GNUNET_break (payload_len == | 325 | GNUNET_break (payload_len == |
313 | GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len, | 326 | GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len, |
314 | &skey, &iv, | 327 | &skey, &iv, |
315 | payload)); | 328 | payload)); |
316 | GNUNET_memcpy (&rd_count, | 329 | GNUNET_memcpy (&rd_count, |
317 | payload, | 330 | payload, |
318 | sizeof (uint32_t)); | 331 | sizeof (uint32_t)); |
319 | rd_count = ntohl (rd_count); | 332 | rd_count = ntohl (rd_count); |
320 | if (rd_count > 2048) | 333 | if (rd_count > 2048) |
321 | { | 334 | { |
@@ -324,7 +337,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
324 | return GNUNET_SYSERR; | 337 | return GNUNET_SYSERR; |
325 | } | 338 | } |
326 | { | 339 | { |
327 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 340 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; |
328 | unsigned int j; | 341 | unsigned int j; |
329 | struct GNUNET_TIME_Absolute now; | 342 | struct GNUNET_TIME_Absolute now; |
330 | 343 | ||
@@ -359,10 +372,15 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
359 | continue; | 372 | continue; |
360 | if (rd[i].expiration_time < now.abs_value_us) | 373 | if (rd[i].expiration_time < now.abs_value_us) |
361 | include_record = GNUNET_NO; /* Shadow record is expired */ | 374 | include_record = GNUNET_NO; /* Shadow record is expired */ |
362 | if ((rd[k].record_type == rd[i].record_type) | 375 | if ( (rd[k].record_type == rd[i].record_type) && |
363 | && (rd[k].expiration_time >= now.abs_value_us) | 376 | (rd[k].expiration_time >= now.abs_value_us) && |
364 | && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD))) | 377 | (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ) |
378 | { | ||
365 | include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */ | 379 | include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */ |
380 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
381 | "Ignoring shadow record\n"); | ||
382 | break; | ||
383 | } | ||
366 | } | 384 | } |
367 | if (GNUNET_YES == include_record) | 385 | if (GNUNET_YES == include_record) |
368 | { | 386 | { |
@@ -379,6 +397,16 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
379 | rd[j] = rd[i]; | 397 | rd[j] = rd[i]; |
380 | j++; | 398 | j++; |
381 | } | 399 | } |
400 | else | ||
401 | { | ||
402 | struct GNUNET_TIME_Absolute at; | ||
403 | |||
404 | at.abs_value_us = rd[i].expiration_time; | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
406 | "Excluding record that expired %s (%llu ago)\n", | ||
407 | GNUNET_STRINGS_absolute_time_to_string (at), | ||
408 | (unsigned long long) rd[i].expiration_time - now.abs_value_us); | ||
409 | } | ||
382 | } | 410 | } |
383 | rd_count = j; | 411 | rd_count = j; |
384 | if (NULL != proc) | 412 | if (NULL != proc) |
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 05f56cf70..5032647ef 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/gnsrecord/gnsrecord_serialization.c b/src/gnsrecord/gnsrecord_serialization.c index 190f62fc2..934d36102 100644 --- a/src/gnsrecord/gnsrecord_serialization.c +++ b/src/gnsrecord/gnsrecord_serialization.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2013 GNUnet e.V. | 3 | Copyright (C) 2009-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -37,6 +35,12 @@ | |||
37 | 35 | ||
38 | #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) | 36 | #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) |
39 | 37 | ||
38 | /** | ||
39 | * Set to 1 to check that all records are well-formed (can be converted | ||
40 | * to string) during serialization/deserialization. | ||
41 | */ | ||
42 | #define DEBUG_GNSRECORDS 0 | ||
43 | |||
40 | GNUNET_NETWORK_STRUCT_BEGIN | 44 | GNUNET_NETWORK_STRUCT_BEGIN |
41 | 45 | ||
42 | 46 | ||
@@ -78,22 +82,63 @@ GNUNET_NETWORK_STRUCT_END | |||
78 | * | 82 | * |
79 | * @param rd_count number of records in the rd array | 83 | * @param rd_count number of records in the rd array |
80 | * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements | 84 | * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements |
81 | * @return the required size to serialize | 85 | * @return the required size to serialize, -1 on error |
82 | */ | 86 | */ |
83 | size_t | 87 | ssize_t |
84 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | 88 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, |
85 | const struct GNUNET_GNSRECORD_Data *rd) | 89 | const struct GNUNET_GNSRECORD_Data *rd) |
86 | { | 90 | { |
87 | unsigned int i; | ||
88 | size_t ret; | 91 | size_t ret; |
89 | 92 | ||
93 | if (0 == rd_count) | ||
94 | return 0; | ||
95 | |||
90 | ret = sizeof (struct NetworkRecord) * rd_count; | 96 | ret = sizeof (struct NetworkRecord) * rd_count; |
91 | for (i=0;i<rd_count;i++) | 97 | for (unsigned int i=0;i<rd_count;i++) |
92 | { | 98 | { |
93 | GNUNET_assert ((ret + rd[i].data_size) >= ret); | 99 | if ((ret + rd[i].data_size) < ret) |
100 | { | ||
101 | GNUNET_break (0); | ||
102 | return -1; | ||
103 | } | ||
94 | ret += rd[i].data_size; | 104 | ret += rd[i].data_size; |
105 | #if DEBUG_GNSRECORDS | ||
106 | { | ||
107 | char *str; | ||
108 | |||
109 | str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
110 | rd[i].data, | ||
111 | rd[i].data_size); | ||
112 | if (NULL == str) | ||
113 | { | ||
114 | GNUNET_break_op (0); | ||
115 | return -1; | ||
116 | } | ||
117 | GNUNET_free (str); | ||
118 | } | ||
119 | #endif | ||
95 | } | 120 | } |
96 | return ret; | 121 | if (ret > SSIZE_MAX) |
122 | { | ||
123 | GNUNET_break (0); | ||
124 | return -1; | ||
125 | } | ||
126 | //Do not pad PKEY | ||
127 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd->record_type) | ||
128 | return ret; | ||
129 | /** | ||
130 | * Efficiently round up to the next | ||
131 | * power of 2 for padding | ||
132 | * https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 | ||
133 | */ | ||
134 | ret--; | ||
135 | ret |= ret >> 1; | ||
136 | ret |= ret >> 2; | ||
137 | ret |= ret >> 4; | ||
138 | ret |= ret >> 8; | ||
139 | ret |= ret >> 16; | ||
140 | ret++; | ||
141 | return (ssize_t) ret; | ||
97 | } | 142 | } |
98 | 143 | ||
99 | 144 | ||
@@ -108,16 +153,15 @@ GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | |||
108 | */ | 153 | */ |
109 | ssize_t | 154 | ssize_t |
110 | GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | 155 | GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, |
111 | const struct GNUNET_GNSRECORD_Data *rd, | 156 | const struct GNUNET_GNSRECORD_Data *rd, |
112 | size_t dest_size, | 157 | size_t dest_size, |
113 | char *dest) | 158 | char *dest) |
114 | { | 159 | { |
115 | struct NetworkRecord rec; | 160 | struct NetworkRecord rec; |
116 | unsigned int i; | ||
117 | size_t off; | 161 | size_t off; |
118 | 162 | ||
119 | off = 0; | 163 | off = 0; |
120 | for (i=0;i<rd_count;i++) | 164 | for (unsigned int i=0;i<rd_count;i++) |
121 | { | 165 | { |
122 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 166 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
123 | "Serializing record %u with flags %d and expiration time %llu\n", | 167 | "Serializing record %u with flags %d and expiration time %llu\n", |
@@ -128,20 +172,46 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
128 | rec.data_size = htonl ((uint32_t) rd[i].data_size); | 172 | rec.data_size = htonl ((uint32_t) rd[i].data_size); |
129 | rec.record_type = htonl (rd[i].record_type); | 173 | rec.record_type = htonl (rd[i].record_type); |
130 | rec.flags = htonl (rd[i].flags); | 174 | rec.flags = htonl (rd[i].flags); |
131 | if (off + sizeof (rec) > dest_size) | 175 | if ( (off + sizeof (rec) > dest_size) || |
176 | (off + sizeof (rec) < off) ) | ||
177 | { | ||
178 | GNUNET_break (0); | ||
132 | return -1; | 179 | return -1; |
180 | } | ||
133 | GNUNET_memcpy (&dest[off], | 181 | GNUNET_memcpy (&dest[off], |
134 | &rec, | 182 | &rec, |
135 | sizeof (rec)); | 183 | sizeof (rec)); |
136 | off += sizeof (rec); | 184 | off += sizeof (rec); |
137 | if (off + rd[i].data_size > dest_size) | 185 | if ( (off + rd[i].data_size > dest_size) || |
186 | (off + rd[i].data_size < off) ) | ||
187 | { | ||
188 | GNUNET_break (0); | ||
138 | return -1; | 189 | return -1; |
190 | } | ||
139 | GNUNET_memcpy (&dest[off], | 191 | GNUNET_memcpy (&dest[off], |
140 | rd[i].data, | 192 | rd[i].data, |
141 | rd[i].data_size); | 193 | rd[i].data_size); |
142 | off += rd[i].data_size; | 194 | off += rd[i].data_size; |
195 | #if DEBUG_GNSRECORDS | ||
196 | { | ||
197 | char *str; | ||
198 | |||
199 | str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
200 | rd[i].data, | ||
201 | rd[i].data_size); | ||
202 | if (NULL == str) | ||
203 | { | ||
204 | GNUNET_break_op (0); | ||
205 | return -1; | ||
206 | } | ||
207 | GNUNET_free (str); | ||
208 | } | ||
209 | #endif | ||
143 | } | 210 | } |
144 | return off; | 211 | memset (&dest[off], |
212 | 0, | ||
213 | dest_size-off); | ||
214 | return dest_size; | ||
145 | } | 215 | } |
146 | 216 | ||
147 | 217 | ||
@@ -156,29 +226,53 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
156 | */ | 226 | */ |
157 | int | 227 | int |
158 | GNUNET_GNSRECORD_records_deserialize (size_t len, | 228 | GNUNET_GNSRECORD_records_deserialize (size_t len, |
159 | const char *src, | 229 | const char *src, |
160 | unsigned int rd_count, | 230 | unsigned int rd_count, |
161 | struct GNUNET_GNSRECORD_Data *dest) | 231 | struct GNUNET_GNSRECORD_Data *dest) |
162 | { | 232 | { |
163 | struct NetworkRecord rec; | 233 | struct NetworkRecord rec; |
164 | unsigned int i; | ||
165 | size_t off; | 234 | size_t off; |
166 | 235 | ||
167 | off = 0; | 236 | off = 0; |
168 | for (i=0;i<rd_count;i++) | 237 | for (unsigned int i=0;i<rd_count;i++) |
169 | { | 238 | { |
170 | if (off + sizeof (rec) > len) | 239 | if ( (off + sizeof (rec) > len) || |
240 | (off + sizeof (rec) < off) ) | ||
241 | { | ||
242 | GNUNET_break_op (0); | ||
171 | return GNUNET_SYSERR; | 243 | return GNUNET_SYSERR; |
172 | GNUNET_memcpy (&rec, &src[off], sizeof (rec)); | 244 | } |
245 | GNUNET_memcpy (&rec, | ||
246 | &src[off], | ||
247 | sizeof (rec)); | ||
173 | dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time); | 248 | dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time); |
174 | dest[i].data_size = ntohl ((uint32_t) rec.data_size); | 249 | dest[i].data_size = ntohl ((uint32_t) rec.data_size); |
175 | dest[i].record_type = ntohl (rec.record_type); | 250 | dest[i].record_type = ntohl (rec.record_type); |
176 | dest[i].flags = ntohl (rec.flags); | 251 | dest[i].flags = ntohl (rec.flags); |
177 | off += sizeof (rec); | 252 | off += sizeof (rec); |
178 | if (off + dest[i].data_size > len) | 253 | if ( (off + dest[i].data_size > len) || |
254 | (off + dest[i].data_size < off) ) | ||
255 | { | ||
256 | GNUNET_break_op (0); | ||
179 | return GNUNET_SYSERR; | 257 | return GNUNET_SYSERR; |
258 | } | ||
180 | dest[i].data = &src[off]; | 259 | dest[i].data = &src[off]; |
181 | off += dest[i].data_size; | 260 | off += dest[i].data_size; |
261 | #if GNUNET_EXTRA_LOGGING | ||
262 | { | ||
263 | char *str; | ||
264 | |||
265 | str = GNUNET_GNSRECORD_value_to_string (dest[i].record_type, | ||
266 | dest[i].data, | ||
267 | dest[i].data_size); | ||
268 | if (NULL == str) | ||
269 | { | ||
270 | GNUNET_break_op (0); | ||
271 | return GNUNET_SYSERR; | ||
272 | } | ||
273 | GNUNET_free (str); | ||
274 | } | ||
275 | #endif | ||
182 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 276 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
183 | "Deserialized record %u with flags %d and expiration time %llu\n", | 277 | "Deserialized record %u with flags %d and expiration time %llu\n", |
184 | i, | 278 | i, |
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c new file mode 100644 index 000000000..35547ebc2 --- /dev/null +++ b/src/gnsrecord/perf_gnsrecord_crypto.c | |||
@@ -0,0 +1,135 @@ | |||
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 | /** | ||
19 | * @file gnsrecord/test_gnsrecord_crypto.c | ||
20 | * @brief testcase for block creation, verification and decryption | ||
21 | */ | ||
22 | #include "platform.h" | ||
23 | #include "gnunet_util_lib.h" | ||
24 | #include "gnunet_gnsrecord_lib.h" | ||
25 | |||
26 | #define ROUNDS 1000 | ||
27 | |||
28 | #define RECORDS 5 | ||
29 | |||
30 | #define TEST_RECORD_TYPE 1234 | ||
31 | |||
32 | #define TEST_RECORD_DATALEN 123 | ||
33 | |||
34 | #define TEST_RECORD_DATA 'a' | ||
35 | |||
36 | #define TEST_REMOVE_RECORD_TYPE 4321 | ||
37 | |||
38 | #define TEST_REMOVE_RECORD_DATALEN 255 | ||
39 | |||
40 | #define TEST_REMOVE_RECORD_DATA 'b' | ||
41 | |||
42 | |||
43 | static struct GNUNET_GNSRECORD_Data * | ||
44 | create_record (int count) | ||
45 | { | ||
46 | struct GNUNET_GNSRECORD_Data *rd; | ||
47 | |||
48 | rd = GNUNET_new_array (count, | ||
49 | struct GNUNET_GNSRECORD_Data); | ||
50 | for (unsigned int c = 0; c < count; c++) | ||
51 | { | ||
52 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | ||
53 | rd[c].record_type = TEST_RECORD_TYPE; | ||
54 | rd[c].data_size = TEST_RECORD_DATALEN; | ||
55 | rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN); | ||
56 | memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); | ||
57 | } | ||
58 | return rd; | ||
59 | } | ||
60 | |||
61 | |||
62 | static void | ||
63 | run (void *cls, | ||
64 | char *const *args, | ||
65 | const char *cfgfile, | ||
66 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
67 | { | ||
68 | struct GNUNET_GNSRECORD_Block *block; | ||
69 | struct GNUNET_HashCode query; | ||
70 | struct GNUNET_GNSRECORD_Data *s_rd; | ||
71 | const char *s_name; | ||
72 | struct GNUNET_TIME_Absolute start_time; | ||
73 | struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; | ||
74 | struct GNUNET_TIME_Absolute expire; | ||
75 | |||
76 | (void) cls; | ||
77 | (void) args; | ||
78 | (void) cfgfile; | ||
79 | (void) cfg; | ||
80 | expire = GNUNET_TIME_absolute_get(); | ||
81 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | ||
82 | GNUNET_assert (NULL != privkey); | ||
83 | |||
84 | /* test block creation */ | ||
85 | s_name = "DUMMY.dummy.gnunet"; | ||
86 | s_rd = create_record (RECORDS); | ||
87 | start_time = GNUNET_TIME_absolute_get (); | ||
88 | for (unsigned int i=0;i<ROUNDS;i++) | ||
89 | { | ||
90 | GNUNET_assert (NULL != (block = | ||
91 | GNUNET_GNSRECORD_block_create2 (privkey, | ||
92 | expire, | ||
93 | s_name, | ||
94 | s_rd, | ||
95 | RECORDS))); | ||
96 | GNUNET_GNSRECORD_query_from_private_key (privkey, | ||
97 | s_name, | ||
98 | &query); | ||
99 | GNUNET_free (block); | ||
100 | } | ||
101 | fprintf (stderr, | ||
102 | "Took %s to produce %u GNS blocks for the DHT\n", | ||
103 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time), | ||
104 | GNUNET_YES), | ||
105 | ROUNDS); | ||
106 | for (unsigned int i=0;i<RECORDS;i++) | ||
107 | GNUNET_free ((void *) s_rd[i].data); | ||
108 | GNUNET_free (s_rd); | ||
109 | GNUNET_free (privkey); | ||
110 | } | ||
111 | |||
112 | |||
113 | int | ||
114 | main (int argc, char *argv[]) | ||
115 | { | ||
116 | static char *const argvx[] = { | ||
117 | "perf-gnsrecord-crypto", | ||
118 | NULL | ||
119 | }; | ||
120 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
121 | GNUNET_GETOPT_OPTION_END | ||
122 | }; | ||
123 | |||
124 | if (GNUNET_OK != | ||
125 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | ||
126 | argvx, | ||
127 | "perf-gnsrecord-crypto", | ||
128 | "nohelp", options, | ||
129 | &run, | ||
130 | NULL)) | ||
131 | return 1; | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | /* end of test_gnsrecord_crypto.c */ | ||
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c index 691936c16..254ae15ea 100644 --- a/src/gnsrecord/plugin_gnsrecord_dns.c +++ b/src/gnsrecord/plugin_gnsrecord_dns.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2013, 2014 GNUnet e.V. | 3 | Copyright (C) 2013, 2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -465,7 +463,7 @@ dns_string_to_value (void *cls, | |||
465 | } | 463 | } |
466 | cert_size = GNUNET_STRINGS_base64_decode (certp, | 464 | cert_size = GNUNET_STRINGS_base64_decode (certp, |
467 | strlen (certp), | 465 | strlen (certp), |
468 | &cert_data); | 466 | (void **) &cert_data); |
469 | GNUNET_free (sdup); | 467 | GNUNET_free (sdup); |
470 | cert.cert_type = type; | 468 | cert.cert_type = type; |
471 | cert.cert_tag = key; | 469 | cert.cert_tag = key; |
diff --git a/src/gnsrecord/test_gnsrecord_block_expiration.c b/src/gnsrecord/test_gnsrecord_block_expiration.c index 3fab577a5..5bb14cdbc 100644 --- a/src/gnsrecord/test_gnsrecord_block_expiration.c +++ b/src/gnsrecord/test_gnsrecord_block_expiration.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file gnsrecord/test_gnsrecord_crypto.c | 19 | * @file gnsrecord/test_gnsrecord_crypto.c |
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c index 1df3f3730..5a78f8b25 100644 --- a/src/gnsrecord/test_gnsrecord_crypto.c +++ b/src/gnsrecord/test_gnsrecord_crypto.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file gnsrecord/test_gnsrecord_crypto.c | 19 | * @file gnsrecord/test_gnsrecord_crypto.c |
@@ -23,11 +21,12 @@ | |||
23 | */ | 21 | */ |
24 | #include "platform.h" | 22 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 23 | #include "gnunet_util_lib.h" |
24 | #include "gnunet_dnsparser_lib.h" | ||
26 | #include "gnunet_gnsrecord_lib.h" | 25 | #include "gnunet_gnsrecord_lib.h" |
27 | 26 | ||
28 | #define RECORDS 5 | 27 | #define RECORDS 5 |
29 | 28 | ||
30 | #define TEST_RECORD_TYPE 1234 | 29 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT |
31 | 30 | ||
32 | #define TEST_RECORD_DATALEN 123 | 31 | #define TEST_RECORD_DATALEN 123 |
33 | 32 | ||
@@ -54,7 +53,7 @@ create_record (int count) | |||
54 | { | 53 | { |
55 | struct GNUNET_GNSRECORD_Data *rd; | 54 | struct GNUNET_GNSRECORD_Data *rd; |
56 | 55 | ||
57 | rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); | 56 | rd = GNUNET_new_array (count, struct GNUNET_GNSRECORD_Data); |
58 | for (unsigned int c = 0; c < count; c++) | 57 | for (unsigned int c = 0; c < count; c++) |
59 | { | 58 | { |
60 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; | 59 | rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; |
@@ -103,11 +102,10 @@ run (void *cls, | |||
103 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 102 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; |
104 | struct GNUNET_HashCode query_pub; | 103 | struct GNUNET_HashCode query_pub; |
105 | struct GNUNET_HashCode query_priv; | 104 | struct GNUNET_HashCode query_priv; |
105 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); | ||
106 | 106 | ||
107 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); | 107 | privkey = GNUNET_CRYPTO_ecdsa_key_create (); |
108 | GNUNET_assert (NULL != privkey); | 108 | GNUNET_assert (NULL != privkey); |
109 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); | ||
110 | |||
111 | /* get public key */ | 109 | /* get public key */ |
112 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, | 110 | GNUNET_CRYPTO_ecdsa_key_get_public (privkey, |
113 | &pubkey); | 111 | &pubkey); |
@@ -142,6 +140,7 @@ run (void *cls, | |||
142 | &rd_decrypt_cb, | 140 | &rd_decrypt_cb, |
143 | s_name)); | 141 | s_name)); |
144 | GNUNET_free (block); | 142 | GNUNET_free (block); |
143 | GNUNET_free (privkey); | ||
145 | } | 144 | } |
146 | 145 | ||
147 | 146 | ||
diff --git a/src/gnsrecord/test_gnsrecord_serialization.c b/src/gnsrecord/test_gnsrecord_serialization.c index 3edd2bc48..03a4d8b03 100644 --- a/src/gnsrecord/test_gnsrecord_serialization.c +++ b/src/gnsrecord/test_gnsrecord_serialization.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file gnsrecord/test_gnsrecord_serialization.c | 19 | * @file gnsrecord/test_gnsrecord_serialization.c |
@@ -24,6 +22,7 @@ | |||
24 | #include "platform.h" | 22 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 23 | #include "gnunet_util_lib.h" |
26 | #include "gnunet_gnsrecord_lib.h" | 24 | #include "gnunet_gnsrecord_lib.h" |
25 | #include "gnunet_dnsparser_lib.h" | ||
27 | 26 | ||
28 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | 27 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) |
29 | 28 | ||
@@ -31,7 +30,9 @@ static int res; | |||
31 | 30 | ||
32 | 31 | ||
33 | static void | 32 | static void |
34 | run (void *cls, char *const *args, const char *cfgfile, | 33 | run (void *cls, |
34 | char *const *args, | ||
35 | const char *cfgfile, | ||
35 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 36 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
36 | { | 37 | { |
37 | size_t len; | 38 | size_t len; |
@@ -46,7 +47,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
46 | data_len = 0; | 47 | data_len = 0; |
47 | for (c = 0; c < rd_count; c++) | 48 | for (c = 0; c < rd_count; c++) |
48 | { | 49 | { |
49 | src[c].record_type = c+1; | 50 | src[c].record_type = GNUNET_DNSPARSER_TYPE_TXT; |
50 | src[c].data_size = data_len; | 51 | src[c].data_size = data_len; |
51 | src[c].data = GNUNET_malloc (data_len); | 52 | src[c].data = GNUNET_malloc (data_len); |
52 | 53 | ||
@@ -69,58 +70,61 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
69 | (unsigned int) len); | 70 | (unsigned int) len); |
70 | 71 | ||
71 | GNUNET_assert (rd_ser != NULL); | 72 | GNUNET_assert (rd_ser != NULL); |
72 | |||
73 | struct GNUNET_GNSRECORD_Data dst[rd_count]; | ||
74 | GNUNET_assert (GNUNET_OK == | ||
75 | GNUNET_GNSRECORD_records_deserialize (len, | ||
76 | rd_ser, | ||
77 | rd_count, | ||
78 | dst)); | ||
79 | |||
80 | GNUNET_assert (dst != NULL); | ||
81 | |||
82 | for (c = 0; c < rd_count; c++) | ||
83 | { | 73 | { |
84 | if (src[c].data_size != dst[c].data_size) | 74 | struct GNUNET_GNSRECORD_Data dst[rd_count]; |
85 | { | 75 | GNUNET_assert (GNUNET_OK == |
86 | GNUNET_break (0); | 76 | GNUNET_GNSRECORD_records_deserialize (len, |
87 | res = 1; | 77 | rd_ser, |
88 | } | 78 | rd_count, |
89 | if (src[c].expiration_time != dst[c].expiration_time) | 79 | dst)); |
90 | { | ||
91 | GNUNET_break (0); | ||
92 | res = 1; | ||
93 | } | ||
94 | if (src[c].flags != dst[c].flags) | ||
95 | { | ||
96 | GNUNET_break (0); | ||
97 | res = 1; | ||
98 | } | ||
99 | if (src[c].record_type != dst[c].record_type) | ||
100 | { | ||
101 | GNUNET_break (0); | ||
102 | res = 1; | ||
103 | } | ||
104 | 80 | ||
105 | size_t data_size = src[c].data_size; | 81 | GNUNET_assert (dst != NULL); |
106 | char data[data_size]; | 82 | |
107 | memset (data, 'a', data_size); | 83 | for (c = 0; c < rd_count; c++) |
108 | if (0 != memcmp (data, dst[c].data, data_size)) | ||
109 | { | ||
110 | GNUNET_break (0); | ||
111 | res = 1; | ||
112 | } | ||
113 | if (0 != memcmp (data, src[c].data, data_size)) | ||
114 | { | ||
115 | GNUNET_break (0); | ||
116 | res = 1; | ||
117 | } | ||
118 | if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size)) | ||
119 | { | 84 | { |
120 | GNUNET_break (0); | 85 | if (src[c].data_size != dst[c].data_size) |
121 | res = 1; | 86 | { |
87 | GNUNET_break (0); | ||
88 | res = 1; | ||
89 | } | ||
90 | if (src[c].expiration_time != dst[c].expiration_time) | ||
91 | { | ||
92 | GNUNET_break (0); | ||
93 | res = 1; | ||
94 | } | ||
95 | if (src[c].flags != dst[c].flags) | ||
96 | { | ||
97 | GNUNET_break (0); | ||
98 | res = 1; | ||
99 | } | ||
100 | if (src[c].record_type != dst[c].record_type) | ||
101 | { | ||
102 | GNUNET_break (0); | ||
103 | res = 1; | ||
104 | } | ||
105 | |||
106 | { | ||
107 | size_t data_size = src[c].data_size; | ||
108 | char data[data_size]; | ||
109 | |||
110 | memset (data, 'a', data_size); | ||
111 | if (0 != memcmp (data, dst[c].data, data_size)) | ||
112 | { | ||
113 | GNUNET_break (0); | ||
114 | res = 1; | ||
115 | } | ||
116 | if (0 != memcmp (data, src[c].data, data_size)) | ||
117 | { | ||
118 | GNUNET_break (0); | ||
119 | res = 1; | ||
120 | } | ||
121 | if (0 != memcmp (src[c].data, dst[c].data, src[c].data_size)) | ||
122 | { | ||
123 | GNUNET_break (0); | ||
124 | res = 1; | ||
125 | } | ||
126 | } | ||
122 | } | 127 | } |
123 | |||
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Element [%i]: EQUAL\n", c); |
125 | } | 129 | } |
126 | 130 | ||