Commit graph

102 commits

Author SHA1 Message Date
Lukas Puehringer
ff8819577b Adopt sslib keygen interface encryption changes
secure-systems-lab/securesystemslib#288 changes the key generation
interface functions in such a way that it is clear if a call opens
a blocking prompt, or writes the key unencrypted. To do this two
functions are added per key type:
 - `generate_and_write_*_keypair_with_prompt`
 - `generate_and_write_unencrypted_*_keypair`

The default `generate_and_write_*_keypair` function now only allows
encrypted keys and only using a passed password. This respects the
principle of secure defaults and least surprise.

sslib#288 furthermore adds a protected
`_generate_and_write_*_keypair`, which is not exposed publicly
because it does not encrypt by default, but is more flexible and
thus convenient e.g. to consume all arguments from a key generation
command line tool such as 'repo.py'.

This commit adds the new public functions to the tuf namespace and
adopts their usage accordingly.

NOTE regarding repo.py:
This commit does not fix any problematic password behavior of
'repo.py' like default passwords, etc. (see #881). It only adopts
the sslib#288 changes to maintain the current behvior, plus
removing one glaringly obsolete password prompt.

NOTE regarding key import:
The securesystemslib private key import functions were also changed
to no longer auto-prompt for decryption passwords , TUF, however,
only exposes custom wrappers (see repository_lib) that do
auto-prompt. sslib#288 changes to the prompt texts are nevertheless
propagated to tuf and reflected in this commit.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-11-11 10:27:56 +01:00
Joshua Lock
d4705502fc repo: make colorama a soft dependency
Instead of using colorama directly for terminal colours, use the
constants in securesystemslib.interface which map to colorama colours
IFF colorama is installed.

This change results in a red password prompt when colorama is installed
and a standard terminal output coloured prompt when colorama is not
installed.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-10-20 15:23:39 +01:00
Martin Vrachev
946d11bca4 Make confined_target_dirs optional field
The field confined_target_dirs from the MIRROR_SCHEMA  is
a list of strings. Those strings define the accessible target
paths for that mirror. For one target to be available for that mirror,
its path should have as a prefix at least one of the strings defined
in confined_target_dirs.

That's why when confined_target_dirs is a list with one element empty
string (e.g. ['']) this means all targets files on that mirror are
available and if confined_target_dirs is empty list (e.g. []) this
would be interpreted as none of the target files is available.

This is a confusing API that could easily lead to mistakes.
That's why it's better we promote to not set confined_target_dirs
at all if a user wants targets to be available.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-10-16 15:35:24 +03:00
Teodora Sechkova
0ebe226fb6
Re-raise exceptions explicitly using the 'from' keyword
Versions 2.6.0 and later of pylint adhere to PEP 3134
and trigger a 'raise-missing-from' warning (W0707) when
chained exceptions are raised implicitly.

The 'from' keyword is a Python3.x feature, that is why
six.raise_from is used for Python2.x compatibility.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-24 13:44:09 +03:00
Jussi Kukkonen
e662f4fda0 repo.py: Decode key bytes for SHA key as well
key bytes were decoded as utf-8 for the JSON keys. Do the same for SHA
key bytes.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-07-03 11:45:12 +03:00
lukpueh
256aef8695
Merge pull request #989 from joshuagl/logger
Use __name__ for loggers, per convention
2020-03-11 14:33:35 +01:00
Joshua Lock
292b18926b Use __name__ for loggers, per convention
Replace hard-coded logger names with __name__. For the most part this just uses
the standard conventions to create the same logger hierarchy as existed before.
The only real difference is that loggers created for printing during tests are
no longer part of the 'tuf' hierarchy.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-03 10:36:39 +00:00
Lukas Puehringer
842f843210 Remove duplicate testing simple_server.py
tests/simple_server.py was copied to tuf/scripts/ to "make testing
easier" (cf84d3f51f), although with
the current test setup the original (and recently patched to fix an
Windows/Py2 test issue) test simple_server.py can be used just as
well.

This commit:
- removes tuf/scripts/simple_server.py
  Note: that version slightly differed from the original test
  server, probably due to demands by the linter that is only executed
  on the tuf core code and not on the tests. However, for the testing
  purposes of simple_server.py these changes (i.e., `SystemRandom()`,
  `if __name__ =='__main__':`) are not necessary.
- updates the tests that used tuf.scripts.simple_server to instead
  use tests.simple_server,
- updates setup.py to not install the simple_server module as
  script, when installing tuf, as it is only a testing script and
  not meant for end-user usage.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-25 14:55:36 +01:00
chentanjun
04019a1bd8 fix-up some spelling mistakes
Signed-off-by: chentanjun <2799194073@qq.com>
2019-09-26 00:52:21 +08:00
chentanjun
560d45dca2 fix-up the document spelling mistake
Signed-off-by: chentanjun <2799194073@qq.com>
2019-08-27 14:41:24 +08:00
Michael Zhou
bcbb213613 Added command-line option explanations and usage examples
Signed-off-by: Michael Zhou <myz227@nyu.edu>
2018-11-03 10:48:05 -04:00
Vladimir Diaz
e42874db46
Catch tuf.exceptions.Error in client.py to prevent printing exception trace
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-28 12:38:55 -04:00
Vladimir Diaz
a300122978
Reorder the parsed command-line arguments and add missing options to docstring
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-28 12:37:54 -04:00
Vladimir Diaz
d24f826009
Condense the code that sets the logging level
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-28 11:51:19 -04:00
Vladimir Diaz
56aa91239b
Use guard clause and comment on expected exceptions raised by try block
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-28 11:34:59 -04:00
Vladimir Diaz
839c646204
Convert lists to sets, use == instead of membership operator, remove unneeded write()
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-28 11:02:36 -04:00
Vladimir Diaz
16071e0421
Use set() instead list() for supported key types, and revise comment
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-27 17:58:38 -04:00
Vladimir Diaz
609889fa24
Use guard clause and set a constant for the list of supported CLI key types
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-27 17:44:28 -04:00
Vladimir Diaz
5e94dd3f08
Use consistent number of blank lines between functions
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-27 17:28:47 -04:00
Vladimir Diaz
8a7e0fc4b0
Add constants for the keytypes specified on the command line
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-27 16:54:32 -04:00
Vladimir Diaz
52ed7a2a04
Add note about using multile options in invocation, and add TODO
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-27 16:06:10 -04:00
Vladimir Diaz
725d809c65
Rename process_arguments() and revise docstring, remove TODO, minor changes
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-27 15:42:03 -04:00
Vladimir Diaz
97021b4e16
Revise help description for --init
It should mention the files/directories that are created.

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-26 17:20:33 -04:00
Vladimir Diaz
d7feacbff5
Verify --no_release with --sign, edit comment in repo.py and document change in CLI.md
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-07 11:03:20 -04:00
Vladimir Diaz
2e2b1dd232
Add --no_release option to repo.py
The --no_release option applies to:
(1) delegate()
(2) revoke()
(3) sign_role()
(4) add_targets()
(5) remove_targets()

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-06 17:14:58 -04:00
Vladimir Diaz
6683d6e25f
Generate Ed25519 key with --key, by default
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-18 15:11:20 -04:00
Vladimir Diaz
55123ab73e
Generate Ed25519 keys in repo.py, by default
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-18 15:07:52 -04:00
Vladimir Diaz
0892812feb
Remove unused 'e' variable
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-18 10:53:49 -04:00
Vladimir Diaz
33734d31fd
Remove unused variables
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-18 10:52:26 -04:00
Vladimir Diaz
52519c8c34
Remove unused imports
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-18 10:48:56 -04:00
Vladimir Diaz
affc884c95
Fix 'tuf.exception' typo to resolve pylint warning
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-17 17:00:13 -04:00
Vladimir Diaz
dc9fedf9db
Resolve undefined variable warnings in repo.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-17 15:46:43 -04:00
Vladimir Diaz
9cd8a6d6a3
Resolve pylint warnings in client.py for 'redefined variable'
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-17 15:29:17 -04:00
Vladimir Diaz
7021dba285
Remove unused import statement in client.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-17 15:25:20 -04:00
Vladimir Diaz
8defb4ac0a
Add __init__.py to scripts directory
.. to mark it as a Python package directory

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-17 14:54:10 -04:00
Vladimir Diaz
b7c6275cef
Remove incorrect use of os.path.join in repo.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-13 11:25:06 -04:00
Vladimir Diaz
156f20fdfd
Fix issues encounted while expanding CLI.md and CLI_EXAMPLES.md
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-10 15:22:22 -04:00
Vladimir Diaz
717ad8a460
Use --targets_pw when signing the Targets role
Also, do not generate a new release if signing a delegated role

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-06 17:22:13 -04:00
Vladimir Diaz
fe5d335555
Modify modules to remove/expect no leading path separators
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-06 13:16:41 -04:00
Vladimir Diaz
b04e1be29a
Rename --consistent_snapshot to --consistent
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-02 13:56:16 -04:00
Vladimir Diaz
d428b75293
Do not allow a blank --sign
A missing or blank --sign causes the default targets key to be used.  Unfortunately, this action leads to unexpected behavior and confusion.  It's better if the user is required to specify a path with this option.

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-02 13:48:12 -04:00
Vladimir Diaz
ade0ba2e47
Allow multiple keys with --sign
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-30 17:01:15 -04:00
Vladimir Diaz
10039c857c
Allow any of the top-level to be signed with --sign
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-30 14:52:43 -04:00
Vladimir Diaz
9c57a7920a
Adjust default verbosity level and revise a couple exception msgs
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-30 11:03:53 -04:00
Vladimir Diaz
c178a7314c
Fix typo in error message
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-23 14:40:58 -04:00
Vladimir Diaz
173b6185af
Implement --distrust command-line option
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-23 14:11:44 -04:00
Vladimir Diaz
dfd88860c6
Make sure the keystore directory exists when moving default keys
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-22 14:07:44 -04:00
Vladimir Diaz
1bcafdb8a9
Implement --trust option
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-19 17:01:26 -04:00
Vladimir Diaz
5ff7a5ea84
Raise exception if --pubkeys not given while delegating
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-16 15:44:54 -04:00
Vladimir Diaz
3f3be4f94d
Remove obsolete code from repo.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-15 16:33:28 -04:00