mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Better catch for key restauration problems.
This commit is contained in:
parent
4d933e1ef7
commit
45fbf83971
@ -74,11 +74,19 @@ class RestoreOAuthKeys extends Command
|
|||||||
}
|
}
|
||||||
if ($this->keysInDatabase() && !$this->keysOnDrive()) {
|
if ($this->keysInDatabase() && !$this->keysOnDrive()) {
|
||||||
Log::debug('Keys are in DB and keys are not on the drive. Restore.');
|
Log::debug('Keys are in DB and keys are not on the drive. Restore.');
|
||||||
$this->restoreKeysFromDB();
|
$result = $this->restoreKeysFromDB();
|
||||||
|
if(true === $result) {
|
||||||
$this->line('Restored OAuth keys from database.');
|
$this->line('Restored OAuth keys from database.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Log::warning('Could not restore keys. Will create new ones.');
|
||||||
|
$this->generateKeys();
|
||||||
|
$this->storeKeysInDB();
|
||||||
|
$this->line('Generated and stored new keys.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!$this->keysInDatabase() && $this->keysOnDrive()) {
|
if (!$this->keysInDatabase() && $this->keysOnDrive()) {
|
||||||
Log::debug('Keys are not in DB and keys are on the drive. Save in DB.');
|
Log::debug('Keys are not in DB and keys are on the drive. Save in DB.');
|
||||||
$this->storeKeysInDB();
|
$this->storeKeysInDB();
|
||||||
@ -124,8 +132,8 @@ class RestoreOAuthKeys extends Command
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function restoreKeysFromDB(): void
|
private function restoreKeysFromDB(): bool
|
||||||
{
|
{
|
||||||
OAuthKeys::restoreKeysFromDB();
|
return OAuthKeys::restoreKeysFromDB();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ namespace FireflyIII\Support\System;
|
|||||||
use Artisan;
|
use Artisan;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Laravel\Passport\Console\KeysCommand;
|
use Laravel\Passport\Console\KeysCommand;
|
||||||
use Log;
|
use Log;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
@ -117,18 +118,30 @@ class OAuthKeys
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function restoreKeysFromDB(): void
|
public static function restoreKeysFromDB(): bool
|
||||||
{
|
{
|
||||||
$privateKey = (string)app('fireflyconfig')->get(self::PRIVATE_KEY)?->data;
|
$privateKey = (string)app('fireflyconfig')->get(self::PRIVATE_KEY)?->data;
|
||||||
$publicKey = (string)app('fireflyconfig')->get(self::PUBLIC_KEY)?->data;
|
$publicKey = (string)app('fireflyconfig')->get(self::PUBLIC_KEY)?->data;
|
||||||
|
try {
|
||||||
$privateContent = Crypt::decrypt($privateKey);
|
$privateContent = Crypt::decrypt($privateKey);
|
||||||
$publicContent = Crypt::decrypt($publicKey);
|
$publicContent = Crypt::decrypt($publicKey);
|
||||||
|
} catch(DecryptException $e) {
|
||||||
|
Log::error('Could not decrypt pub/private keypair.');
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
|
||||||
|
// delete config vars from DB:
|
||||||
|
app('fireflyconfig')->delete(self::PRIVATE_KEY);
|
||||||
|
app('fireflyconfig')->delete(self::PUBLIC_KEY);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$private = storage_path('oauth-private.key');
|
$private = storage_path('oauth-private.key');
|
||||||
$public = storage_path('oauth-public.key');
|
$public = storage_path('oauth-public.key');
|
||||||
file_put_contents($private, $privateContent);
|
file_put_contents($private, $privateContent);
|
||||||
file_put_contents($public, $publicContent);
|
file_put_contents($public, $publicContent);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user