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
24 changes: 14 additions & 10 deletions ci/apiv2/hashtopolis_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@ def _load_config():


class ProcessState(enum.IntEnum):
""" See src/inc/defines/hashcat.php for mapping"""
""" See src/inc/defines/DHashcatStatus.php for mapping"""
INIT = 0
AUTOTUNE = 1
RUNNING = 2
PAUSED = 3
EXHAUSTED = 4
CRACKED = 5
ABORTED = 6
QUIT = 7
BYPASS = 8
ABORTED_CHECKPOINT = 9
STATUS_ABORTED_RUNTIME = 10
SELFTEST = 2
RUNNING = 3
PAUSED = 4
EXHAUSTED = 5
CRACKED = 6
ABORTED = 7
QUIT = 8
BYPASS = 9
ABORTED_CHECKPOINT = 10
ABORTED_RUNTIME = 11
ERROR = 13
ABORTED_FINISH = 14
AUTODETECT = 16


class HashtopolisConfig(object):
Expand Down
83 changes: 63 additions & 20 deletions ci/apiv2/test_agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ def test_get_chunk_fully_dispatched(self):
"keyspaceProgress": resp['skip'] + resp['length'],
"relativeProgress": 10000,
"speed": 1000,
"state": 4,
"state": 5,
"cracks": [],
})
code, body = agent_request({
Expand Down Expand Up @@ -1438,7 +1438,7 @@ def _make_chunk(self, dummy, task_id):
return self._drive_agent_to_chunk(dummy, task_id)

@staticmethod
def _send_progress(token, chunk, state=2, cracks=None, progress=100):
def _send_progress(token, chunk, state=3, cracks=None, progress=100):
"""Send a progress update and return the parsed response."""
_, body = agent_request({
"action": "sendProgress",
Expand Down Expand Up @@ -1583,7 +1583,7 @@ def test_send_progress_no_zaps_without_other_cracks(self):
self.assertNotIn(self.CRACK_HASH, resp['zaps'])

def test_send_progress_state_aborted(self):
"""Sending progress with state=ABORTED (6) returns error 'Chunk was aborted!'."""
"""Sending progress with state=ABORTED (7) returns error 'Chunk was aborted!'."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
code, body = agent_request({
Expand All @@ -1593,14 +1593,14 @@ def test_send_progress_state_aborted(self):
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 6,
"state": 7,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!")

def test_send_progress_state_quit(self):
"""Sending progress with state=QUIT (7) returns error 'Chunk was aborted!'."""
"""Sending progress with state=QUIT (8) returns error 'Chunk was aborted!'."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
code, body = agent_request({
Expand All @@ -1610,12 +1610,55 @@ def test_send_progress_state_quit(self):
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 7,
"state": 8,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!")

def test_send_progress_state_error(self):
"""Sending progress with state=ERROR (13) returns error 'Chunk was aborted!'."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
code, body = agent_request({
"action": "sendProgress",
"token": dummy.token,
"chunkId": chunk['chunkId'],
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 13,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!")

def test_send_progress_state_aborted_finish(self):
"""Sending progress with state=ABORTED_FINISH (14) returns error 'Chunk was aborted!'."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
code, body = agent_request({
"action": "sendProgress",
"token": dummy.token,
"chunkId": chunk['chunkId'],
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 14,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!")

def test_send_progress_state_transient_states(self):
"""Transient states SELFTEST (2) and AUTODETECT (16) are handled like RUNNING."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
resp = self._send_progress(dummy.token, chunk, state=2)
self.assertEqual(resp['response'], "SUCCESS")
resp = self._send_progress(dummy.token, chunk, state=16)
self.assertEqual(resp['response'], "SUCCESS")

def test_send_progress_on_already_aborted_chunk(self):
"""Sending progress on an already-aborted chunk returns 'Chunk was aborted!' via the aborting path."""
dummy, agent, task, _ = self._setup_with_two_hashes()
Expand All @@ -1627,7 +1670,7 @@ def test_send_progress_on_already_aborted_chunk(self):
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 6,
"state": 7,
"cracks": [],
})
code, body = agent_request({
Expand All @@ -1637,14 +1680,14 @@ def test_send_progress_on_already_aborted_chunk(self):
"keyspaceProgress": chunk['skip'] + 2,
"relativeProgress": 200,
"speed": 5700,
"state": 2,
"state": 3,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Chunk was aborted!")

def test_send_progress_state_status_aborted_runtime(self):
"""Sending progress with state=STATUS_ABORTED_RUNTIME (10) returns 'Chunk was manually interrupted.'."""
def test_send_progress_state_aborted_runtime(self):
"""Sending progress with state=ABORTED_RUNTIME (11) returns 'Chunk was manually interrupted.'."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
code, body = agent_request({
Expand All @@ -1654,17 +1697,17 @@ def test_send_progress_state_status_aborted_runtime(self):
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 10,
"state": 11,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Chunk was manually interrupted.")

def test_send_progress_state_exhausted(self):
"""Sending progress with state=EXHAUSTED (4) returns SUCCESS with cracked/skipped fields."""
"""Sending progress with state=EXHAUSTED (5) returns SUCCESS with cracked/skipped fields."""
dummy, agent, task, _ = self._setup_with_two_hashes()
chunk = self._make_chunk(dummy, task.id)
resp = self._send_progress(dummy.token, chunk, state=4, progress=100)
resp = self._send_progress(dummy.token, chunk, state=5, progress=100)
self.assertEqual(resp['response'], "SUCCESS")
self.assertIsInstance(resp['cracked'], int)
self.assertIsInstance(resp['skipped'], int)
Expand All @@ -1678,7 +1721,7 @@ def test_send_progress_agent_stop_on_all_cracked(self):
"""
dummy, agent, task, _ = self._setup_assigned_agent()
chunk = self._make_chunk(dummy, task.id)
resp = self._send_progress(dummy.token, chunk, state=2, cracks=[
resp = self._send_progress(dummy.token, chunk, state=3, cracks=[
[self.CRACK_HASH, self.CRACK_PLAIN, self.CRACK_HEX, "1"],
])
self.assertEqual(resp['response'], "SUCCESS")
Expand All @@ -1694,7 +1737,7 @@ def test_send_progress_invalid_chunk(self):
"keyspaceProgress": 1,
"relativeProgress": 1,
"speed": 1,
"state": 2,
"state": 3,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
Expand All @@ -1712,7 +1755,7 @@ def test_send_progress_not_assigned_to_chunk(self):
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 2,
"state": 3,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
Expand All @@ -1731,7 +1774,7 @@ def test_send_progress_inactive_agent(self):
"keyspaceProgress": chunk['skip'] + 1,
"relativeProgress": 100,
"speed": 5700,
"state": 2,
"state": 3,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
Expand All @@ -1746,20 +1789,20 @@ def test_send_progress_invalid_token(self):
"keyspaceProgress": 1,
"relativeProgress": 1,
"speed": 1,
"state": 2,
"state": 3,
"cracks": [],
})
assert_error_envelope(self, body, "sendProgress")
self.assertEqual(parse_envelope(body)['message'], "Invalid token!")

def test_send_progress_state_cracked(self):
"""Sending progress with state=CRACKED (5) returns SUCCESS (deprioritizes all tasks and unassigns all agents).
"""Sending progress with state=CRACKED (6) returns SUCCESS (deprioritizes all tasks and unassigns all agents).

Uses a single-hash hashlist so cracking it triggers the CRACKED state.
"""
dummy, agent, task, _ = self._setup_assigned_agent()
chunk = self._make_chunk(dummy, task.id)
resp = self._send_progress(dummy.token, chunk, state=5, cracks=[
resp = self._send_progress(dummy.token, chunk, state=6, cracks=[
[self.CRACK_HASH, self.CRACK_PLAIN, self.CRACK_HEX, "1"],
])
self.assertEqual(resp['response'], "SUCCESS")
Expand Down
5 changes: 4 additions & 1 deletion ci/apiv2/test_realworld_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def test_chunk_pagination_on_large_task(self):
first_ids = [chunk.id for chunk in first_page]
self.assertEqual(first_ids, list(range(1157, 1167)))
self.assertTrue(all(chunk.taskId == 1308 for chunk in first_page))
self.assertTrue(all(chunk.state == 4 for chunk in first_page))
# State 5 is EXHAUSTED in hashcat's aligned status_rc_t enum; the dump itself
# still carries the old pre-SELFTEST numbering (4) which the server migration
# shifts on startup.
self.assertTrue(all(chunk.state == 5 for chunk in first_page))

second_page = Chunk.objects.paginate(size=10, after=self._cursor_after('chunkId', first_ids[-1])) \
.filter(taskId=1308).order_by('chunkId').get_pagination()
Expand Down
11 changes: 8 additions & 3 deletions ci/phpunit/inc/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Hashtopolis\dba\models\StoredValue;
use Hashtopolis\TestBase;
use Hashtopolis\inc\defines\DConfig;
use Hashtopolis\inc\defines\DHashcatStatus;

require_once(dirname(__FILE__) . '/../TestBase.php');

Expand Down Expand Up @@ -618,9 +619,13 @@ public function testGetStaticArrayOsUnknown(): void {
* getStaticArray returns the state label for each chunk state.
*/
public function testGetStaticArrayStates(): void {
$this->assertEquals("New", Util::getStaticArray("0", "states"));
$this->assertEquals("Running", Util::getStaticArray("2", "states"));
$this->assertEquals("Cracked", Util::getStaticArray("5", "states"));
$this->assertEquals("New", Util::getStaticArray(DHashcatStatus::INIT, "states"));
$this->assertEquals("Running", Util::getStaticArray(DHashcatStatus::RUNNING, "states"));
$this->assertEquals("Cracked", Util::getStaticArray(DHashcatStatus::CRACKED, "states"));
$this->assertEquals("Aborted at runtime", Util::getStaticArray(DHashcatStatus::ABORTED_RUNTIME, "states"));
$this->assertEquals("Error", Util::getStaticArray(DHashcatStatus::ERROR, "states"));
$this->assertEquals("Autodetect", Util::getStaticArray(DHashcatStatus::AUTODETECT, "states"));
$this->assertEquals("Unknown", Util::getStaticArray(12, "states"));
}

/**
Expand Down
57 changes: 57 additions & 0 deletions ci/phpunit/inc/defines/DHashcatStatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Hashtopolis\inc\defines;

use PHPUnit\Framework\TestCase;

require_once(dirname(__FILE__) . '/../../../../src/inc/defines/DHashcatStatus.php');

/**
* Unit tests for {@see DHashcatStatus} — the chunk state constants must stay
* in sync with hashcat's status_rc_t enum (include/types.h in the hashcat
* repository).
*/
final class DHashcatStatusTest extends TestCase {
/**
* The constants mirror hashcat's status_rc_t values, including the gaps at
* 12 and 15 which hashcat does not use.
*/
public function testValuesMatchHashcatStatusRc(): void {
$this->assertSame(0, DHashcatStatus::INIT);
$this->assertSame(1, DHashcatStatus::AUTOTUNE);
$this->assertSame(2, DHashcatStatus::SELFTEST);
$this->assertSame(3, DHashcatStatus::RUNNING);
$this->assertSame(4, DHashcatStatus::PAUSED);
$this->assertSame(5, DHashcatStatus::EXHAUSTED);
$this->assertSame(6, DHashcatStatus::CRACKED);
$this->assertSame(7, DHashcatStatus::ABORTED);
$this->assertSame(8, DHashcatStatus::QUIT);
$this->assertSame(9, DHashcatStatus::BYPASS);
$this->assertSame(10, DHashcatStatus::ABORTED_CHECKPOINT);
$this->assertSame(11, DHashcatStatus::ABORTED_RUNTIME);
$this->assertSame(13, DHashcatStatus::ERROR);
$this->assertSame(14, DHashcatStatus::ABORTED_FINISH);
$this->assertSame(16, DHashcatStatus::AUTODETECT);
}

/**
* ABORTED_STATES covers exactly the states telling that a chunk was stopped
* prematurely and none of the states of a normally completed chunk.
*/
public function testAbortedStatesContents(): void {
$this->assertSame(
[
DHashcatStatus::ABORTED,
DHashcatStatus::QUIT,
DHashcatStatus::BYPASS,
DHashcatStatus::ABORTED_CHECKPOINT,
DHashcatStatus::ABORTED_RUNTIME,
DHashcatStatus::ERROR,
DHashcatStatus::ABORTED_FINISH,
],
DHashcatStatus::ABORTED_STATES
);
$this->assertNotContains(DHashcatStatus::EXHAUSTED, DHashcatStatus::ABORTED_STATES);
$this->assertNotContains(DHashcatStatus::CRACKED, DHashcatStatus::ABORTED_STATES);
}
}
6 changes: 5 additions & 1 deletion ci/phpunit/inc/utils/AccessGroupUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function testAbortChunksGroupOnlyAbortsInitAndRunningChunks(): void {
$statusCases = [
DHashcatStatus::INIT => DHashcatStatus::ABORTED,
DHashcatStatus::AUTOTUNE => DHashcatStatus::AUTOTUNE,
DHashcatStatus::SELFTEST => DHashcatStatus::SELFTEST,
DHashcatStatus::RUNNING => DHashcatStatus::ABORTED,
DHashcatStatus::PAUSED => DHashcatStatus::PAUSED,
DHashcatStatus::EXHAUSTED => DHashcatStatus::EXHAUSTED,
Expand All @@ -154,7 +155,10 @@ public function testAbortChunksGroupOnlyAbortsInitAndRunningChunks(): void {
DHashcatStatus::QUIT => DHashcatStatus::QUIT,
DHashcatStatus::BYPASS => DHashcatStatus::BYPASS,
DHashcatStatus::ABORTED_CHECKPOINT => DHashcatStatus::ABORTED_CHECKPOINT,
DHashcatStatus::STATUS_ABORTED_RUNTIME => DHashcatStatus::STATUS_ABORTED_RUNTIME,
DHashcatStatus::ABORTED_RUNTIME => DHashcatStatus::ABORTED_RUNTIME,
DHashcatStatus::ERROR => DHashcatStatus::ERROR,
DHashcatStatus::ABORTED_FINISH => DHashcatStatus::ABORTED_FINISH,
DHashcatStatus::AUTODETECT => DHashcatStatus::AUTODETECT,
];


Expand Down
Loading
Loading