Apply restrictive permissions on private key files during creation#16
Apply restrictive permissions on private key files during creation#16aburgm merged 1 commit intogobby:masterfrom
Conversation
libinfinity/common/inf-file-util.c
Outdated
| inf_file_write_data_with_perms(const gchar* filename, | ||
| const void* data, | ||
| size_t length, | ||
| int flags, |
There was a problem hiding this comment.
I wonder if flags should really be an argument to this function given that it attempts to write to the newly created file immediately afterwards, and so passing or not passing certain flags does not make sense for it (such as everything that would result in the file being opened for reading only). In both cases this function is used, the flags are the same anyway, so we could just hardcode those inside this function.
|
Thanks! Can you also add the new One advantage of |
|
You're welcome! Many thanks for your feedback. I will incorporate your suggestions and update the PR accordingly. Regarding your last point: What do you mean by "loosing their private key"? I think in most of the cases (successful write) the old key is lost anyway (with and without applying your suggestion). Your suggestion only improves the failure case. Wouldn't it make sense to abort the key generation if a private key file (and possibly a certificate file) already exist? |
|
You are right, in the success case the previous key is lost anyway. I don't think it's an issue to overwrite an existing file, but it would be good to guarantee that either the previous or the new private key is available, and not to leave the user without any. I wouldn't prevent the key generation if another file already exists--if that is desired, it should be handled before calling |
|
Dear Armin, I think I have applied all your suggestion in the second commit. If you are fine with the changes, I will happily rebase them on the master branch. |
| g_free(temp_file); | ||
| return FALSE; | ||
| } | ||
| remaining -= written; |
There was a problem hiding this comment.
data needs to be advanced by written bytes at this point, or in the next iteration of the loop it will point to an incorrect location. Sorry I didn't see this the first time.
|
Thanks @hph86. I'll merge once those two remaining things are fixed. |
|
Oh, and you might also want to protect the implementation of the new function in an #ifdef block defaulting to |
libinfinity/common/inf-file-util.c
Outdated
| return g_file_set_contents( | ||
| filename, | ||
| string->str, | ||
| string->len, |
There was a problem hiding this comment.
Should be data and length instead of string->str and string->len.
|
Merged--Thanks for the contribution! |
This should fix #11.