2020use CakeDC \Api \Utility \RequestParser ;
2121use CakeDC \Api \Webauthn \Repository \UserCredentialSourceRepository ;
2222use CakeDC \Users \Model \Table \UsersTable ;
23+ use Cose \Algorithm \Manager ;
24+ use Cose \Algorithm \Signature \ECDSA \ES256 ;
25+ use Cose \Algorithm \Signature \ECDSA \ES256K ;
26+ use Cose \Algorithm \Signature \ECDSA \ES384 ;
27+ use Cose \Algorithm \Signature \ECDSA \ES512 ;
28+ use Cose \Algorithm \Signature \EdDSA \Ed256 ;
29+ use Cose \Algorithm \Signature \EdDSA \Ed512 ;
30+ use Cose \Algorithm \Signature \RSA \PS256 ;
31+ use Cose \Algorithm \Signature \RSA \PS384 ;
32+ use Cose \Algorithm \Signature \RSA \PS512 ;
33+ use Cose \Algorithm \Signature \RSA \RS256 ;
34+ use Cose \Algorithm \Signature \RSA \RS384 ;
35+ use Cose \Algorithm \Signature \RSA \RS512 ;
36+ use Webauthn \AttestationStatement \AttestationObjectLoader ;
37+ use Webauthn \AttestationStatement \AttestationStatementSupportManager ;
38+ use Webauthn \AttestationStatement \NoneAttestationStatementSupport ;
39+ use Webauthn \AuthenticationExtensions \ExtensionOutputCheckerHandler ;
2340use Webauthn \PublicKeyCredentialRpEntity ;
2441use Webauthn \PublicKeyCredentialUserEntity ;
25- use Webauthn \Server ;
2642
2743class BaseAdapter
2844{
@@ -39,20 +55,30 @@ class BaseAdapter
3955 protected $ repository ;
4056
4157 /**
42- * @var \Webauthn\Server
58+ * @var \Cake\Datasource\EntityInterface|\CakeDC\Users\Model\Entity\User
4359 */
44- protected $ server ;
60+ private $ user ;
4561
4662 /**
47- * @var \Cake\Datasource\EntityInterface|\CakeDC\Users\Model\Entity\User
63+ * @var \Webauthn\PublicKeyCredentialRpEntity
4864 */
49- private $ user ;
65+ protected PublicKeyCredentialRpEntity $ rpEntity ;
5066
5167 /**
5268 * @var \CakeDC\Api\Model\Table\AuthStoreTable
5369 */
5470 protected $ store ;
5571
72+ /**
73+ * @var \Webauthn\AttestationStatement\AttestationStatementSupportManager|null
74+ */
75+ protected ?AttestationStatementSupportManager $ attestationStatementSupportManager = null ;
76+
77+ /**
78+ * @var \Cose\Algorithm\Manager|null
79+ */
80+ protected ?Manager $ algorithmManager = null ;
81+
5682 /**
5783 * Constructor.
5884 *
@@ -67,7 +93,7 @@ public function __construct(ServerRequest $request, ?UsersTable $usersTable, $us
6793 $ store = TableRegistry::getTableLocator ()->get ('CakeDC/Api.AuthStore ' );
6894 $ this ->store = $ store ;
6995 $ session = $ this ->readStore ();
70- $ rpEntity = new PublicKeyCredentialRpEntity (
96+ $ this -> rpEntity = new PublicKeyCredentialRpEntity (
7197 Configure::read ('Api.Webauthn2fa. ' . $ this ->getDomain () . '.appName ' ), // The application name
7298 Configure::read ('Api.Webauthn2fa. ' . $ this ->getDomain () . '.id ' )
7399 );
@@ -81,11 +107,6 @@ public function __construct(ServerRequest $request, ?UsersTable $usersTable, $us
81107 $ this ->user ,
82108 $ usersTable
83109 );
84-
85- $ this ->server = new Server (
86- $ rpEntity ,
87- $ this ->repository
88- );
89110 }
90111
91112 /**
@@ -107,7 +128,7 @@ protected function getUserEntity(): PublicKeyCredentialUserEntity
107128 /**
108129 * Get the user.
109130 *
110- * @return array| mixed|null
131+ * @return mixed|array |null
111132 */
112133 public function getUser ()
113134 {
@@ -229,4 +250,75 @@ public function getDomain($replace = true)
229250 {
230251 return RequestParser::getDomain ($ this ->request , $ replace );
231252 }
253+
254+ /**
255+ * @param \Webauthn\AttestationStatement\AttestationStatementSupportManager $attestationStatementSupportManager manager instance
256+ * @return void
257+ */
258+ public function setAttestationStatementSupportManager (
259+ AttestationStatementSupportManager $ attestationStatementSupportManager
260+ ): void {
261+ $ this ->attestationStatementSupportManager = $ attestationStatementSupportManager ;
262+ }
263+
264+ /**
265+ * @return \Webauthn\AttestationStatement\AttestationStatementSupportManager
266+ */
267+ protected function getAttestationStatementSupportManager (): AttestationStatementSupportManager
268+ {
269+ if ($ this ->attestationStatementSupportManager === null ) {
270+ $ this ->attestationStatementSupportManager = new AttestationStatementSupportManager ();
271+ $ this ->attestationStatementSupportManager
272+ ->add (new NoneAttestationStatementSupport ());
273+ }
274+
275+ return $ this ->attestationStatementSupportManager ;
276+ }
277+
278+ /**
279+ * @return \CakeDC\Api\Webauthn\PublicKeyCredentialLoader
280+ */
281+ protected function createPublicKeyCredentialLoader (): PublicKeyCredentialLoader
282+ {
283+ $ attestationObjectLoader = new AttestationObjectLoader (
284+ $ this ->getAttestationStatementSupportManager ()
285+ );
286+
287+ return new PublicKeyCredentialLoader (
288+ $ attestationObjectLoader
289+ );
290+ }
291+
292+ /**
293+ * @return \Webauthn\AuthenticationExtensions\ExtensionOutputCheckerHandler
294+ */
295+ protected function createExtensionOutputCheckerHandler (): ExtensionOutputCheckerHandler
296+ {
297+ return new ExtensionOutputCheckerHandler ();
298+ }
299+
300+ /**
301+ * @return \Cose\Algorithm\Manager
302+ */
303+ protected function getAlgorithmManager (): Manager
304+ {
305+ if ($ this ->algorithmManager === null ) {
306+ $ this ->algorithmManager = Manager::create ()->add (
307+ ES256 ::create (),
308+ ES256K ::create (),
309+ ES384 ::create (),
310+ ES512 ::create (),
311+ RS256 ::create (),
312+ RS384 ::create (),
313+ RS512 ::create (),
314+ PS256 ::create (),
315+ PS384 ::create (),
316+ PS512 ::create (),
317+ Ed256::create (),
318+ Ed512::create (),
319+ );
320+ }
321+
322+ return $ this ->algorithmManager ;
323+ }
232324}
0 commit comments