add alternate entry mode for ssh keys

This commit is contained in:
2024-07-03 16:28:12 -04:00
parent ae93a57aab
commit 10231df860
11 changed files with 71 additions and 11 deletions

View File

@ -53,6 +53,7 @@ pub fn run() -> tauri::Result<()> {
ipc::delete_credential,
ipc::list_credentials,
ipc::sshkey_from_file,
ipc::sshkey_from_private_key,
ipc::get_config,
ipc::save_config,
ipc::launch_terminal,

View File

@ -74,6 +74,21 @@ impl SshKey {
})
}
pub fn from_private_key(private_key: &str, passphrase: &str) -> Result<SshKey, LoadSshKeyError> {
let mut privkey = PrivateKey::from_openssh(private_key)?;
if privkey.is_encrypted() {
privkey = privkey.decrypt(passphrase)
.map_err(|_| LoadSshKeyError::InvalidPassphrase)?;
}
Ok(SshKey {
algorithm: privkey.algorithm(),
comment: privkey.comment().into(),
public_key: privkey.public_key().clone(),
private_key: privkey,
})
}
pub async fn name_from_pubkey(pubkey: &[u8], pool: &SqlitePool) -> Result<String, LoadCredentialsError> {
let row = sqlx::query!(
"SELECT c.name

View File

@ -142,6 +142,12 @@ pub async fn sshkey_from_file(path: &str, passphrase: &str) -> Result<SshKey, Lo
}
#[tauri::command]
pub async fn sshkey_from_private_key(private_key: &str, passphrase: &str) -> Result<SshKey, LoadSshKeyError> {
SshKey::from_private_key(private_key, passphrase)
}
#[tauri::command]
pub async fn get_config(app_state: State<'_, AppState>) -> Result<AppConfig, ()> {
let config = app_state.config.read().await;