X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcrypto_rsa.c;h=5820065301f0a20b541600b151bc74ab91dd6ec8;hb=d47f834c1f2de41c9fba74a4b6928e7c8e0679e0;hp=c3e0a7833881a12e53efd7365e31726c02038ad5;hpb=652e89b59ed2207c2c12172fdabcd6e659995c81;p=oweals%2Fgnunet.git diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index c3e0a7833..582006530 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -566,6 +566,8 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) unsigned int cnt; int ec; uint64_t fs; + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; + struct GNUNET_PeerIdentity pid; if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) return NULL; @@ -576,12 +578,23 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE | - GNUNET_DISK_PERM_GROUP_READ); + GNUNET_DISK_PERM_USER_WRITE); if (NULL == fd) { if (errno == EEXIST) - continue; + { + if (GNUNET_YES != GNUNET_DISK_file_test (filename)) + { + /* must exist but not be accessible, fail for good! */ + if (0 != ACCESS (filename, R_OK)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "access", filename); + else + GNUNET_break (0); /* what is going on!? */ + return NULL; + } + continue; + } GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); return NULL; @@ -622,8 +635,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); + GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); + GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Stored new private key in `%s'.\n"), filename); + _("I am host `%s'. Stored new private key in `%s'.\n"), + GNUNET_i2s (&pid), + filename); return ret; } /* hostkey file exists already, read it! */ @@ -642,7 +659,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) sizeof (struct RsaPrivateKeyBinaryEncoded), GNUNET_NO)) { - if (0 == ++cnt % 10) + if (0 == ++cnt % 60) { ec = errno; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -707,8 +724,14 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ - ("File `%s' does not contain a valid private key. You should delete it.\n"), + ("File `%s' does not contain a valid private key. Deleting it.\n"), filename); + if (0 != UNLINK (filename)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "unlink", + filename); + } } GNUNET_free (enc); if (GNUNET_YES != @@ -716,6 +739,15 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) sizeof (struct RsaPrivateKeyBinaryEncoded))) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); + if (ret != NULL) + { + GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); + GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("I am host `%s'. Read private key from `%s'.\n"), + GNUNET_i2s (&pid), + filename); + } return ret; } @@ -747,6 +779,8 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, GNUNET_assert (size <= sizeof (GNUNET_HashCode)); pubkey = public2PrivateKey (publicKey); + if (pubkey == NULL) + return GNUNET_SYSERR; isize = size; GNUNET_assert (0 == gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize));