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

Allow using password-protected private keys #797

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

fghanmi
Copy link

@fghanmi fghanmi commented Jul 26, 2024

Issue #, if available:
#796

Description of changes:

  • Added support for signing TUF repositories with password-protected private keys.
  • Implemented functionality to handle password protection during key management.
  • add unit tests

If the password is invalid, the code will throw the following error:
Failed to sign repository: Unable to parse keypair: Unrecognized private key format

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@fghanmi fghanmi force-pushed the KeyPass branch 2 times, most recently from c98f607 to c572489 Compare July 26, 2024 10:19
@fghanmi
Copy link
Author

fghanmi commented Jul 31, 2024

Hello @bcressey, @jpculp,
Could you please take a look when you have a moment?
Thank you in advance!

@jpculp
Copy link
Contributor

jpculp commented Aug 2, 2024

Hello @fghanmi! Thank you for this. I'll share this with the rest of the team, but while we take a look at it would you be able to do a rustfmt? The actions workflow will fail as is.

tough/Cargo.toml Outdated
@@ -35,6 +35,7 @@ typed-path = "0.9"
untrusted = "0.9"
url = "2"
walkdir = "2"
openssl = "0.10"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we have in the near past worked to remove openssl from the dependencies of tough and would prefer to keep it that way. Is there a way to adjust this implementation to rely on rustls instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that reading password encrypted private keys is not yet supported by rustls(pemfile) as per this issue. They've suggested to use pkcs8 instead.
So, I've done the same and removed openssl.

@fghanmi
Copy link
Author

fghanmi commented Aug 4, 2024

Hello @fghanmi! Thank you for this. I'll share this with the rest of the team, but while we take a look at it would you be able to do a rustfmt? The actions workflow will fail as is.

Hello @jpculp,
I tried it and it failed. But, I tried it on develop branch and it fails as well. I am not sure if I am using a rust version that is incompatible with this project.

@jpculp
Copy link
Contributor

jpculp commented Aug 12, 2024

I tried it and it failed.

I was able to run cargo fmt at the top level of the repo, but we can also push the adjustment if you'd rather we take care of it.

@fghanmi
Copy link
Author

fghanmi commented Aug 13, 2024

I tried it and it failed.

I was able to run cargo fmt at the top level of the repo, but we can also push the adjustment if you'd rather we take care of it.

@jpculp
Yes, cargo fmt is working fine without any errors on this PR branch.
I've updated the PR
Thanks!

Copy link
Contributor

@jpculp jpculp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the formatting fix! We are still evaluating this, but I left a couple of small changes in the code in the meantime.

tough/Cargo.toml Outdated Show resolved Hide resolved
tuftool/src/add_key_role.rs Outdated Show resolved Hide resolved
tuftool/src/root.rs Outdated Show resolved Hide resolved
tuftool/src/root.rs Outdated Show resolved Hide resolved
@fghanmi
Copy link
Author

fghanmi commented Sep 20, 2024

Hello @jpculp ,
any news regarding this PR, please ?

@jpculp
Copy link
Contributor

jpculp commented Sep 20, 2024

@fghanmi, apologies for the delays. It's still under review, but the gears are in motion. Something that might help is if you are able to include a small unit test for handling a password protected key. The same is true for adding a small test for SHA512 hashes in #814. Thank you for your patience in all of this.

@jpculp
Copy link
Contributor

jpculp commented Sep 23, 2024

Thank you for the quick follow-up! It looks like if we bump pkcs8 to 0.10 the duplicate dependencies will drop in the check-licenses action, but looks like it requires a tweak in the code. I suspect it requires something close to:

    let encrypted_private_key_document = pkcs8::EncryptedPrivateKeyInfo::from_der(pem.contents())?;
    let decrypted_private_key_document =
        encrypted_private_key_document.decrypt(password.as_bytes())?;
    let decrypted_key_bytes: Vec<u8> = decrypted_private_key_document.as_bytes().to_vec();

@jpculp
Copy link
Contributor

jpculp commented Sep 27, 2024

I think we're getting close here. @fghanmi, would you be able to include example output in the description if the password is incorrect?

@fghanmi
Copy link
Author

fghanmi commented Sep 30, 2024

Failed to sign repository: Unable to parse keypair: Unrecognized private key format

@jpculp , I hope I understood you correctly, I've added an error example to the PR description.

Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
Signed-off-by: Firas Ghanmi <[email protected]>
@jku
Copy link

jku commented Oct 16, 2024

I'm not a maintainer, so I'll leave this as a drive by comment, not a review:

In my opinion "--password" is an anti pattern in any cli: It practically guarantees users are going to make a mistake and the password is then available in shell history and /proc/.

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 this pull request may close these issues.

4 participants