diff --git a/Cargo.lock b/Cargo.lock index dbdb2c4..fef9b7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1670,9 +1670,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e136c1904604defe99ce5fd71a28d473fa60a12255d511aa78a9ddf11237aeb" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ "cfg-if", "cloudabi", @@ -2049,9 +2049,9 @@ dependencies = [ [[package]] name = "rsa-magic-public-key" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe89053790d2de7953814284a0d4b64edab2c9619103c6df7d133135fcfdafe" +checksum = "11bc74e37efd50ace66f9f250bb917d1370bee373b9d974f3873cda073d8e5ac" dependencies = [ "base64 0.11.0", "num-bigint-dig", @@ -2062,7 +2062,8 @@ dependencies = [ [[package]] name = "rsa-pem" version = "0.1.0" -source = "git+https://git.asonix.dog/Aardwolf/rsa-pem#8dc04bd060d7993058c120f5cbfa654890113614" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f5c8511d542ea4c96e1f7c4e8fb8010adceb741d3ff5d92673db44954b4abae" dependencies = [ "bit-vec", "log", @@ -2335,9 +2336,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "standback" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389164ce46e8a68e1b373787efcca3b6b6620bb50b12d4e8d14380838db316f" +checksum = "898341a519ec30272f8665dd05fb00156254310e99df3dc1e0cb096883d8656c" [[package]] name = "static_assertions" diff --git a/Cargo.toml b/Cargo.toml index c69717d..bc7692f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,8 +38,8 @@ num_cpus = "1.12" pretty_env_logger = "0.4.0" rand = "0.7" rsa = "0.2" -rsa-magic-public-key = "0.1.0" -rsa-pem = { version = "0.1.0", git = "https://git.asonix.dog/Aardwolf/rsa-pem" } +rsa-magic-public-key = "0.1.1" +rsa-pem = "0.1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sha2 = "0.8" diff --git a/src/data/state.rs b/src/data/state.rs index 6e8b215..bd0d9fb 100644 --- a/src/data/state.rs +++ b/src/data/state.rs @@ -155,7 +155,7 @@ impl State { let f3 = db.hydrate_listeners(); let f4 = async move { - if let Some(key) = db.hydrate_private_key().await? { + if let Ok(Some(key)) = db.hydrate_private_key().await { Ok(key) } else { info!("Generating new keys"); diff --git a/src/db.rs b/src/db.rs index 82e04cd..17c6c1d 100644 --- a/src/db.rs +++ b/src/db.rs @@ -165,8 +165,25 @@ impl Db { pub async fn update_private_key(&self, private_key: &RSAPrivateKey) -> Result<(), MyError> { let pem_pkcs8 = private_key.to_pem_pkcs8()?; - info!("INSERT INTO settings (key, value, created_at) VALUES ('private_key', $1::TEXT, 'now');"); - self.pool.get().await?.execute("INSERT INTO settings (key, value, created_at) VALUES ('private_key', $1::TEXT, 'now');", &[&pem_pkcs8]).await?; + info!( + "INSERT INTO settings (key, value, created_at) + VALUES ('private_key', $1::TEXT, 'now') + ON CONFLICT (key) + DO UPDATE + SET value = $1::TEXT;" + ); + self.pool + .get() + .await? + .execute( + "INSERT INTO settings (key, value, created_at) + VALUES ('private_key', $1::TEXT, 'now') + ON CONFLICT (key) + DO UPDATE + SET value = $1::TEXT;", + &[&pem_pkcs8], + ) + .await?; Ok(()) } }