diff --git a/cracklab/server/repositories/handshakes.py b/cracklab/server/repositories/handshakes.py index 38f32a6..04a47ab 100644 --- a/cracklab/server/repositories/handshakes.py +++ b/cracklab/server/repositories/handshakes.py @@ -75,6 +75,60 @@ class HandshakesRepository: parameters, ).fetchall() + def list_eligible_for_search_context( + self, + token_hash: str, + method_id: str, + method_version: int, + limit: int | None, + ) -> list[sqlite3.Row]: + return self._conn.execute( + """ + SELECT + h.id AS handshake_id, + h.hash22000, + h.access_point_id, + h.captured_at + FROM crack_search_context_handshakes AS sch + INNER JOIN handshakes AS h + ON h.id = sch.handshake_id + WHERE sch.token_hash = ? + AND h.hash22000 IS NOT NULL + AND TRIM(h.hash22000) <> '' + AND NOT EXISTS ( + SELECT 1 + FROM credentials AS c + WHERE c.handshake_id = h.id + ) + AND NOT EXISTS ( + SELECT 1 + FROM crack_attempts AS a + WHERE a.handshake_id = h.id + AND a.method_id = ? + AND a.method_version = ? + AND a.status = 'COMPLETED' + ) + AND NOT EXISTS ( + SELECT 1 + FROM crack_reservations AS r + WHERE r.handshake_id = h.id + AND r.method_id = ? + AND r.method_version = ? + AND r.status = 'ACTIVE' + ) + ORDER BY h.id + LIMIT ? + """, + ( + token_hash, + method_id, + method_version, + method_id, + method_version, + limit if limit is not None else -1, + ), + ).fetchall() + def get_method_statistics( self, method_id: str,