mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
load os tor key from db
This commit is contained in:
committed by
Aiden McClelland
parent
cdca5e1b67
commit
6093518e46
@@ -55,10 +55,10 @@ pub async fn login(
|
||||
) -> Result<(), Error> {
|
||||
let rpc_ctx = ctx.as_rpc().unwrap();
|
||||
let mut handle = rpc_ctx.secret_store.acquire().await?;
|
||||
let pw_hash = sqlx::query!("SELECT hash FROM password")
|
||||
let pw_hash = sqlx::query!("SELECT password FROM account")
|
||||
.fetch_one(&mut handle)
|
||||
.await?
|
||||
.hash;
|
||||
.password;
|
||||
ensure_code!(
|
||||
argon2::verify_encoded(&pw_hash, password.as_bytes()).map_err(|_| {
|
||||
Error::new(
|
||||
|
||||
@@ -83,7 +83,7 @@ impl RpcContext {
|
||||
let net_controller = Arc::new(
|
||||
NetController::init(
|
||||
([127, 0, 0, 1], 80).into(),
|
||||
todo!("Grab Key from Database, Generate if it doesn't exist"),
|
||||
crate::net::tor::os_key(&mut secret_store.acquire().await?).await?,
|
||||
base.tor_control
|
||||
.unwrap_or(SocketAddr::from(([127, 0, 0, 1], 9051))),
|
||||
)
|
||||
|
||||
@@ -26,6 +26,7 @@ pub async fn get_product_key() -> Result<String, Error> {
|
||||
Ok(out.trim().to_owned())
|
||||
}
|
||||
|
||||
// cat /boot/product_key.txt | shasum -a 256 | head -c 8 | awk '{print "start9-"$1}' | xargs hostnamectl set-hostname
|
||||
pub async fn sync_hostname() -> Result<(), Error> {
|
||||
let key = get_product_key().await?;
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
|
||||
@@ -5,16 +5,41 @@ use std::time::Duration;
|
||||
use anyhow::anyhow;
|
||||
use futures::future::BoxFuture;
|
||||
use futures::FutureExt;
|
||||
use sqlx::{Executor, Sqlite};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::Mutex;
|
||||
use torut::control::{AsyncEvent, AuthenticatedConn, ConnError};
|
||||
use torut::onion::{OnionAddressV3, TorSecretKey, TorSecretKeyV3};
|
||||
use torut::onion::{OnionAddressV3, TorSecretKeyV3};
|
||||
|
||||
use super::interface::{InterfaceId, TorConfig};
|
||||
use crate::s9pk::manifest::PackageId;
|
||||
use crate::{Error, ErrorKind, ResultExt as _};
|
||||
|
||||
fn event_handler(event: AsyncEvent<'static>) -> BoxFuture<'static, Result<(), ConnError>> {
|
||||
#[test]
|
||||
fn random_key() {
|
||||
println!("'0x{}'", hex::encode(TorSecretKeyV3::generate().as_bytes()));
|
||||
}
|
||||
|
||||
pub async fn os_key<Ex>(secrets: &mut Ex) -> Result<TorSecretKeyV3, Error>
|
||||
where
|
||||
for<'a> &'a mut Ex: Executor<'a, Database = Sqlite>,
|
||||
{
|
||||
let key = sqlx::query!("SELECT tor_key FROM account")
|
||||
.fetch_one(secrets)
|
||||
.await?
|
||||
.tor_key;
|
||||
|
||||
let mut buf = [0; 64];
|
||||
buf.clone_from_slice(key.get(0..64).ok_or_else(|| {
|
||||
Error::new(
|
||||
anyhow!("Invalid Tor Key Length"),
|
||||
crate::ErrorKind::Database,
|
||||
)
|
||||
})?);
|
||||
Ok(buf.into())
|
||||
}
|
||||
|
||||
fn event_handler(_event: AsyncEvent<'static>) -> BoxFuture<'static, Result<(), ConnError>> {
|
||||
async move { Ok(()) }.boxed()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user