Remove Firefly III's ability to encrypt data in the database.

This commit is contained in:
James Cole
2019-01-31 19:56:09 +01:00
parent d56bd85328
commit 4307bf3b83
26 changed files with 166 additions and 742 deletions

View File

@@ -143,49 +143,6 @@ class Account extends Model
return $name;
}
/**
* @param $value
*
* @return string
*
* @throws FireflyException
*/
public function getIbanAttribute($value): string
{
if ('' === (string)$value) {
return '';
}
try {
$result = Crypt::decrypt($value);
} catch (DecryptException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
throw new FireflyException('Cannot decrypt value "' . $value . '" for account #' . $this->id);
}
if (null === $result) {
return '';
}
return $result;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getNameAttribute($value): ?string
{
if ($this->encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* Returns the opening balance.
*
@@ -237,31 +194,6 @@ class Account extends Model
$query->whereIn('account_types.type', $types);
}
/**
* @param $value
*
* @codeCoverageIgnore
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setIbanAttribute($value): void
{
$this->attributes['iban'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setNameAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['encrypted'] = $encrypt;
}
/**
* @codeCoverageIgnore
*

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use Crypt;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -115,70 +114,6 @@ class Attachment extends Model
return sprintf('at-%s.data', (string)$this->id);
}
/**
* @param $value
*
* @codeCoverageIgnore
* @return null|string
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getDescriptionAttribute($value): ?string
{
if (null === $value || '' === $value) {
return null;
}
return Crypt::decrypt($value);
}
/**
* @param $value
*
* @codeCoverageIgnore
* @return null|string
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getFilenameAttribute($value): ?string
{
if (null === $value || '' === $value) {
return null;
}
return Crypt::decrypt($value);
}
/**
* @param $value
*
* @codeCoverageIgnore
* @return null|string
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getMimeAttribute($value): ?string
{
if (null === $value || '' === $value) {
return null;
}
return Crypt::decrypt($value);
}
/**
* @param $value
*
* @codeCoverageIgnore
* @return null|string
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getTitleAttribute($value): ?string
{
if (null === $value || '' === $value) {
return null;
}
return Crypt::decrypt($value);
}
/**
* @codeCoverageIgnore
* Get all of the notes.
@@ -188,57 +123,6 @@ class Attachment extends Model
return $this->morphMany(Note::class, 'noteable');
}
/**
* @codeCoverageIgnore
*
* @param string|null $value
*/
public function setDescriptionAttribute(string $value = null): void
{
if (null !== $value) {
$this->attributes['description'] = Crypt::encrypt($value);
}
}
/**
* @codeCoverageIgnore
*
* @param string $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setFilenameAttribute(string $value): void
{
$this->attributes['filename'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore
*
* @param string $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setMimeAttribute(string $value): void
{
$this->attributes['mime'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore
*
* @param string $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setTitleAttribute(string $value = null): void
{
if (null !== $value) {
$this->attributes['title'] = Crypt::encrypt($value);
}
}
/**
* @codeCoverageIgnore
* @return BelongsTo

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use Crypt;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -80,7 +79,7 @@ class Bill extends Model
/** @var array Fields that can be filled */
protected $fillable
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
= ['name', 'match', 'amount_min', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
'automatch', 'active', 'transaction_currency_id'];
/** @var array Hidden from view */
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
@@ -117,40 +116,6 @@ class Bill extends Model
return $this->morphMany(Attachment::class, 'attachable');
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getMatchAttribute($value): string
{
if (1 === (int)$this->match_encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getNameAttribute($value): ?string
{
if (1 === (int)$this->name_encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @codeCoverageIgnore
* Get all of the notes.
@@ -180,32 +145,6 @@ class Bill extends Model
$this->attributes['amount_min'] = (string)$value;
}
/**
* @param $value
*
* @codeCoverageIgnore
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setMatchAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['match'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['match_encrypted'] = $encrypt;
}
/**
* @param $value
*
* @codeCoverageIgnore
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setNameAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['name_encrypted'] = $encrypt;
}
/**
* @codeCoverageIgnore
* @return BelongsTo

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use Crypt;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -101,37 +100,6 @@ class Budget extends Model
return $this->hasMany(BudgetLimit::class);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getNameAttribute($value): ?string
{
if ($this->encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setNameAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['encrypted'] = $encrypt;
}
/**
* @codeCoverageIgnore
* @return BelongsToMany

View File

@@ -88,37 +88,6 @@ class Category extends Model
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getNameAttribute($value): ?string
{
if ($this->encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setNameAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['encrypted'] = $encrypt;
}
/**
* @codeCoverageIgnore
* @return BelongsToMany

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use Crypt;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -104,23 +103,6 @@ class PiggyBank extends Model
return $this->belongsTo(Account::class);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getNameAttribute($value): ?string
{
if ($this->encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @codeCoverageIgnore
* Get all of the piggy bank's notes.
@@ -148,20 +130,6 @@ class PiggyBank extends Model
return $this->hasMany(PiggyBankRepetition::class);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setNameAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['encrypted'] = $encrypt;
}
/**
* @codeCoverageIgnore
*

View File

@@ -54,6 +54,7 @@ class Preference extends Model
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'data' => 'array',
];
/** @var array Fields that can be filled */
@@ -81,54 +82,6 @@ class Preference extends Model
throw new NotFoundHttpException;
}
/**
* @param $value
*
* @return mixed
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getDataAttribute($value)
{
$result = null;
try {
$data = Crypt::decrypt($value);
} catch (DecryptException $e) {
Log::error(sprintf('Could not decrypt preference: %s', $e->getMessage()), ['id' => $this->id, 'name' => $this->name, 'data' => $value]);
throw new FireflyException(
sprintf('Could not decrypt preference #%d. If this error persists, please run "php artisan cache:clear" on the command line.', $this->id)
);
}
$serialized = true;
try {
unserialize($data, ['allowed_classes' => false]);
} /** @noinspection BadExceptionsProcessingInspection */ catch (Exception $e) {
$serialized = false;
}
if (!$serialized) {
$result = json_decode($data, true);
}
if ($serialized) {
Log::error(sprintf('Preference #%d ("%s") was stored as serialised object. It will be deleted and recreated.', $this->id, $this->name));
}
return $result;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setDataAttribute($value): void
{
$this->attributes['data'] = Crypt::encrypt(json_encode($value));
}
/**
* @codeCoverageIgnore
* @return BelongsTo

View File

@@ -93,63 +93,6 @@ class Tag extends Model
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getDescriptionAttribute($value): ?string
{
if (null === $value) {
return $value;
}
return Crypt::decrypt($value);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getTagAttribute($value): ?string
{
if (null === $value) {
return null;
}
return Crypt::decrypt($value);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setDescriptionAttribute($value): void
{
$this->attributes['description'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setTagAttribute($value): void
{
$this->attributes['tag'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore

View File

@@ -196,24 +196,6 @@ class TransactionJournal extends Model
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return string|null
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function getDescriptionAttribute($value): ?string
{
if ($this->encrypted) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @codeCoverageIgnore
* @return bool
*/
public function isDeposit(): bool
@@ -324,20 +306,6 @@ class TransactionJournal extends Model
}
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setDescriptionAttribute($value): void
{
$encrypt = config('firefly.encryption');
$this->attributes['description'] = $encrypt ? Crypt::encrypt($value) : $value;
$this->attributes['encrypted'] = $encrypt;
}
/**
* @codeCoverageIgnore
* @return HasMany

View File

@@ -93,22 +93,6 @@ class TransactionJournalLink extends Model
return $this->belongsTo(TransactionJournal::class, 'destination_id');
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @return null|string
*/
public function getCommentAttribute($value): ?string
{
if (null !== $value) {
return app('steam')->tryDecrypt($value);
}
return null;
}
/**
* @codeCoverageIgnore
* @return BelongsTo
@@ -127,23 +111,6 @@ class TransactionJournalLink extends Model
return $this->morphMany(Note::class, 'noteable');
}
/**
* @codeCoverageIgnore
*
* @param $value
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public function setCommentAttribute($value): void
{
if (null !== $value && \strlen($value) > 0) {
$this->attributes['comment'] = Crypt::encrypt($value);
return;
}
$this->attributes['comment'] = null;
}
/**
* @codeCoverageIgnore
* @return BelongsTo