This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from DarkGhostHunter/master
Version 4.0
- Loading branch information
Showing
47 changed files
with
1,210 additions
and
1,510 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: composer | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
time: "09:00" | ||
open-pull-requests-limit: 10 |
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 |
---|---|---|
|
@@ -2,4 +2,7 @@ build | |
composer.lock | ||
docs | ||
vendor | ||
coverage | ||
coverage | ||
.idea | ||
/.phpunit.result.cache | ||
/phpunit.xml.dist.bak |
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,18 @@ | ||
# Upgrading | ||
|
||
## Upgrade from 3.0 | ||
|
||
If you're upgrading from Laraguard 3.0, you will need to migrate. | ||
|
||
Laraguard 4.0 encrypts the Shared Secret and Recovery Codes. This adds an extra layer of protection in case the database records are leaked to the wild, as recommended by the [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238). | ||
|
||
To upgrade, ensure you have installed `doctrine/dbal` so the migration can run, as it needs to change a column type. | ||
|
||
composer require doctrine/dbal | ||
|
||
Then, publish the upgrading migration and run it: | ||
|
||
php artisan vendor:publish --provider="DarkGhostHunter\Laraguard\LaraguardServiceProvider" --tag="upgrade" | ||
php artisan migrate | ||
|
||
The migration will automatically encrypt all shared secrets, while also reverting the decryption on rolling back migrations. |
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
85 changes: 85 additions & 0 deletions
85
database/migrations/2020_04_02_000000_upgrade_two_factor_authentications_table.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,85 @@ | ||
<?php | ||
|
||
use Composer\InstalledVersions; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Crypt; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class UpgradeTwoFactorAuthenticationsTable extends Migration | ||
{ | ||
/** | ||
* Creates a new Migration instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
if (! InstalledVersions::isInstalled('doctrine/dbal')) { | ||
throw new OutOfBoundsException("Install the doctrine/dbal package to upgrade or downgrade."); | ||
} | ||
} | ||
|
||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('two_factor_authentications', static function (Blueprint $table): void { | ||
$table->text('shared_secret')->change(); | ||
$table->text('recovery_codes')->nullable()->change(); | ||
}); | ||
|
||
// We need to encrypt all shared secrets so these can be used with Laraguard v4.0. | ||
$this->chunkRows(true); | ||
} | ||
|
||
/** | ||
* Returns a chunk of authentications to encrypt/decrypt them. | ||
* | ||
* @param bool $encrypt | ||
* | ||
* @return void | ||
*/ | ||
protected function chunkRows(bool $encrypt): void | ||
{ | ||
$call = $encrypt ? 'encryptString' : 'decryptString'; | ||
$encrypter = Crypt::getFacadeRoot(); | ||
$query = DB::table('two_factor_authentications'); | ||
|
||
$query->clone()->select('id', 'shared_secret', 'recovery_codes') | ||
->chunkById( | ||
1000, | ||
static function (Collection $chunk) use ($encrypter, $query, $call): void { | ||
DB::beginTransaction(); | ||
foreach ($chunk as $item) { | ||
$query->clone()->where('id', $item->id)->update([ | ||
'shared_secret' => $encrypter->$call($item->shared_secret), | ||
'recovery_codes' => $item->recovery_codes ? $encrypter->$call($item->recovery_codes) : null, | ||
]); | ||
} | ||
DB::commit(); | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down(): void | ||
{ | ||
// Before changing the shared secret column, we will need to decrypt the shared secret. | ||
$this->chunkRows(false); | ||
|
||
Schema::table('two_factor_authentications', static function (Blueprint $table): void { | ||
$table->string('shared_secret')->change(); | ||
$table->json('recovery_codes')->nullable()->change(); | ||
}); | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.