-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rudamentary, as it only checks gen_psk() and not ssl.wrap_socket (and as such won't catch issues like sslpsk#16), but the best we can do for now and without modifying the code itself.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
"""Test the smarthack.pskproxy module.""" | ||
|
||
# Copyright (c) 2020 Faidon Liambotis | ||
# SPDX-License-Identifier: MIT | ||
|
||
import pytest # type: ignore | ||
|
||
from smarthack.pskproxy import IDENTITY_PREFIX, gen_psk | ||
|
||
|
||
PREFIX = b"\x01" + IDENTITY_PREFIX | ||
HINT = b"1dHRsc2NjbHltbGx3eWh5" b"0000000000000000" # taken from the code being tested | ||
PRECOMPUTED = ( | ||
("", "310ab75a8d067ccea734482eb07adf04"), | ||
("00" * 16, "3100cad5df5a8f719407b55e0ff55e883c53ab665efe02bd1bb93d7eda9e15e2"), | ||
("80" * 16, "36ac9fe6f25bb46b652eeb78c9dbf2c6675f82bf574808da316295cab811efc5"), | ||
( | ||
"fef0f7f7d1fff1602f64cbdb482d86dc5f35949857a88ba085f9c17b7cae02ed95", | ||
"5578f55f9e82e8ab7ea053cbacc7a3f4cc1cfd51ac202a447c5e3155bf347078", | ||
), | ||
) | ||
|
||
|
||
def test_gen_psk() -> None: | ||
"""Test the gen_psk() method against precomputed data.""" | ||
for clear, encrypted in PRECOMPUTED: | ||
identity = PREFIX + bytes.fromhex(clear) | ||
assert gen_psk(identity, HINT).hex() == encrypted | ||
|
||
with pytest.raises(ValueError): | ||
assert gen_psk(b"not 16 chars", HINT) |