-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Better Doctrine support * Simplified Credential Source
- Loading branch information
Showing
29 changed files
with
965 additions
and
283 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
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
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
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
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
93 changes: 0 additions & 93 deletions
93
src/symfony-security/tests/functional/CredentialRepository.php
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
src/symfony-security/tests/functional/PublicKeyCredentialSourceRepository.php
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,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2018 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Webauthn\SecurityBundle\Tests\Functional; | ||
|
||
use Webauthn\AttestationStatement\AttestationStatement; | ||
use Webauthn\AttestedCredentialData; | ||
use Webauthn\PublicKeyCredentialDescriptor; | ||
use Webauthn\PublicKeyCredentialSource; | ||
use Webauthn\PublicKeyCredentialSourceRepository as PublicKeyCredentialSourceRepositoryInterface; | ||
use Webauthn\TrustPath\EmptyTrustPath; | ||
|
||
final class PublicKeyCredentialSourceRepository implements PublicKeyCredentialSourceRepositoryInterface | ||
{ | ||
/** | ||
* @var PublicKeyCredentialSource[] | ||
*/ | ||
private $credentials; | ||
|
||
public function __construct() | ||
{ | ||
$pkcs1 = new PublicKeyCredentialSource( | ||
\Safe\base64_decode('eHouz/Zi7+BmByHjJ/tx9h4a1WZsK4IzUmgGjkhyOodPGAyUqUp/B9yUkflXY3yHWsNtsrgCXQ3HjAIFUeZB+w==', true), | ||
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, | ||
[], | ||
AttestationStatement::TYPE_NONE, | ||
new EmptyTrustPath(), | ||
\Safe\base64_decode('AAAAAAAAAAAAAAAAAAAAAA==', true), | ||
\Safe\base64_decode('pQECAyYgASFYIJV56vRrFusoDf9hm3iDmllcxxXzzKyO9WruKw4kWx7zIlgg/nq63l8IMJcIdKDJcXRh9hoz0L+nVwP1Oxil3/oNQYs=', true), | ||
'foo', | ||
100 | ||
); | ||
$this->save($pkcs1); | ||
} | ||
|
||
public function find(string $credentialId): ?PublicKeyCredentialSource | ||
{ | ||
if (!array_key_exists(base64_encode($credentialId), $this->credentials)) { | ||
return null; | ||
} | ||
|
||
return $this->credentials[base64_encode($credentialId)]; | ||
} | ||
|
||
public function save(PublicKeyCredentialSource $publicKeyCredentialSource): void | ||
{ | ||
$this->credentials[base64_encode($publicKeyCredentialSource->getPublicKeyCredentialId())] = $publicKeyCredentialSource; | ||
} | ||
|
||
public function has(string $credentialId): bool | ||
{ | ||
return null !== $this->find($credentialId); | ||
} | ||
|
||
public function get(string $credentialId): AttestedCredentialData | ||
{ | ||
$credential = $this->find($credentialId); | ||
if (null === $credential) { | ||
throw new \InvalidArgumentException('Invalid credential ID'); | ||
} | ||
|
||
return $credential->getAttestedCredentialData(); | ||
} | ||
|
||
public function getUserHandleFor(string $credentialId): string | ||
{ | ||
$credential = $this->find($credentialId); | ||
if (null === $credential) { | ||
throw new \InvalidArgumentException('Invalid credential ID'); | ||
} | ||
|
||
return $credential->getUserHandle(); | ||
} | ||
|
||
public function getCounterFor(string $credentialId): int | ||
{ | ||
$credential = $this->find($credentialId); | ||
if (null === $credential) { | ||
throw new \InvalidArgumentException('Invalid credential ID'); | ||
} | ||
|
||
return $credential->getCounter(); | ||
} | ||
|
||
public function updateCounterFor(string $credentialId, int $newCounter): void | ||
{ | ||
$credential = $this->find($credentialId); | ||
if (null === $credential) { | ||
throw new \InvalidArgumentException('Invalid credential ID'); | ||
} | ||
|
||
$credential->setCounter($newCounter); | ||
$this->save($credential); | ||
} | ||
} |
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
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2018 Spomky-Labs | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
namespace Webauthn\Bundle\Doctrine\Type; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\Type; | ||
|
||
final class Base64BinaryDataType extends Type | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
return base64_encode($value); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
return \Safe\base64_decode($value, true); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | ||
{ | ||
return $platform->getClobTypeDeclarationSQL($fieldDeclaration); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'base64'; | ||
} | ||
} |
Oops, something went wrong.