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

Feat/os keychain followup #1770

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Conversation

elizabethengelman
Copy link
Contributor

@elizabethengelman elizabethengelman commented Dec 2, 2024

What

This PR is based on #1703 and adds some additional compatibility with the secure store like keys rm and keys add.

  • keys rm
  • keys add
  • manual test on Mac OS
    • add the key: cargo run keys add --secure-store alice (will be prompted for a seed phrase)
    • make sure we can get the address from the new key: cargo run keys address alice
    • make sure we can sign & send with the new key:
        stello contract deploy --wasm target/test-wasms/hello_world.wasm  --build-only --network testnet --source alice | \
        stello tx simulate --network testnet --source alice | \
        stello tx sign --network testnet --sign-with-key alice | \
        stello tx send --network testnet
    
    • remove the key: stello keys rm alice
    • make sure it is no longer in the list or the keychain
  • manual test on Linux
  • manual test on Windows

Why

I wanted to keep #1703 from getting too big so it was easier to review.

Known limitations

[TODO or N/A]

@elizabethengelman elizabethengelman force-pushed the feat/os-keychain-followup branch 2 times, most recently from 244508d to a97ccbb Compare December 2, 2024 20:59
@elizabethengelman elizabethengelman force-pushed the feat/os-keychain-followup branch 3 times, most recently from df3543a to 3311a50 Compare December 3, 2024 17:18
@elizabethengelman elizabethengelman force-pushed the feat/os-keychain-followup branch 4 times, most recently from c39bf60 to fe02078 Compare December 6, 2024 16:19
@elizabethengelman elizabethengelman marked this pull request as ready for review December 6, 2024 16:58
@elizabethengelman elizabethengelman force-pushed the feat/os-keychain-followup branch 2 times, most recently from f4e2913 to 3acc3d0 Compare December 13, 2024 14:31
Copy link
Member

@willemneal willemneal left a comment

Choose a reason for hiding this comment

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

I still need to try this out locally, but correct me if I'm wrong, but it's possible to have the name used in keys add differ from what is used in entry-name?

@elizabethengelman
Copy link
Contributor Author

@willemneal

... it's possible to have the name used in keys add differ from what is used in entry-name?

Good call! Yeah, at the moment, this is possible. It still ends up working because we are saving the value of --entry-name in the <NAME>.toml file, like this: entry_name = "secure_store:org.stellar.cli-<NAME>. And then getting that entry_name from the toml file when accessing the public key, or using the private key.

Though, this may be confusing. 🤔

Instead, we could remove the --entry-name flag, and when adding a new key, require that the key name is the same as the entry name in the OS's secure store. So, this command would change to be: cargo run keys add alice.

But, now I'm starting to wonder if we shouldn't allow users to add keys from the keychain at all. If we do, we'd need to make sure that users add the keys to their secure store with:

  1. the key name prepended with secure_store:org.stellar.cli-
  2. the key saved as a base64 encoded ed25519_dalek::SigningKey

And we could probably do that, but I'm not sure how necessary this feature is. 🤔

@elizabethengelman
Copy link
Contributor Author

elizabethengelman commented Jan 8, 2025

Since we are now planning to store the seed phrase instead of the signing key in the OS secure storage, I think that a more useful feature would be to allow a user to add a new key with their seed phrase, which is saved in secure storage instead of in the local file. So the command could look like this:

cargo run keys add <NAME> --secure-store

which would then prompt the user to enter their seed phrase:

Type a 12/24 word seed phrase:
...

Base automatically changed from feat/os_keychain to main January 9, 2025 20:57
@elizabethengelman elizabethengelman force-pushed the feat/os-keychain-followup branch from 7b8d00c to 8e234bc Compare January 14, 2025 18:50
let path = self.config_locator.write_identity(&self.name, &secret)?;
print.checkln(format!("Key saved with alias {:?} in {path:?}", self.name));
Ok(())
}

fn read_secret(&self, print: &Print) -> Result<Secret, Error> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this here from config/secret.rs - i was seeing an interesting cyclical dependency, and moving this here helped that be a bit less confusing.

let prompt = "Type a 12 or 24 word seed phrase:";
let secret_key = read_password(print, prompt)?;

let seed_phrase: SeedPhrase = secret_key.parse()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment I only added support for a user to add a new seed phrase to secure storage. I'm happy to make a change so that this supports adding a private key directly as well, but wanted to get some more eyes on this to see if folks thought it was worth the effort.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's always a mistake to use a private key directly when storing keys. It has no recovery method and almost all wallets to my knowledge use a seed phrase so if users would be importing it wouldn't be a Secret Key.

cmd/soroban-cli/src/commands/keys/generate.rs Show resolved Hide resolved
@@ -0,0 +1,59 @@
use sep5::SeedPhrase;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure if this needs its own mod, or exactly where to put this, but I wanted to pull the code out where both add and generate could use it

@sagpatil sagpatil requested a review from fnando January 23, 2025 23:03
}

fn write_to_secure_store(
entry_name: &String,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
entry_name: &String,
entry_name: &str,

Comment on lines 268 to 282
if let Secret::SecureStore { entry_name } = identity {
let entry = StellarEntry::new(&entry_name)?;
match entry.delete_seed_phrase() {
Ok(()) => {}
Err(e) => match e {
signer::keyring::Error::Keyring(keyring::Error::NoEntry) => {
print.infoln("This key was already removed from the secure store. Removing the cli config file.");
}
_ => {
return Err(Error::Keyring(e));
}
},
}
}
KeyType::Identity.remove(name, &self.config_dir()?)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this will be an issue, but it seems like it could be possible for the keyring to successfully delete the key but not the Identity file? I think we can assume this isn't the case since we read the id first.

@willemneal
Copy link
Member

🎉

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

Successfully merging this pull request may close these issues.

2 participants