Make sure disabling old RSA keys works on Windows.

Seeking in files and rewriting parts of them does not seem to work properly on
Windows. Instead, when old RSA keys are found when generating new ones, the
file containing the old keys is copied to a temporary file where the changes
are made, and that file is renamed back to the original filename. On Windows,
we cannot atomically replace files with a rename(), so we need to move the
original file out of the way first. If anything fails, the new code will warn
that the user has to solve the problem by hand.
This commit is contained in:
Guus Sliepen 2012-03-08 23:23:39 +01:00
parent 2f1c337c54
commit 5b0f5ad958
3 changed files with 67 additions and 46 deletions

View file

@ -362,9 +362,6 @@ static bool keygen(int bits) {
if(!f)
return false;
if(disable_old_keys(f))
fprintf(stderr, "Warning: old key(s) found and disabled.\n");
#ifdef HAVE_FCHMOD
/* Make it unreadable for others. */
fchmod(fileno(f), 0600);
@ -385,9 +382,6 @@ static bool keygen(int bits) {
if(!f)
return false;
if(disable_old_keys(f))
fprintf(stderr, "Warning: old key(s) found and disabled.\n");
fputc('\n', f);
PEM_write_RSAPublicKey(f, rsa_key);
fclose(f);