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

keys: add command warns on poor key practices #1809

Closed
wants to merge 1 commit into from
Closed

Conversation

leighmcculloch
Copy link
Member

What

Output a warning if word count is less than 24 when accepting seed phrases as a new key.

Also changed how the output of the add command is displayed to use the Print functionality to normalize the output like other newer commands.

Why

Close #1806

Known limitations

[TODO or N/A]

if let Ok(secret_key) = std::env::var("SOROBAN_SECRET_KEY") {
print.infoln("Read secret key from environment variable SOROBAN_SECRET_KEY");
Ok(Secret::SecretKey { secret_key })
Copy link
Member

Choose a reason for hiding this comment

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

Just realized there is no check here that it is a valid secret key. That's what we get for using a String when we should just use PrivateKey directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

@leighmcculloch
Copy link
Member Author

leighmcculloch commented Dec 19, 2024

Closing this because this warning is too aggressive. I had a moment and forgot that 12 word seed phrases are still 128-bit.

@leighmcculloch leighmcculloch deleted the i1806 branch December 19, 2024 15:33
if let Ok(secret_key) = std::env::var("SOROBAN_SECRET_KEY") {
print.infoln("Read secret key from environment variable SOROBAN_SECRET_KEY");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit

Suggested change
print.infoln("Read secret key from environment variable SOROBAN_SECRET_KEY");
print.infoln("Reading secret key from environment variable SOROBAN_SECRET_KEY");

.collect::<Vec<_>>();
let seed_words_len = seed_words.len();
if seed_words_len < 24 {
print.warnln("Warning, seed phrases containing less than 24 words may not be secure. It is safer to use a 24 word seed. To generate a new key and a 24 word seed phrase use the `stellar keys generate` command.");
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

.map(ToString::to_string)
.collect::<Vec<_>>()
.join(" "),
seed_phrase: seed_words.join(" "),
})
} else {
Err(Error::PasswordRead {})
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed that when a user doesn't pass --secret-key or --seed-phrase, we get to this else arm, but the error isn't super informative:

$ stellar keys add my-new-key

❌ error: secret input error

Perhaps we can add this, or just add a new error message for this case.

Suggested change
Err(Error::PasswordRead {})
print.errorln("No secret key or seed phrase provided. Please use one of these flags: `--secret-key` or `--seed-phrase`.");
Err(Error::PasswordRead {})

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, just noticed that this PR is closed. I can open a new PR with this small change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm removing the error in another PR anyway:

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, that's even better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

keys: add command can warn on poor key practices
3 participants