… | |
… | |
33 | |
33 | |
34 | #include <openssl/err.h> |
34 | #include <openssl/err.h> |
35 | #include <openssl/pem.h> |
35 | #include <openssl/pem.h> |
36 | #include <openssl/rsa.h> |
36 | #include <openssl/rsa.h> |
37 | #include <openssl/rand.h> |
37 | #include <openssl/rand.h> |
|
|
38 | #include <openssl/bn.h> |
38 | |
39 | |
39 | #include "gettext.h" |
40 | #include "gettext.h" |
40 | |
41 | |
41 | #include "conf.h" |
42 | #include "conf.h" |
42 | #include "slog.h" |
43 | #include "slog.h" |
… | |
… | |
258 | |
259 | |
259 | if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL)) |
260 | if (!PEM_read_RSAPublicKey(f, &node->rsa_key, NULL, NULL)) |
260 | { |
261 | { |
261 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
262 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
262 | slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
263 | slog (L_ERR, _("unable to open public rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
263 | exit (1); |
264 | exit (EXIT_FAILURE); |
264 | } |
265 | } |
265 | |
266 | |
266 | RSA_blinding_on (node->rsa_key, 0); |
267 | require (RSA_blinding_on (node->rsa_key, 0)); |
267 | |
268 | |
268 | fclose (f); |
269 | fclose (f); |
269 | } |
270 | } |
270 | else |
271 | else |
271 | { |
272 | { |
272 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); |
273 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to read public rsa key file '%s': %s"), fname, strerror (errno)); |
273 | |
274 | |
274 | if (need_keys) |
275 | if (need_keys) |
275 | exit (1); |
276 | exit (EXIT_FAILURE); |
276 | } |
277 | } |
277 | |
278 | |
278 | free (fname); |
279 | free (fname); |
279 | } |
280 | } |
280 | |
281 | |
281 | if (!::thisnode || !strcmp (node->nodename, ::thisnode)) |
282 | if (::thisnode && !strcmp (node->nodename, ::thisnode)) |
282 | thisnode = node; |
283 | thisnode = node; |
283 | } |
284 | } |
284 | else if (!strcmp (var, "private-key")) |
285 | else if (!strcmp (var, "private-key")) |
285 | prikeyfile = strdup (val); |
286 | prikeyfile = strdup (val); |
286 | else if (!strcmp (var, "ifpersist")) |
287 | else if (!strcmp (var, "ifpersist")) |
… | |
… | |
389 | fclose (f); |
390 | fclose (f); |
390 | } |
391 | } |
391 | else |
392 | else |
392 | { |
393 | { |
393 | slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); |
394 | slog (L_ERR, _("unable to read config file '%s': %s"), fname, strerror (errno)); |
394 | exit (1); |
395 | exit (EXIT_FAILURE); |
395 | } |
396 | } |
396 | |
397 | |
397 | free (fname); |
398 | free (fname); |
398 | |
399 | |
399 | fname = config_filename (prikeyfile, "hostkey"); |
400 | fname = config_filename (prikeyfile, "hostkey"); |
… | |
… | |
405 | |
406 | |
406 | if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL)) |
407 | if (!PEM_read_RSAPrivateKey (f, &rsa_key, NULL, NULL)) |
407 | { |
408 | { |
408 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
409 | ERR_load_RSA_strings (); ERR_load_PEM_strings (); |
409 | slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
410 | slog (L_ERR, _("unable to read private rsa key file '%s': %s"), fname, ERR_error_string (ERR_get_error (), 0)); |
410 | exit (1); |
411 | exit (EXIT_FAILURE); |
411 | } |
412 | } |
412 | |
413 | |
413 | RSA_blinding_on (rsa_key, 0); |
414 | require (RSA_blinding_on (rsa_key, 0)); |
414 | |
415 | |
415 | fclose (f); |
416 | fclose (f); |
416 | } |
417 | } |
417 | else |
418 | else |
418 | { |
419 | { |
419 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); |
420 | slog (need_keys ? L_ERR : L_NOTICE, _("unable to open private rsa key file '%s': %s"), fname, strerror (errno)); |
420 | |
421 | |
421 | if (need_keys) |
422 | if (need_keys) |
422 | exit (1); |
423 | exit (EXIT_FAILURE); |
423 | } |
424 | } |
|
|
425 | |
|
|
426 | if (need_keys && ::thisnode |
|
|
427 | && rsa_key && thisnode && thisnode->rsa_key) |
|
|
428 | if (BN_cmp (rsa_key->n, thisnode->rsa_key->n) != 0 |
|
|
429 | || BN_cmp (rsa_key->e, thisnode->rsa_key->e) != 0) |
|
|
430 | { |
|
|
431 | slog (L_NOTICE, _("private hostkey and public node key mismatch: is '%s' the correct node?"), ::thisnode); |
|
|
432 | exit (EXIT_FAILURE); |
|
|
433 | } |
424 | |
434 | |
425 | free (fname); |
435 | free (fname); |
426 | } |
436 | } |
427 | |
437 | |
428 | char *configuration::config_filename (const char *name, const char *dflt) |
438 | char *configuration::config_filename (const char *name, const char *dflt) |