initial working implementation of ssh agent
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
use sqlx::{
|
||||
Encode,
|
||||
FromRow,
|
||||
Sqlite,
|
||||
SqlitePool,
|
||||
sqlite::SqliteRow,
|
||||
Transaction,
|
||||
Type,
|
||||
types::Uuid,
|
||||
};
|
||||
use tokio_stream::StreamExt;
|
||||
|
@@ -21,12 +21,14 @@ use sqlx::{
|
||||
Transaction,
|
||||
types::Uuid,
|
||||
};
|
||||
use ssh_agent_lib::proto::message::Identity;
|
||||
use ssh_key::{
|
||||
Algorithm,
|
||||
LineEnding,
|
||||
private::PrivateKey,
|
||||
public::PublicKey,
|
||||
};
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
use crate::errors::*;
|
||||
use super::{
|
||||
@@ -73,6 +75,37 @@ impl SshKey {
|
||||
private_key: privkey,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn name_from_pubkey(pubkey: &[u8], pool: &SqlitePool) -> Result<String, LoadCredentialsError> {
|
||||
let row = sqlx::query!(
|
||||
"SELECT c.name
|
||||
FROM credentials c
|
||||
JOIN ssh_credentials s
|
||||
ON s.id = c.id
|
||||
WHERE s.public_key = ?",
|
||||
pubkey
|
||||
).fetch_optional(pool)
|
||||
.await?
|
||||
.ok_or(LoadCredentialsError::NoCredentials)?;
|
||||
|
||||
Ok(row.name)
|
||||
}
|
||||
|
||||
pub async fn list_identities(pool: &SqlitePool) -> Result<Vec<Identity>, LoadCredentialsError> {
|
||||
let mut rows = sqlx::query!(
|
||||
"SELECT public_key, comment FROM ssh_credentials"
|
||||
).fetch(pool);
|
||||
|
||||
let mut identities = Vec::new();
|
||||
while let Some(row) = rows.try_next().await? {
|
||||
identities.push(Identity {
|
||||
pubkey_blob: row.public_key,
|
||||
comment: row.comment,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(identities)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user