add alternate entry mode for ssh keys
This commit is contained in:
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user