aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_ecc_setup.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-04 17:05:05 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-04 17:05:05 +0100
commitf46c107278b96264b2e5302b4ebb050f73abf869 (patch)
treef2bd74b81fa33546e513b2eabf7a790eb3b631e8 /src/util/crypto_ecc_setup.c
parente20eca334a33b8340524a8fa6ad1d6b606e1dd0c (diff)
downloadgnunet-f46c107278b96264b2e5302b4ebb050f73abf869.tar.gz
gnunet-f46c107278b96264b2e5302b4ebb050f73abf869.zip
trying again to fix test_service timeout on v6 failure
Diffstat (limited to 'src/util/crypto_ecc_setup.c')
-rw-r--r--src/util/crypto_ecc_setup.c98
1 files changed, 71 insertions, 27 deletions
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c
index 64610ddd3..e7caf9ded 100644
--- a/src/util/crypto_ecc_setup.c
+++ b/src/util/crypto_ecc_setup.c
@@ -80,6 +80,7 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
80 unsigned int cnt; 80 unsigned int cnt;
81 int ec; 81 int ec;
82 uint64_t fs; 82 uint64_t fs;
83 ssize_t sret;
83 84
84 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) 85 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename))
85 return NULL; 86 return NULL;
@@ -193,7 +194,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
193 { 194 {
194 LOG (GNUNET_ERROR_TYPE_ERROR, 195 LOG (GNUNET_ERROR_TYPE_ERROR,
195 _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), 196 _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
196 filename, (unsigned int) fs, 197 filename,
198 (unsigned int) fs,
197 (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 199 (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
198 LOG (GNUNET_ERROR_TYPE_ERROR, 200 LOG (GNUNET_ERROR_TYPE_ERROR,
199 _("This may be ok if someone is currently generating a key.\n")); 201 _("This may be ok if someone is currently generating a key.\n"));
@@ -205,12 +207,20 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename)
205 } 207 }
206 fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey); 208 fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey);
207 priv = GNUNET_malloc (fs); 209 priv = GNUNET_malloc (fs);
208 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, priv, fs)); 210 sret = GNUNET_DISK_file_read (fd,
211 priv,
212 fs);
213 GNUNET_assert ( (sret >= 0) &&
214 (fs == (size_t) sret) );
209 if (GNUNET_YES != 215 if (GNUNET_YES !=
210 GNUNET_DISK_file_unlock (fd, 0, 216 GNUNET_DISK_file_unlock (fd,
217 0,
211 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) 218 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
212 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 219 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
213 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 220 "fcntl",
221 filename);
222 GNUNET_assert (GNUNET_YES ==
223 GNUNET_DISK_file_close (fd));
214 return priv; 224 return priv;
215} 225}
216 226
@@ -237,8 +247,10 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
237 unsigned int cnt; 247 unsigned int cnt;
238 int ec; 248 int ec;
239 uint64_t fs; 249 uint64_t fs;
240 250 ssize_t sret;
241 if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) 251
252 if (GNUNET_SYSERR ==
253 GNUNET_DISK_directory_create_for_file (filename))
242 return NULL; 254 return NULL;
243 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 255 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
244 { 256 {
@@ -255,19 +267,24 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
255 { 267 {
256 /* must exist but not be accessible, fail for good! */ 268 /* must exist but not be accessible, fail for good! */
257 if (0 != ACCESS (filename, R_OK)) 269 if (0 != ACCESS (filename, R_OK))
258 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); 270 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
271 "access",
272 filename);
259 else 273 else
260 GNUNET_break (0); /* what is going on!? */ 274 GNUNET_break (0); /* what is going on!? */
261 return NULL; 275 return NULL;
262 } 276 }
263 continue; 277 continue;
264 } 278 }
265 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 279 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
280 "open",
281 filename);
266 return NULL; 282 return NULL;
267 } 283 }
268 cnt = 0; 284 cnt = 0;
269 while (GNUNET_YES != 285 while (GNUNET_YES !=
270 GNUNET_DISK_file_lock (fd, 0, 286 GNUNET_DISK_file_lock (fd,
287 0,
271 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 288 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
272 GNUNET_YES)) 289 GNUNET_YES))
273 { 290 {
@@ -276,7 +293,8 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
276 { 293 {
277 ec = errno; 294 ec = errno;
278 LOG (GNUNET_ERROR_TYPE_ERROR, 295 LOG (GNUNET_ERROR_TYPE_ERROR,
279 _("Could not acquire lock on file `%s': %s...\n"), filename, 296 _("Could not acquire lock on file `%s': %s...\n"),
297 filename,
280 STRERROR (ec)); 298 STRERROR (ec));
281 } 299 }
282 } 300 }
@@ -285,21 +303,29 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
285 priv = GNUNET_CRYPTO_ecdsa_key_create (); 303 priv = GNUNET_CRYPTO_ecdsa_key_create ();
286 GNUNET_assert (NULL != priv); 304 GNUNET_assert (NULL != priv);
287 GNUNET_assert (sizeof (*priv) == 305 GNUNET_assert (sizeof (*priv) ==
288 GNUNET_DISK_file_write (fd, priv, sizeof (*priv))); 306 GNUNET_DISK_file_write (fd,
307 priv,
308 sizeof (*priv)));
289 GNUNET_DISK_file_sync (fd); 309 GNUNET_DISK_file_sync (fd);
290 if (GNUNET_YES != 310 if (GNUNET_YES !=
291 GNUNET_DISK_file_unlock (fd, 0, 311 GNUNET_DISK_file_unlock (fd, 0,
292 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 312 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
293 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 313 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
294 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 314 "fcntl",
315 filename);
316 GNUNET_assert (GNUNET_YES ==
317 GNUNET_DISK_file_close (fd));
295 return priv; 318 return priv;
296 } 319 }
297 /* key file exists already, read it! */ 320 /* key file exists already, read it! */
298 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 321 fd = GNUNET_DISK_file_open (filename,
322 GNUNET_DISK_OPEN_READ,
299 GNUNET_DISK_PERM_NONE); 323 GNUNET_DISK_PERM_NONE);
300 if (NULL == fd) 324 if (NULL == fd)
301 { 325 {
302 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); 326 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR,
327 "open",
328 filename);
303 return NULL; 329 return NULL;
304 } 330 }
305 cnt = 0; 331 cnt = 0;
@@ -318,25 +344,34 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
318 filename, 344 filename,
319 STRERROR (ec)); 345 STRERROR (ec));
320 LOG (GNUNET_ERROR_TYPE_ERROR, 346 LOG (GNUNET_ERROR_TYPE_ERROR,
321 _ 347 _("This may be ok if someone is currently generating a private key.\n"));
322 ("This may be ok if someone is currently generating a private key.\n"));
323 } 348 }
324 short_wait (); 349 short_wait ();
325 continue; 350 continue;
326 } 351 }
327 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 352 if (GNUNET_YES !=
353 GNUNET_DISK_file_test (filename))
328 { 354 {
329 /* eh, what!? File we opened is now gone!? */ 355 /* eh, what!? File we opened is now gone!? */
330 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); 356 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
357 "stat",
358 filename);
331 if (GNUNET_YES != 359 if (GNUNET_YES !=
332 GNUNET_DISK_file_unlock (fd, 0, 360 GNUNET_DISK_file_unlock (fd, 0,
333 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 361 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
334 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 362 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
335 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 363 "fcntl",
364 filename);
365 GNUNET_assert (GNUNET_OK ==
366 GNUNET_DISK_file_close (fd));
336 367
337 return NULL; 368 return NULL;
338 } 369 }
339 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 370 if (GNUNET_OK !=
371 GNUNET_DISK_file_size (filename,
372 &fs,
373 GNUNET_YES,
374 GNUNET_YES))
340 fs = 0; 375 fs = 0;
341 if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) 376 if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))
342 { 377 {
@@ -345,7 +380,9 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
345 if (GNUNET_YES != 380 if (GNUNET_YES !=
346 GNUNET_DISK_file_unlock (fd, 0, 381 GNUNET_DISK_file_unlock (fd, 0,
347 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 382 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
348 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 383 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
384 "fcntl",
385 filename);
349 if (0 == ++cnt % 10) 386 if (0 == ++cnt % 10)
350 { 387 {
351 LOG (GNUNET_ERROR_TYPE_ERROR, 388 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -362,12 +399,19 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename)
362 } 399 }
363 fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 400 fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
364 priv = GNUNET_malloc (fs); 401 priv = GNUNET_malloc (fs);
365 GNUNET_assert (fs == GNUNET_DISK_file_read (fd, priv, fs)); 402 sret = GNUNET_DISK_file_read (fd,
403 priv,
404 fs);
405 GNUNET_assert ( (sret >= 0) &&
406 (fs == (size_t) sret) );
366 if (GNUNET_YES != 407 if (GNUNET_YES !=
367 GNUNET_DISK_file_unlock (fd, 0, 408 GNUNET_DISK_file_unlock (fd, 0,
368 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 409 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
369 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 410 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
370 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 411 "fcntl",
412 filename);
413 GNUNET_assert (GNUNET_YES ==
414 GNUNET_DISK_file_close (fd));
371 return priv; 415 return priv;
372} 416}
373 417