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

Bug: Improve error handling when not using encrypted key (without password) #789

Open
1 task done
kairoaraujo opened this issue Feb 7, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@kairoaraujo
Copy link
Member

What happened?

RSTUF requires an encrypted key for Root keys and encrypted keys for online keys when using PEM format.
Right now, we don't handle this well in the code (as of in the docs).

Please enter [yellow]path[/] to encrypted private key '[green]<securesystemslib.signer._key.SSlibKey object at 0x75ed13f2e1d0>[/]'/home/user/Desktop/repository-service-tuf/keys/keypair.pem

Please enter password to encrypted private key 'ali1': 
Traceback (most recent call last):
  File "/home/user/.local/bin/rstuf", line 8, in <module>
    sys.exit(rstuf())
             ^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/repository_service_tuf/cli/admin/ceremony.py", line 137, in ceremony
    _add_root_signatures_prompt(root_md, None)
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/repository_service_tuf/cli/admin/helpers.py", line 633, in _add_root_signatures_prompt
    _add_signature_prompt(root_md, key_choices[choice])
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/repository_service_tuf/cli/admin/helpers.py", line 589, in _add_signature_prompt
    signer = _load_signer_from_file_prompt(key)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/pipx/venvs/repository-service-tuf/lib/python3.11/site-packages/repository_service_tuf/cli/admin/helpers.py", line 254, in _load_signer_from_file_prompt
    private_key = load_pem_private_key(private_pem, password.encode())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Password was given but private key is not encrypted.

```code

### What steps did you take?

Se the parent issue for it.

### What behavior did you expect?

_No response_

### Relevant log output

```shell

Code of Conduct

  • I agree to follow this project's Code of Conduct
@kairoaraujo kairoaraujo added bug Something isn't working needs-triage The issue needs triage good first issue Good for newcomers and removed needs-triage The issue needs triage labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant