diff options
Diffstat (limited to 'src/util/crypto_ecc_setup.c')
-rw-r--r-- | src/util/crypto_ecc_setup.c | 247 |
1 files changed, 124 insertions, 123 deletions
diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c index 1031b302e..c556d805d 100644 --- a/src/util/crypto_ecc_setup.c +++ b/src/util/crypto_ecc_setup.c | |||
@@ -27,18 +27,29 @@ | |||
27 | #include <gcrypt.h> | 27 | #include <gcrypt.h> |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | 29 | ||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__) | 30 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__) |
31 | 31 | ||
32 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall) | 32 | #define LOG_STRERROR(kind, syscall) \ |
33 | GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall) | ||
33 | 34 | ||
34 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename) | 35 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
36 | GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename) | ||
35 | 37 | ||
36 | /** | 38 | /** |
37 | * Log an error message at log-level 'level' that indicates | 39 | * Log an error message at log-level 'level' that indicates |
38 | * a failure of the command 'cmd' with the message given | 40 | * a failure of the command 'cmd' with the message given |
39 | * by gcry_strerror(rc). | 41 | * by gcry_strerror(rc). |
40 | */ | 42 | */ |
41 | #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0) | 43 | #define LOG_GCRY(level, cmd, rc) \ |
44 | do \ | ||
45 | { \ | ||
46 | LOG (level, \ | ||
47 | _ ("`%s' failed at %s:%d with error: %s\n"), \ | ||
48 | cmd, \ | ||
49 | __FILE__, \ | ||
50 | __LINE__, \ | ||
51 | gcry_strerror (rc)); \ | ||
52 | } while (0) | ||
42 | 53 | ||
43 | 54 | ||
44 | /** | 55 | /** |
@@ -86,11 +97,12 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
86 | return NULL; | 97 | return NULL; |
87 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 98 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
88 | { | 99 | { |
89 | fd = GNUNET_DISK_file_open (filename, | 100 | fd = |
90 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 101 | GNUNET_DISK_file_open (filename, |
91 | | GNUNET_DISK_OPEN_FAILIFEXISTS, | 102 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | |
92 | GNUNET_DISK_PERM_USER_READ | | 103 | GNUNET_DISK_OPEN_FAILIFEXISTS, |
93 | GNUNET_DISK_PERM_USER_WRITE); | 104 | GNUNET_DISK_PERM_USER_READ | |
105 | GNUNET_DISK_PERM_USER_WRITE); | ||
94 | if (NULL == fd) | 106 | if (NULL == fd) |
95 | { | 107 | { |
96 | if (EEXIST == errno) | 108 | if (EEXIST == errno) |
@@ -98,10 +110,10 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
98 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 110 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
99 | { | 111 | { |
100 | /* must exist but not be accessible, fail for good! */ | 112 | /* must exist but not be accessible, fail for good! */ |
101 | if (0 != ACCESS (filename, R_OK)) | 113 | if (0 != access (filename, R_OK)) |
102 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); | 114 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); |
103 | else | 115 | else |
104 | GNUNET_break (0); /* what is going on!? */ | 116 | GNUNET_break (0); /* what is going on!? */ |
105 | return NULL; | 117 | return NULL; |
106 | } | 118 | } |
107 | continue; | 119 | continue; |
@@ -111,7 +123,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
111 | } | 123 | } |
112 | cnt = 0; | 124 | cnt = 0; |
113 | while (GNUNET_YES != | 125 | while (GNUNET_YES != |
114 | GNUNET_DISK_file_lock (fd, 0, | 126 | GNUNET_DISK_file_lock (fd, |
127 | 0, | ||
115 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), | 128 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), |
116 | GNUNET_YES)) | 129 | GNUNET_YES)) |
117 | { | 130 | { |
@@ -120,27 +133,29 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
120 | { | 133 | { |
121 | ec = errno; | 134 | ec = errno; |
122 | LOG (GNUNET_ERROR_TYPE_ERROR, | 135 | LOG (GNUNET_ERROR_TYPE_ERROR, |
123 | _("Could not acquire lock on file `%s': %s...\n"), | 136 | _ ("Could not acquire lock on file `%s': %s...\n"), |
124 | filename, | 137 | filename, |
125 | STRERROR (ec)); | 138 | strerror (ec)); |
126 | } | 139 | } |
127 | } | 140 | } |
128 | LOG (GNUNET_ERROR_TYPE_INFO, | 141 | LOG (GNUNET_ERROR_TYPE_INFO, |
129 | _("Creating a new private key. This may take a while.\n")); | 142 | _ ("Creating a new private key. This may take a while.\n")); |
130 | priv = GNUNET_CRYPTO_eddsa_key_create (); | 143 | priv = GNUNET_CRYPTO_eddsa_key_create (); |
131 | GNUNET_assert (NULL != priv); | 144 | GNUNET_assert (NULL != priv); |
132 | GNUNET_assert (sizeof (*priv) == | 145 | GNUNET_assert (sizeof (*priv) == |
133 | GNUNET_DISK_file_write (fd, priv, sizeof (*priv))); | 146 | GNUNET_DISK_file_write (fd, priv, sizeof (*priv))); |
134 | GNUNET_DISK_file_sync (fd); | 147 | GNUNET_DISK_file_sync (fd); |
135 | if (GNUNET_YES != | 148 | if (GNUNET_YES != |
136 | GNUNET_DISK_file_unlock (fd, 0, | 149 | GNUNET_DISK_file_unlock (fd, |
150 | 0, | ||
137 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) | 151 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) |
138 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 152 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
139 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 153 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
140 | return priv; | 154 | return priv; |
141 | } | 155 | } |
142 | /* key file exists already, read it! */ | 156 | /* key file exists already, read it! */ |
143 | fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, | 157 | fd = GNUNET_DISK_file_open (filename, |
158 | GNUNET_DISK_OPEN_READ, | ||
144 | GNUNET_DISK_PERM_NONE); | 159 | GNUNET_DISK_PERM_NONE); |
145 | if (NULL == fd) | 160 | if (NULL == fd) |
146 | { | 161 | { |
@@ -151,7 +166,8 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
151 | while (1) | 166 | while (1) |
152 | { | 167 | { |
153 | if (GNUNET_YES != | 168 | if (GNUNET_YES != |
154 | GNUNET_DISK_file_lock (fd, 0, | 169 | GNUNET_DISK_file_lock (fd, |
170 | 0, | ||
155 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), | 171 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), |
156 | GNUNET_NO)) | 172 | GNUNET_NO)) |
157 | { | 173 | { |
@@ -159,11 +175,13 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
159 | { | 175 | { |
160 | ec = errno; | 176 | ec = errno; |
161 | LOG (GNUNET_ERROR_TYPE_ERROR, | 177 | LOG (GNUNET_ERROR_TYPE_ERROR, |
162 | _("Could not acquire lock on file `%s': %s...\n"), filename, | 178 | _ ("Could not acquire lock on file `%s': %s...\n"), |
163 | STRERROR (ec)); | 179 | filename, |
164 | LOG (GNUNET_ERROR_TYPE_ERROR, | 180 | strerror (ec)); |
165 | _ | 181 | LOG ( |
166 | ("This may be ok if someone is currently generating a private key.\n")); | 182 | GNUNET_ERROR_TYPE_ERROR, |
183 | _ ( | ||
184 | "This may be ok if someone is currently generating a private key.\n")); | ||
167 | } | 185 | } |
168 | short_wait (); | 186 | short_wait (); |
169 | continue; | 187 | continue; |
@@ -173,57 +191,56 @@ GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename) | |||
173 | /* eh, what!? File we opened is now gone!? */ | 191 | /* eh, what!? File we opened is now gone!? */ |
174 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); | 192 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
175 | if (GNUNET_YES != | 193 | if (GNUNET_YES != |
176 | GNUNET_DISK_file_unlock (fd, 0, | 194 | GNUNET_DISK_file_unlock (fd, |
177 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) | 195 | 0, |
196 | sizeof ( | ||
197 | struct GNUNET_CRYPTO_EddsaPrivateKey))) | ||
178 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 198 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
179 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | 199 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); |
180 | 200 | ||
181 | return NULL; | 201 | return NULL; |
182 | } | 202 | } |
183 | if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | 203 | if (GNUNET_OK != |
204 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | ||
184 | fs = 0; | 205 | fs = 0; |
185 | if (fs < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) | 206 | if (fs < sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) |
186 | { | 207 | { |
187 | /* maybe we got the read lock before the key generating | 208 | /* maybe we got the read lock before the key generating |
188 | * process had a chance to get the write lock; give it up! */ | 209 | * process had a chance to get the write lock; give it up! */ |
189 | if (GNUNET_YES != | 210 | if (GNUNET_YES != |
190 | GNUNET_DISK_file_unlock (fd, 0, | 211 | GNUNET_DISK_file_unlock (fd, |
191 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) | 212 | 0, |
213 | sizeof ( | ||
214 | struct GNUNET_CRYPTO_EddsaPrivateKey))) | ||
192 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 215 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
193 | if (0 == ++cnt % 10) | 216 | if (0 == ++cnt % 10) |
194 | { | 217 | { |
195 | LOG (GNUNET_ERROR_TYPE_ERROR, | 218 | LOG (GNUNET_ERROR_TYPE_ERROR, |
196 | _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), | 219 | _ ( |
220 | "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), | ||
197 | filename, | 221 | filename, |
198 | (unsigned int) fs, | 222 | (unsigned int) fs, |
199 | (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); | 223 | (unsigned int) sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); |
200 | LOG (GNUNET_ERROR_TYPE_ERROR, | 224 | LOG (GNUNET_ERROR_TYPE_ERROR, |
201 | _("This may be ok if someone is currently generating a key.\n")); | 225 | _ ("This may be ok if someone is currently generating a key.\n")); |
202 | } | 226 | } |
203 | short_wait (); /* wait a bit longer! */ | 227 | short_wait (); /* wait a bit longer! */ |
204 | continue; | 228 | continue; |
205 | } | 229 | } |
206 | break; | 230 | break; |
207 | } | 231 | } |
208 | fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey); | 232 | fs = sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey); |
209 | priv = GNUNET_malloc (fs); | 233 | priv = GNUNET_malloc (fs); |
210 | sret = GNUNET_DISK_file_read (fd, | 234 | sret = GNUNET_DISK_file_read (fd, priv, fs); |
211 | priv, | 235 | GNUNET_assert ((sret >= 0) && (fs == (size_t) sret)); |
212 | fs); | ||
213 | GNUNET_assert ( (sret >= 0) && | ||
214 | (fs == (size_t) sret) ); | ||
215 | if (GNUNET_YES != | 236 | if (GNUNET_YES != |
216 | GNUNET_DISK_file_unlock (fd, | 237 | GNUNET_DISK_file_unlock (fd, |
217 | 0, | 238 | 0, |
218 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) | 239 | sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey))) |
219 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 240 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
220 | "fcntl", | 241 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
221 | filename); | ||
222 | GNUNET_assert (GNUNET_YES == | ||
223 | GNUNET_DISK_file_close (fd)); | ||
224 | #if CRYPTO_BUG | 242 | #if CRYPTO_BUG |
225 | if (GNUNET_OK != | 243 | if (GNUNET_OK != check_eddsa_key (priv)) |
226 | check_eddsa_key (priv)) | ||
227 | { | 244 | { |
228 | GNUNET_break (0); | 245 | GNUNET_break (0); |
229 | GNUNET_free (priv); | 246 | GNUNET_free (priv); |
@@ -258,16 +275,16 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename) | |||
258 | uint64_t fs; | 275 | uint64_t fs; |
259 | ssize_t sret; | 276 | ssize_t sret; |
260 | 277 | ||
261 | if (GNUNET_SYSERR == | 278 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) |
262 | GNUNET_DISK_directory_create_for_file (filename)) | ||
263 | return NULL; | 279 | return NULL; |
264 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 280 | while (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
265 | { | 281 | { |
266 | fd = GNUNET_DISK_file_open (filename, | 282 | fd = |
267 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 283 | GNUNET_DISK_file_open (filename, |
268 | | GNUNET_DISK_OPEN_FAILIFEXISTS, | 284 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | |
269 | GNUNET_DISK_PERM_USER_READ | | 285 | GNUNET_DISK_OPEN_FAILIFEXISTS, |
270 | GNUNET_DISK_PERM_USER_WRITE); | 286 | GNUNET_DISK_PERM_USER_READ | |
287 | GNUNET_DISK_PERM_USER_WRITE); | ||
271 | if (NULL == fd) | 288 | if (NULL == fd) |
272 | { | 289 | { |
273 | if (EEXIST == errno) | 290 | if (EEXIST == errno) |
@@ -275,25 +292,21 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename) | |||
275 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 292 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
276 | { | 293 | { |
277 | /* must exist but not be accessible, fail for good! */ | 294 | /* must exist but not be accessible, fail for good! */ |
278 | if (0 != ACCESS (filename, R_OK)) | 295 | if (0 != access (filename, R_OK)) |
279 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, | 296 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", filename); |
280 | "access", | ||
281 | filename); | ||
282 | else | 297 | else |
283 | GNUNET_break (0); /* what is going on!? */ | 298 | GNUNET_break (0); /* what is going on!? */ |
284 | return NULL; | 299 | return NULL; |
285 | } | 300 | } |
286 | continue; | 301 | continue; |
287 | } | 302 | } |
288 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, | 303 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); |
289 | "open", | ||
290 | filename); | ||
291 | return NULL; | 304 | return NULL; |
292 | } | 305 | } |
293 | cnt = 0; | 306 | cnt = 0; |
294 | while (GNUNET_YES != | 307 | while (GNUNET_YES != |
295 | GNUNET_DISK_file_lock (fd, | 308 | GNUNET_DISK_file_lock (fd, |
296 | 0, | 309 | 0, |
297 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 310 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), |
298 | GNUNET_YES)) | 311 | GNUNET_YES)) |
299 | { | 312 | { |
@@ -302,46 +315,41 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename) | |||
302 | { | 315 | { |
303 | ec = errno; | 316 | ec = errno; |
304 | LOG (GNUNET_ERROR_TYPE_ERROR, | 317 | LOG (GNUNET_ERROR_TYPE_ERROR, |
305 | _("Could not acquire lock on file `%s': %s...\n"), | 318 | _ ("Could not acquire lock on file `%s': %s...\n"), |
306 | filename, | 319 | filename, |
307 | STRERROR (ec)); | 320 | strerror (ec)); |
308 | } | 321 | } |
309 | } | 322 | } |
310 | LOG (GNUNET_ERROR_TYPE_INFO, | 323 | LOG (GNUNET_ERROR_TYPE_INFO, |
311 | _("Creating a new private key. This may take a while.\n")); | 324 | _ ("Creating a new private key. This may take a while.\n")); |
312 | priv = GNUNET_CRYPTO_ecdsa_key_create (); | 325 | priv = GNUNET_CRYPTO_ecdsa_key_create (); |
313 | GNUNET_assert (NULL != priv); | 326 | GNUNET_assert (NULL != priv); |
314 | GNUNET_assert (sizeof (*priv) == | 327 | GNUNET_assert (sizeof (*priv) == |
315 | GNUNET_DISK_file_write (fd, | 328 | GNUNET_DISK_file_write (fd, priv, sizeof (*priv))); |
316 | priv, | ||
317 | sizeof (*priv))); | ||
318 | GNUNET_DISK_file_sync (fd); | 329 | GNUNET_DISK_file_sync (fd); |
319 | if (GNUNET_YES != | 330 | if (GNUNET_YES != |
320 | GNUNET_DISK_file_unlock (fd, 0, | 331 | GNUNET_DISK_file_unlock (fd, |
332 | 0, | ||
321 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 333 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
322 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 334 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
323 | "fcntl", | 335 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
324 | filename); | ||
325 | GNUNET_assert (GNUNET_YES == | ||
326 | GNUNET_DISK_file_close (fd)); | ||
327 | return priv; | 336 | return priv; |
328 | } | 337 | } |
329 | /* key file exists already, read it! */ | 338 | /* key file exists already, read it! */ |
330 | fd = GNUNET_DISK_file_open (filename, | 339 | fd = GNUNET_DISK_file_open (filename, |
331 | GNUNET_DISK_OPEN_READ, | 340 | GNUNET_DISK_OPEN_READ, |
332 | GNUNET_DISK_PERM_NONE); | 341 | GNUNET_DISK_PERM_NONE); |
333 | if (NULL == fd) | 342 | if (NULL == fd) |
334 | { | 343 | { |
335 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, | 344 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "open", filename); |
336 | "open", | ||
337 | filename); | ||
338 | return NULL; | 345 | return NULL; |
339 | } | 346 | } |
340 | cnt = 0; | 347 | cnt = 0; |
341 | while (1) | 348 | while (1) |
342 | { | 349 | { |
343 | if (GNUNET_YES != | 350 | if (GNUNET_YES != |
344 | GNUNET_DISK_file_lock (fd, 0, | 351 | GNUNET_DISK_file_lock (fd, |
352 | 0, | ||
345 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 353 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), |
346 | GNUNET_NO)) | 354 | GNUNET_NO)) |
347 | { | 355 | { |
@@ -349,78 +357,70 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename) | |||
349 | { | 357 | { |
350 | ec = errno; | 358 | ec = errno; |
351 | LOG (GNUNET_ERROR_TYPE_ERROR, | 359 | LOG (GNUNET_ERROR_TYPE_ERROR, |
352 | _("Could not acquire lock on file `%s': %s...\n"), | 360 | _ ("Could not acquire lock on file `%s': %s...\n"), |
353 | filename, | 361 | filename, |
354 | STRERROR (ec)); | 362 | strerror (ec)); |
355 | LOG (GNUNET_ERROR_TYPE_ERROR, | 363 | LOG ( |
356 | _("This may be ok if someone is currently generating a private key.\n")); | 364 | GNUNET_ERROR_TYPE_ERROR, |
365 | _ ( | ||
366 | "This may be ok if someone is currently generating a private key.\n")); | ||
357 | } | 367 | } |
358 | short_wait (); | 368 | short_wait (); |
359 | continue; | 369 | continue; |
360 | } | 370 | } |
361 | if (GNUNET_YES != | 371 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
362 | GNUNET_DISK_file_test (filename)) | ||
363 | { | 372 | { |
364 | /* eh, what!? File we opened is now gone!? */ | 373 | /* eh, what!? File we opened is now gone!? */ |
365 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 374 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", filename); |
366 | "stat", | ||
367 | filename); | ||
368 | if (GNUNET_YES != | 375 | if (GNUNET_YES != |
369 | GNUNET_DISK_file_unlock (fd, 0, | 376 | GNUNET_DISK_file_unlock (fd, |
370 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 377 | 0, |
371 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 378 | sizeof ( |
372 | "fcntl", | 379 | struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
373 | filename); | 380 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
374 | GNUNET_assert (GNUNET_OK == | 381 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); |
375 | GNUNET_DISK_file_close (fd)); | ||
376 | 382 | ||
377 | return NULL; | 383 | return NULL; |
378 | } | 384 | } |
379 | if (GNUNET_OK != | 385 | if (GNUNET_OK != |
380 | GNUNET_DISK_file_size (filename, | 386 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) |
381 | &fs, | ||
382 | GNUNET_YES, | ||
383 | GNUNET_YES)) | ||
384 | fs = 0; | 387 | fs = 0; |
385 | if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) | 388 | if (fs < sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) |
386 | { | 389 | { |
387 | /* maybe we got the read lock before the key generating | 390 | /* maybe we got the read lock before the key generating |
388 | * process had a chance to get the write lock; give it up! */ | 391 | * process had a chance to get the write lock; give it up! */ |
389 | if (GNUNET_YES != | 392 | if (GNUNET_YES != |
390 | GNUNET_DISK_file_unlock (fd, 0, | 393 | GNUNET_DISK_file_unlock (fd, |
391 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 394 | 0, |
392 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 395 | sizeof ( |
393 | "fcntl", | 396 | struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
394 | filename); | 397 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
395 | if (0 == ++cnt % 10) | 398 | if (0 == ++cnt % 10) |
396 | { | 399 | { |
397 | LOG (GNUNET_ERROR_TYPE_ERROR, | 400 | LOG (GNUNET_ERROR_TYPE_ERROR, |
398 | _("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), | 401 | _ ( |
399 | filename, (unsigned int) fs, | 402 | "When trying to read key file `%s' I found %u bytes but I need at least %u.\n"), |
403 | filename, | ||
404 | (unsigned int) fs, | ||
400 | (unsigned int) sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | 405 | (unsigned int) sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); |
401 | LOG (GNUNET_ERROR_TYPE_ERROR, | 406 | LOG (GNUNET_ERROR_TYPE_ERROR, |
402 | _("This may be ok if someone is currently generating a key.\n")); | 407 | _ ("This may be ok if someone is currently generating a key.\n")); |
403 | } | 408 | } |
404 | short_wait (); /* wait a bit longer! */ | 409 | short_wait (); /* wait a bit longer! */ |
405 | continue; | 410 | continue; |
406 | } | 411 | } |
407 | break; | 412 | break; |
408 | } | 413 | } |
409 | fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 414 | fs = sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); |
410 | priv = GNUNET_malloc (fs); | 415 | priv = GNUNET_malloc (fs); |
411 | sret = GNUNET_DISK_file_read (fd, | 416 | sret = GNUNET_DISK_file_read (fd, priv, fs); |
412 | priv, | 417 | GNUNET_assert ((sret >= 0) && (fs == (size_t) sret)); |
413 | fs); | ||
414 | GNUNET_assert ( (sret >= 0) && | ||
415 | (fs == (size_t) sret) ); | ||
416 | if (GNUNET_YES != | 418 | if (GNUNET_YES != |
417 | GNUNET_DISK_file_unlock (fd, 0, | 419 | GNUNET_DISK_file_unlock (fd, |
420 | 0, | ||
418 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) | 421 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) |
419 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 422 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
420 | "fcntl", | 423 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
421 | filename); | ||
422 | GNUNET_assert (GNUNET_YES == | ||
423 | GNUNET_DISK_file_close (fd)); | ||
424 | return priv; | 424 | return priv; |
425 | } | 425 | } |
426 | 426 | ||
@@ -434,7 +434,8 @@ GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename) | |||
434 | * permission denied) | 434 | * permission denied) |
435 | */ | 435 | */ |
436 | struct GNUNET_CRYPTO_EddsaPrivateKey * | 436 | struct GNUNET_CRYPTO_EddsaPrivateKey * |
437 | GNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) | 437 | GNUNET_CRYPTO_eddsa_key_create_from_configuration ( |
438 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
438 | { | 439 | { |
439 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv; | 440 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv; |
440 | char *fn; | 441 | char *fn; |
@@ -465,7 +466,7 @@ GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
465 | if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg))) | 466 | if (NULL == (priv = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg))) |
466 | { | 467 | { |
467 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 468 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
468 | _("Could not load peer's private key\n")); | 469 | _ ("Could not load peer's private key\n")); |
469 | return GNUNET_SYSERR; | 470 | return GNUNET_SYSERR; |
470 | } | 471 | } |
471 | GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key); | 472 | GNUNET_CRYPTO_eddsa_key_get_public (priv, &dst->public_key); |