Skip to content
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

Load non-encrypted private keys and toggle password prompt #122

Closed
lukpueh opened this issue Mar 7, 2018 · 1 comment · Fixed by #288
Closed

Load non-encrypted private keys and toggle password prompt #122

lukpueh opened this issue Mar 7, 2018 · 1 comment · Fixed by #288

Comments

@lukpueh
Copy link
Member

lukpueh commented Mar 7, 2018

Description of issue or feature request:
The interface module provides functions to import RSA, ed25510 and ECDSA private keys from files.

The functions take an optional password argument and if no password is passed, the caller is prompted for a password. In either case the received password is used to decrypt the key. Hence, there is no way to load a non-password-encrypted private key without getting a prompt, or to fail if the key is encrypted but no password is passed, rather than prompting for a password.

This ticket proposes the addition of an optional boolean prompt argument to the functions:
import_rsa_privatekey_from_file(filepath, password=None, scheme='rsassa-pss-sha256')
import_ed25519_privatekey_from_file(filepath, password=None)
import_ecdsa_privatekey_from_file(filepath, password=None)

Current behavior:
If a password is passed, that password is used to decrypt the key.
If no password is passed, the user will be prompted for a password, which is used to decrypt the key.
Fail if the key can't be decrypted.

Expected behavior:
If a password is passed and prompt is False, the passed password is used to decrypt the key.
If prompt is True, the caller is prompted for a password, which is used to decrypt the key.
If no password is passed and prompt is False, the key will be loaded as non-encrypted key.
Fail if no password is passed and the key is decrypted.
Fail if a password is passed and the key can't be decrypted.

@lukpueh
Copy link
Member Author

lukpueh commented Mar 8, 2018

UPDATE:
The current behavior actually does allow loading non-encrypted keys. This can be achieved by passing an empty string as password, which does not trigger the prompt, but skips decryption.

IMHO, this behavior is not obvious. I think it is better to fail if an empty password is passed. If a caller wants to use the function to load a non-encrypted key, s/he should just not pass a password.

However, a user, who is prompted for a password, can only enter either a non-empty or an empty password. To give that user the option to load a non-encrypted key, we should skip decryption if the user does not enter a password, i.e. the password is an empty string.

lukpueh added a commit to lukpueh/securesystemslib that referenced this issue Mar 8, 2018
Add an optional boolean 'prompt' argument to
interface.import_rsa_privatekey_from_file and change the behavior
of the function like so:

If password is passed use passed password for decryption.
If prompt is True use entered password for decryption.
If no password is passed or entered, or if the entered password
is an empty string, omit decryption.
Passing and prompting for a passowrd is not possible.

See code comments or secure-systems-lab#122 for
more details.

This commit also adopts the unit tests accordingly.
lukpueh added a commit to lukpueh/securesystemslib that referenced this issue Mar 12, 2020
Fixes secure-systems-lab#122 together with secure-systems-lab#124 and secure-systems-lab#148
Prepares for fixing in-toto/in-toto#80

TODO (Maybe in separate PRs):

- support prompt arg for import_ecdsa_privatekey_from_file
  (see this commit)
- support prompt arg for interface.generate_and_write_*_keypair
- support password=None (no encryption) for
  generate_and_write_*_keypair (is there a way to check if
  encrypted?)

- add import_key_from_file(filepath, password=None, prompt=False, key_type=RSA), for pub/priv, rsa/ecdsa/ed25519
- add import_public_keys_from_file(filepaths, key_types=RSA), for pub/priv, rsa/ecdsa/ed25519
- add import_public_keys_from_gpg(keyids, gpg_home=None)

+ fix tests/docs/etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant