Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pcrDev.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"HashAlgorithm": "Sha384 { ... }",
"PCR0": "c17aa763c3b3380b874ca846a87df09705bfef194883914bb8e718d340b690b9c44ecee45a4796cf2b314617596070a8",
"PCR0": "b467001371e0b922ac598b385aecad0167c25e8d5a4f6e35bae7533c01b2b4563522b67f0ca2eb3d842187429c5c38d1",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "d51c91d66ec80f17ca1e9a78b4e8b921a92673cac31abbe4a2f64a67a1acda2a3c26058faf120249212e96916f39946d"
"PCR2": "597692561e55d33bde78152e863c29f157ebbd5f53870bcc8db2bdbe8a64ee1a219f090136e692e2bc7be2d8c9db6f34"
}
7 changes: 7 additions & 0 deletions pcrDevHistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,5 +439,12 @@
"PCR2": "d51c91d66ec80f17ca1e9a78b4e8b921a92673cac31abbe4a2f64a67a1acda2a3c26058faf120249212e96916f39946d",
"timestamp": 1763841286,
"signature": "1XP/1Ln+yDIUXzTZaPWoBA7A4ZvkiHfqsCG8pV3b3xrGobUGR/XU1zWLG8p1tMh8Dz1mQrkOz8CmK/bYiiGthy4H8kjhKmPie8elgM14Vv2qsaTHwKTCQeT217GJVRgq"
},
{
"PCR0": "b467001371e0b922ac598b385aecad0167c25e8d5a4f6e35bae7533c01b2b4563522b67f0ca2eb3d842187429c5c38d1",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "597692561e55d33bde78152e863c29f157ebbd5f53870bcc8db2bdbe8a64ee1a219f090136e692e2bc7be2d8c9db6f34",
"timestamp": 1763921652,
"signature": "Jq36eNC1xEVENoBI+XDO19ODY0cCWTxMf5yq308Ai0y9njRQgZOvIzC2cV/+kkXXyac0sMUNZ/m4jNy2ytnsC8XVPiIZGvuc+tjF/E8spZtqjgjZhfpwHQvyo6POghQt"
}
]
4 changes: 2 additions & 2 deletions pcrProd.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"HashAlgorithm": "Sha384 { ... }",
"PCR0": "dbd61a9a17e02b9fc9b595a9826576af81156263e6ebaa909d0549ece19290ab9bcf0fbedb0fd96fe362d40053db33f4",
"PCR0": "964567ff931b87294d6a0b1a6d3040b83225375e8a60df4b78460812cd0cef93d7f45627105c1e3301cd6610e81ac144",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "f06c680d76fe22e86c5534cecb0841b824afc3b7222fd63d10537dfde62ebbdfa73c279c64f7bb0ed929e28c49a25938"
"PCR2": "9ab7c221d344ceb7f0432c8f3fa1aac73fa1b28b32360e8f7885f782979622424fe702c379af55aae897bab2ceaf6c51"
}
7 changes: 7 additions & 0 deletions pcrProdHistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,5 +439,12 @@
"PCR2": "f06c680d76fe22e86c5534cecb0841b824afc3b7222fd63d10537dfde62ebbdfa73c279c64f7bb0ed929e28c49a25938",
"timestamp": 1763841305,
"signature": "IaNLKy0lkCIE9xbBz5sNXQvFX4gZHPAGkirB81EKKx2p2heSEG2BdkesrqIJHBBP6htDy1c3LGyIkMoaqdNP794JnBLxm8zhHFm3QzlMSIfnTh3CvX8pekXk1+xW9pxF"
},
{
"PCR0": "964567ff931b87294d6a0b1a6d3040b83225375e8a60df4b78460812cd0cef93d7f45627105c1e3301cd6610e81ac144",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "9ab7c221d344ceb7f0432c8f3fa1aac73fa1b28b32360e8f7885f782979622424fe702c379af55aae897bab2ceaf6c51",
"timestamp": 1763921684,
"signature": "HPtRy8w/xyfn9ceivfWighJjtCX8V/qjViO2dLVmNkr5MfJIW6Cd0DuIXbe7JR4cfzWokWXsUQEEIpeoZZDz+k9b14f003dgDKwtUTUYd9e+QoMOuMcbH3xyiqfa6I/N"
}
]
11 changes: 11 additions & 0 deletions src/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ pub fn delete(
}
}

pub fn delete_all(
pool: &diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<PgConnection>>,
user_id: Uuid,
) -> StoreResult<()> {
let mut conn = pool.get().map_err(|_| {
StoreError::DatabaseError(UserKVError::DatabaseError(diesel::result::Error::NotFound))
})?;

UserKV::delete_all_for_user(&mut conn, user_id).map_err(StoreError::DatabaseError)
}

pub fn list(
pool: &diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<PgConnection>>,
user_id: Uuid,
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,10 @@ impl AppState {
kv::delete(self.db.get_pool(), user_id, &key, &user_key)
}

async fn delete_all(&self, user_id: Uuid) -> StoreResult<()> {
kv::delete_all(self.db.get_pool(), user_id)
}

async fn list(&self, user_id: Uuid) -> StoreResult<Vec<KVPair>> {
let user_key = self
.get_user_key(user_id, None, None)
Expand Down
11 changes: 11 additions & 0 deletions src/models/user_kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ impl UserKV {
.map(|_| ())
.map_err(UserKVError::DatabaseError)
}

pub fn delete_all_for_user(
conn: &mut PgConnection,
lookup_user_id: Uuid,
) -> Result<(), UserKVError> {
diesel::delete(user_kv::table)
.filter(user_kv::user_id.eq(lookup_user_id))
.execute(conn)
.map(|_| ())
.map_err(UserKVError::DatabaseError)
}
}

#[derive(Insertable)]
Expand Down
28 changes: 28 additions & 0 deletions src/web/protected_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ pub fn router(app_state: Arc<AppState>) -> Router<()> {
"/protected/kv",
get(list_kv).layer(from_fn_with_state(app_state.clone(), decrypt_request::<()>)),
)
.route(
"/protected/kv",
delete(delete_all_kv)
.layer(from_fn_with_state(app_state.clone(), decrypt_request::<()>)),
)
.route(
"/protected/request_verification",
post(request_new_verification_code)
Expand Down Expand Up @@ -696,6 +701,29 @@ pub async fn delete_kv(
}
}

pub async fn delete_all_kv(
State(data): State<Arc<AppState>>,
Extension(user): Extension<User>,
Extension(session_id): Extension<Uuid>,
) -> Result<Json<EncryptedResponse<serde_json::Value>>, ApiError> {
debug!("Entering delete_all_kv function");
info!("Deleting all key-value pairs for user");

match data.delete_all(user.uuid).await {
Ok(_) => {
let response = json!({
"message": "All key-value pairs deleted successfully"
});
debug!("Exiting delete_all_kv function");
encrypt_response(&data, &session_id, &response).await
}
Err(e) => {
tracing::error!("Error deleting all key-value pairs: {:?}", e);
Err(ApiError::InternalServerError)
}
}
}

pub async fn list_kv(
State(data): State<Arc<AppState>>,
Extension(user): Extension<User>,
Expand Down