Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/.idea
/.phpunit.cache
.phpunit.result.cache
4 changes: 3 additions & 1 deletion src/Hazelnut.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ private function validateRequest(array $get, array $post) :int {
private function validateNut(?Nut $nut, ?string $key) :int {
if ($nut == null) return NUT_INVALID;
if ($nut->getCreatedTime() < strtotime('-'.$this->nutExpiry.' minutes')) return NUT_EXPIRED;
if ($key != null && $nut->getIdentity() != null && $key != $nut->getIdentity()) return NUT_MISMATCHING_ID;
if ($key != null && $nut->getIdentity() != null && $key != trim($nut->getIdentity())) {
return NUT_MISMATCHING_ID;
}
return NUT_VALID;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/core/CoreValidateNutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ public function testValidNutWithDefinedKey() {
$this->assertEquals(\Varden\Hazelnut\NUT_VALID, $result);
}

public function testValidNutWithPaddedDefinedKey() {
/*
* Per https://www.grc.com/sqrl/details.htm: After its single trailing (“=”) equals sign
* is removed, the resulting 43-character string becomes the value for the sqrlkey parameter.
*
* Test for cases where the CHAR(44) pubkey includes a trailing space.
*/
$nut = new \Varden\Hazelnut\Nut('sample');
$key = "k";
$nut
-> createdAt(time())
-> forIdentity("k ")
-> withTIF('0')
-> byIP('2001:db8::1');
$result = $this->method->invoke($this->hazelnut, $nut, $key);
$this->assertEquals(\Varden\Hazelnut\NUT_VALID, $result);
}

public function testNullNut() {
$result = $this->method->invoke($this->hazelnut, null, null);
$this->assertEquals(\Varden\Hazelnut\NUT_INVALID, $result);
Expand Down