Skip to content

Commit 0d5dd12

Browse files
authored
Merge pull request #43 from pdsinterop/fix/jwkThumb
Fix for the jwk thumbprint calculation (was missing the 'binary' flag).
2 parents eb0033c + f385692 commit 0d5dd12

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Utils/DPop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function makeJwkThumbprint($jwk) {
140140
$jwk['y']
141141
]);
142142
}
143-
$hash = hash('sha256', $json);
143+
$hash = hash('sha256', $json, true);
144144
$encoded = Base64Url::encode($hash);
145145
return $encoded;
146146
}

tests/unit/Utils/DPOPTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,27 @@ final public function testGetWebIdWithDpop(): void
619619
$this->assertEquals(self::MOCK_SUBJECT, $actual);
620620
}
621621

622+
/**
623+
* @testdox makeJwkThumbprint test with a known key and expected result
624+
*
625+
* @covers ::makeJwkThumbprint
626+
*
627+
* @uses \Pdsinterop\Solid\Auth\Utils\DPop::makeJwkThumbprint
628+
*/
629+
final public function testMakeJwkThumbprint(): void
630+
{
631+
$mockJtiValidator = $this->createMockJtiValidator();
632+
$dpop = new DPop($mockJtiValidator);
633+
634+
// Example thumbprint calculation from https://www.rfc-editor.org/rfc/rfc7638#ref-SHS
635+
$jwk = json_decode('{"kty": "RSA","n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw","e": "AQAB","alg": "RS256","kid": "2011-04-29"}', true);
636+
$expectedThumbprint = 'NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs';
637+
638+
$actual = $dpop->makeJwkThumbprint($jwk);
639+
640+
$this->assertEquals($expectedThumbprint, $actual);
641+
}
642+
622643
////////////////////////////// MOCKS AND STUBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
623644

624645
private function createMockJtiValidator()

0 commit comments

Comments
 (0)