Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Commit 0c3af86

Browse files
Merge pull request #12 from DarkGhostHunter/master
Fixed recovery attestation failure.
2 parents b997a63 + 770f107 commit 0c3af86

File tree

11 files changed

+39
-31
lines changed

11 files changed

+39
-31
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Just hit the console and require it with Composer.
4646

4747
## What is WebAuthn? How it uses fingerprints or else?
4848

49-
In a nutshell, [mayor browsers are compatible with Web Authentication API](https://caniuse.com/#feat=webauthn), pushing authentication to the device (fingerprints, Face ID, patterns, codes, etc) instead of plain-text passwords.
49+
In a nutshell, [major browsers are compatible with Web Authentication API](https://caniuse.com/#feat=webauthn), pushing authentication to the device (fingerprints, Face ID, patterns, codes, etc) instead of plain-text passwords.
5050

5151
This package validates the WebAuthn payload from the devices using a custom [user provider](https://laravel.com/docs/authentication#adding-custom-user-providers).
5252

@@ -617,23 +617,23 @@ if (! Larapass.supportsWebAuthn()) {
617617

618618
* **Does this stores the user's fingerprint, PIN or patterns in my site?**
619619

620-
No.
620+
No. It stores the public key generated by the device.
621621

622622
* **Can a phishing site steal WebAuthn credentials and use them in my site?**
623623

624624
No. WebAuthn kills phishing.
625625

626626
* **Can the WebAuthn data identify a particular device?**
627627

628-
Not, unless explicitly requested and consented.
628+
No, unless explicitly requested and consented.
629629

630630
* **Are my user's classic passwords safe?**
631631

632632
Yes, as long you are hashing them as you should, and you have secured your application key. This is done by Laravel by default. You can also [disable them](#password-fallback).
633633

634634
* **Can a user register two or more _devices_?**
635635

636-
Yes, but you need to manually attest (register) these.
636+
Yes, but you need to manually attest (register) these. It's recommended to email him to register a new device.
637637

638638
* **What happens if a credential is cloned?**
639639

@@ -669,19 +669,19 @@ class MyCountChecker implements CounterChecker
669669

670670
* **If a user loses his device, can he register a new device?**
671671

672-
Yes, just send him a signed email to register a new device with secure attestation and assertion routes. You can [use these recovery helpers](#6-set-up-account-recovery-optional).
672+
Yes, [use these recovery helpers](#6-set-up-account-recovery-optional).
673673

674674
* **What's the difference between disabling and deleting a credential?**
675675

676-
Disabling a credential doesn't delete it, so it can be later enabled manually. When the credential is deleted, it goes away forever.
676+
Disabling a credential doesn't delete it, so it can be later enabled manually in the case the user recovers it. When the credential is deleted, it goes away forever.
677677

678678
* **How secure is this against passwords or 2FA?**
679679

680-
Extremely secure since it works only on HTTPS, and no password or codes are exchanged after registration.
680+
Extremely secure since it works only on HTTPS, and no password or codes are exchanged.
681681

682682
* **Can I deactivate the password fallback? Can I enforce only WebAuthn authentication?**
683683

684-
Yes. Just be sure to [use the recovery helpers](#6-set-up-account-recovery-optional) if you want a quick fix.
684+
Yes. Just be sure to [use the recovery helpers](#6-set-up-account-recovery-optional) to avoid users locked out.
685685

686686
* **Does this includes a frontend Javascript?**
687687

@@ -695,6 +695,10 @@ Yes, the included [WebAuthn Helper](#5-use-the-javascript-helper-optional) does
695695

696696
[Yes.](#6-set-up-account-recovery-optional)
697697

698+
* **Can I use my smartphone as authenticator through a PC desktop/laptop/terminal?**
699+
700+
Depends on the OS and hardware. Some will require previously pairing the device to an "account". Others won't and will only work with USB keys. This is up to hardware and software vendor themselves.
701+
698702
## License
699703

700704
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
},
3232
"autoload": {
3333
"psr-4": {
34-
"DarkGhostHunter\\Larapass\\": "src"
34+
"DarkGhostHunter\\Larapass\\": "src/"
3535
}
3636
},
3737
"autoload-dev": {
3838
"psr-4": {
39-
"Tests\\": "tests"
39+
"Tests\\": "tests/"
4040
}
4141
},
4242
"scripts": {
@@ -53,4 +53,4 @@
5353
]
5454
}
5555
}
56-
}
56+
}

src/Auth/EloquentWebAuthnProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function isSignedChallenge(array $credentials)
8787
* @param array $credentials
8888
* @return bool
8989
*/
90-
public function validateCredentials(UserContract $user, array $credentials)
90+
public function validateCredentials($user, array $credentials)
9191
{
9292
if ($this->isSignedChallenge($credentials)) {
9393
return (bool)$this->validator->validate($credentials);

src/Contracts/WebAuthnAuthenticatable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function flushCredentials($except = null) : void;
6464
* Checks if a given credential exists and is enabled.
6565
*
6666
* @param string $id
67-
* @return mixed
67+
* @return bool
6868
*/
6969
public function hasCredentialEnabled(string $id) : bool;
7070

src/Eloquent/Casting/UuidCast.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public function get($model, string $key, $value, array $attributes)
2828
* @param string $key
2929
* @param mixed $value
3030
* @param array $attributes
31-
* @return \Ramsey\Uuid\UuidInterface
31+
* @return array|string
3232
*/
3333
public function set($model, string $key, $value, array $attributes)
3434
{
35-
return mb_strlen($value, '8bit') === 36
35+
return (mb_strlen($value, '8bit') === 36
3636
? Uuid::fromString($value)
37-
: Uuid::fromBytes(base64_decode($value, true));
37+
: Uuid::fromBytes(base64_decode($value, true)))->toString();
3838
}
3939
}

src/Eloquent/WebAuthnCredential.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function isDisabled()
120120
/**
121121
* Returns the credential ID encoded in BASE64.
122122
*
123-
* @return false
123+
* @return string
124124
*/
125125
public function getPrettyIdAttribute()
126126
{

src/Http/RecoversWebAuthn.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public function recover(Request $request)
7777
], $this->rules())->validate();
7878

7979
$response = WebAuthn::recover($credentials, function ($user) use ($request) {
80-
$this->register($request, $user);
80+
if (! $this->register($request, $user)) {
81+
$this->sendRecoveryFailedResponse($request, 'larapass::recovery.failed');
82+
}
8183
});
8284

8385
return $response === WebAuthn::RECOVERY_ATTACHED
@@ -90,7 +92,7 @@ public function recover(Request $request)
9092
*
9193
* @param \Illuminate\Http\Request $request
9294
* @param \DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable $user
93-
* @return void
95+
* @return bool
9496
*/
9597
protected function register(Request $request, WebAuthnAuthenticatable $user)
9698
{
@@ -108,7 +110,11 @@ protected function register(Request $request, WebAuthnAuthenticatable $user)
108110
event(new AttestationSuccessful($user, $validCredential));
109111

110112
$this->guard()->login($user);
113+
114+
return true;
111115
}
116+
117+
return false;
112118
}
113119

114120
/**
@@ -143,6 +149,7 @@ protected function sendRecoveryResponse(Request $request, $response)
143149
*
144150
* @param \Illuminate\Http\Request $request
145151
* @param string $response
152+
* @return \Illuminate\Http\JsonResponse|void
146153
* @throws \Illuminate\Validation\ValidationException
147154
*/
148155
protected function sendRecoveryFailedResponse(Request $request, $response)

src/WebAuthn/WebAuthnAssertValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class WebAuthnAssertValidator
8282
/**
8383
* If the login should require explicit User verification.
8484
*
85-
* @var bool
85+
* @var string
8686
*/
8787
protected $verifyLogin;
8888

src/WebAuthn/WebAuthnAttestCreator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class WebAuthnAttestCreator
6666
/**
6767
* If the devices should be further verified.
6868
*
69-
* @var bool
69+
* @var string
7070
*/
7171
protected $conveyance;
7272

@@ -122,7 +122,7 @@ public function __construct(ConfigContract $config,
122122
* @param \Illuminate\Contracts\Auth\Authenticatable|\DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable $user
123123
* @return \Webauthn\PublicKeyCredentialCreationOptions|null
124124
*/
125-
public function retrieveAttestation(WebAuthnAuthenticatable $user)
125+
public function retrieveAttestation($user)
126126
{
127127
return $this->cache->get($this->cacheKey($user));
128128
}
@@ -133,7 +133,7 @@ public function retrieveAttestation(WebAuthnAuthenticatable $user)
133133
* @param \Illuminate\Contracts\Auth\Authenticatable|\DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable $user
134134
* @return mixed|\Webauthn\PublicKeyCredentialCreationOptions
135135
*/
136-
public function generateAttestation(WebAuthnAuthenticatable $user)
136+
public function generateAttestation($user)
137137
{
138138
$attestation = $this->makeAttestationRequest($user);
139139

src/WebAuthn/WebAuthnAttestValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct(ConfigContract $config,
8080
* @param \Illuminate\Contracts\Auth\Authenticatable|\DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable $user
8181
* @return bool|\Webauthn\PublicKeyCredentialSource
8282
*/
83-
public function validate(array $data, WebAuthnAuthenticatable $user)
83+
public function validate(array $data, $user)
8484
{
8585
if (! $attestation = $this->retrieveAttestation($user)) {
8686
return false;

0 commit comments

Comments
 (0)