Skip to content

Commit a4a1e3a

Browse files
committed
fix: cached key not decrypted beforehand
1 parent e3d518f commit a4a1e3a

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

crates/backend/src/config/cache.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use crate::parameter;
22
use async_trait::async_trait;
3-
use redis::aio::ConnectionManager;
3+
use redis::aio::{MultiplexedConnection};
44

55
#[derive(Clone)]
66
pub struct Cache {
7-
conn: ConnectionManager,
7+
conn: MultiplexedConnection,
88
}
99

1010
#[async_trait]
1111
pub trait CacheTrait {
1212
async fn init() -> Result<Self, redis::RedisError>
1313
where
1414
Self: Sized;
15-
fn get_cache(&mut self) -> &mut ConnectionManager;
15+
fn get_cache(&mut self) -> &mut MultiplexedConnection;
1616
}
1717

1818
#[async_trait]
@@ -22,14 +22,14 @@ impl CacheTrait for Cache {
2222
let client = redis::Client::open(cache)
2323
.unwrap_or_else(|e| panic!("preparing connection to cache err: {}", e));
2424

25-
let cache_conn = client.get_connection_manager()
25+
let cache_conn = client.get_multiplexed_tokio_connection()
2626
.await
2727
.unwrap_or_else(|e| panic!("connection to cache err: {}", e));
2828

2929
Ok(Self { conn: cache_conn })
3030
}
3131

32-
fn get_cache(&mut self) -> &mut ConnectionManager {
32+
fn get_cache(&mut self) -> &mut MultiplexedConnection {
3333
&mut self.conn
3434
}
3535
}

crates/backend/src/service/payload_sec.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,14 @@ impl PayloadSecurityServiceTrait for PayloadSecurityService {
300300
},
301301
};
302302

303-
// let decoded_key = BASE64.decode(get("DB_KEY").as_bytes()).map_err(|e| KeypairError::Yabai(format!("failed to decode key: {e}")))?;
304-
// let key: GenericArray<u8, U32> = GenericArray::clone_from_slice(&decoded_key);
305-
306-
// let mut hashmsg = meta.public_key.clone();
307-
// hashmsg.extend(meta.private_key.clone());
303+
let decoded_key = BASE64.decode(get("DB_KEY").as_bytes()).map_err(|e| KeypairError::Yabai(format!("failed to decode key: {e}")))?;
304+
let key: GenericArray<u8, U32> = GenericArray::clone_from_slice(&decoded_key);
308305

309-
// let sk = corelib::security::aes256_decrypt(key, &meta.private_key)
310-
// .map_err(|e| KeypairError::Yabai(e.to_string()))?;
306+
let mut hashmsg = meta.public_key.clone();
307+
hashmsg.extend(meta.private_key.clone());
311308

312-
let sk = meta.private_key;
309+
let sk = corelib::security::aes256_decrypt(key, &meta.private_key)
310+
.map_err(|e| KeypairError::Yabai(e.to_string()))?;
313311

314312
// validate key
315313
let key = SecretKey::from_slice(&sk)

0 commit comments

Comments
 (0)