work on stuff
This commit is contained in:
		@@ -3,7 +3,8 @@ CREATE TABLE credentials (
 | 
			
		||||
    access_key_id TEXT NOT NULL,
 | 
			
		||||
    secret_key_enc BLOB NOT NULL,
 | 
			
		||||
    salt BLOB NOT NULL,
 | 
			
		||||
    nonce BLOB NOT NULL
 | 
			
		||||
    nonce BLOB NOT NULL,
 | 
			
		||||
    created_at INTEGER NOT NULL
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
CREATE TABLE config (
 | 
			
		||||
 
 | 
			
		||||
@@ -67,3 +67,10 @@ pub fn get_config(app_state: State<'_, AppState>) -> AppConfig {
 | 
			
		||||
    let config = app_state.config.read().unwrap();
 | 
			
		||||
    config.clone()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[tauri::command]
 | 
			
		||||
pub fn save_config(config: AppConfig, app_state: State<'_, AppState>) {
 | 
			
		||||
    let mut prev_config = app_state.config.write().unwrap();
 | 
			
		||||
    *prev_config = config;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@ fn main() {
 | 
			
		||||
            ipc::get_session_status,
 | 
			
		||||
            ipc::save_credentials,
 | 
			
		||||
            ipc::get_config,
 | 
			
		||||
            ipc::save_config,
 | 
			
		||||
        ])
 | 
			
		||||
        .setup(|app| {
 | 
			
		||||
            APP.set(app.handle()).unwrap();
 | 
			
		||||
 
 | 
			
		||||
@@ -91,7 +91,7 @@ impl AppState {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn load_creds(pool: &SqlitePool) -> Result<Session, SetupError> {
 | 
			
		||||
        let res = sqlx::query!("SELECT * FROM credentials")
 | 
			
		||||
        let res = sqlx::query!("SELECT * FROM credentials ORDER BY created_at desc")
 | 
			
		||||
            .fetch_optional(pool)
 | 
			
		||||
            .await?;
 | 
			
		||||
        let row = match res {
 | 
			
		||||
@@ -122,6 +122,10 @@ impl AppState {
 | 
			
		||||
            },
 | 
			
		||||
            _ => unreachable!(),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        // do this first so that if it fails we don't save bad credentials
 | 
			
		||||
        self.new_session(&key_id, &secret_key).await?;
 | 
			
		||||
 | 
			
		||||
        let salt = pwhash::gen_salt();
 | 
			
		||||
        let mut key_buf = [0; secretbox::KEYBYTES];
 | 
			
		||||
        pwhash::derive_key_interactive(&mut key_buf, passphrase.as_bytes(), &salt).unwrap();
 | 
			
		||||
@@ -133,8 +137,8 @@ impl AppState {
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        sqlx::query(
 | 
			
		||||
            "INSERT INTO credentials (access_key_id, secret_key_enc, salt, nonce)
 | 
			
		||||
            VALUES (?, ?, ?, ?)"
 | 
			
		||||
            "INSERT INTO credentials (access_key_id, secret_key_enc, salt, nonce, created_at)
 | 
			
		||||
            VALUES (?, ?, ?, ?, strftime('%s'))"
 | 
			
		||||
        )
 | 
			
		||||
            .bind(&key_id)
 | 
			
		||||
            .bind(&secret_key_enc)
 | 
			
		||||
@@ -143,8 +147,6 @@ impl AppState {
 | 
			
		||||
            .execute(&self.pool)
 | 
			
		||||
            .await?;
 | 
			
		||||
 | 
			
		||||
        self.new_session(&key_id, &secret_key).await?;
 | 
			
		||||
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user