Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FDP-2004: Recognize PSK change correctly #18

Merged
merged 2 commits into from
Mar 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object PskExtractor {
* Group 1 containing the next 16 chars after PSK: this is only the key
* Group 2 containing the next 64 chars after the key this is only the hash
*/
private val pskKeyHashSplitterRegex = "!PSK:([a-zA-Z0-9]{16})([a-zA-Z0-9]{64});PSK:[a-zA-Z0-9]{16}[a-zA-Z0-9]{64}SET".toRegex()
private val pskKeyHashSplitterRegex = "!PSK:([a-zA-Z0-9]{16}):([a-zA-Z0-9]{64});PSK:[a-zA-Z0-9]{16}:[a-zA-Z0-9]{64}SET".toRegex()

fun hasPskCommand(command: String) = pskKeyHashSplitterRegex.matches(command)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class PskExtractorTest {
companion object {
private const val testHash = "1234567890123456123456789012345612345678901234561234567890123456"

private const val validPskCommand = "!PSK:1234567891234567${testHash};PSK:1234567891234567${testHash}SET"
private const val validPskCommandWithKeyWordsInKey = "!PSK:PSKaSET1PSKd2SET${testHash};PSK:PSKaSET1PSKd2SET${testHash}SET"
private const val invalidKeySizePskCommand = "!PSK:1234${testHash};PSK:1234${testHash}SET"
private const val validPskCommand = "!PSK:1234567891234567:${testHash};PSK:1234567891234567:${testHash}SET"
private const val validPskCommandWithKeyWordsInKey = "!PSK:PSKaSET1PSKd2SET:${testHash};PSK:PSKaSET1PSKd2SET:${testHash}SET"
private const val invalidKeySizePskCommand = "!PSK:1234:${testHash};PSK:1234:${testHash}SET"
private const val notPskCommand = "NoPskCommandInThisString"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PskCommandHandlerTest {
@Test
fun shouldSetNewPskInStoreWhenTheKeyIsValid() {
val expectedHash = DigestUtils.sha256Hex("$secret$newKey")
val pskCommand = "!PSK:$newKey$expectedHash;PSK:$newKey${expectedHash}SET"
val pskCommand = "!PSK:$newKey:$expectedHash;PSK:$newKey:${expectedHash}SET"

pskCommandHandler.handlePskChange(pskCommand)

Expand All @@ -64,7 +64,7 @@ class PskCommandHandlerTest {
@Test
fun shouldThrowErrorWhenHashDoesNotMatch() {
val invalidHash = DigestUtils.sha256Hex("invalid")
val pskCommand = "!PSK:$oldKey$invalidHash;PSK:$oldKey${invalidHash}SET"
val pskCommand = "!PSK:$oldKey:$invalidHash;PSK:$oldKey:${invalidHash}SET"

val thrownException = catchException {
pskCommandHandler.handlePskChange(pskCommand)
Expand Down
Loading