-
Notifications
You must be signed in to change notification settings - Fork 53
Create private key files with read and write permissions for the user only #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6264e70
eb40113
9574d92
4d026be
0fffe11
c58d65d
6250c79
9432937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ | |||||||||
import tempfile | ||||||||||
import unittest | ||||||||||
import timeit | ||||||||||
import stat | ||||||||||
|
||||||||||
import securesystemslib.settings | ||||||||||
import securesystemslib.hash | ||||||||||
|
@@ -240,8 +241,18 @@ def test_B9_persist_temp_file(self): | |||||||||
dest_path = os.path.join(dest_temp_dir, self.random_string()) | ||||||||||
tmpfile = tempfile.TemporaryFile() | ||||||||||
tmpfile.write(self.random_string().encode('utf-8')) | ||||||||||
securesystemslib.util.persist_temp_file(tmpfile, dest_path) | ||||||||||
|
||||||||||
# Write a file with restricted permissions | ||||||||||
securesystemslib.util.persist_temp_file(tmpfile, dest_path, restrict=True) | ||||||||||
self.assertTrue(dest_path) | ||||||||||
|
||||||||||
# Need to set also the stat.S_IFREG bit to match the st_mode output | ||||||||||
# stat.S_IFREG - Regular file | ||||||||||
expected_mode = stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR | ||||||||||
if os.name == 'nt': | ||||||||||
# Windows only supports setting the read-only attribute. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment accurate? Doesn't 666 mean rw-rw-rw? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's really hard to locate and parse the docs around this. Python's
which I read as being effectively 0o666 on Windows. Some additional confusion creeps in because Python's
but I assume this means the mode cannot be changed from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the detailed research. Just ran the test on a windows box and it works. Having Windows CI does not seem to be a blocker for this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, great. I think I will push an extra commit to change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added that change as a suggestion https://github.com/secure-systems-lab/securesystemslib/pull/231/files#r988760854 |
||||||||||
expected_mode = stat.S_IFREG | stat.S_IWUSR | stat.S_IRUSR | stat.S_IWGRP | stat.S_IRGRP | stat.S_IWOTH | stat.S_IROTH | ||||||||||
self.assertEqual(os.stat(dest_path).st_mode, expected_mode) | ||||||||||
self.assertTrue(tmpfile.closed) | ||||||||||
|
||||||||||
# Test persisting a file without automatically closing the tmpfile | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.