mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Disable the encryption of uploads, in line with other efforts not to encrypt local data.
This commit is contained in:
@@ -30,6 +30,7 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -105,25 +106,27 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
public function getContent(Attachment $attachment): string
|
||||
{
|
||||
// create a disk.
|
||||
$disk = Storage::disk('upload');
|
||||
$file = $attachment->fileName();
|
||||
$content = '';
|
||||
$disk = Storage::disk('upload');
|
||||
$file = $attachment->fileName();
|
||||
$unencryptedContent = '';
|
||||
|
||||
if ($disk->exists($file)) {
|
||||
$encryptedContent = '';
|
||||
try {
|
||||
$content = Crypt::decrypt($disk->get($file));
|
||||
$encryptedContent = $disk->get($file);
|
||||
} catch (FileNotFoundException $e) {
|
||||
Log::debug(sprintf('File not found: %e', $e->getMessage()));
|
||||
$content = false;
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$unencryptedContent = Crypt::decrypt($encryptedContent); // verified
|
||||
} catch (DecryptException $e) {
|
||||
Log::debug(sprintf('Could not decrypt: %e', $e->getMessage()));
|
||||
$unencryptedContent = $encryptedContent;
|
||||
}
|
||||
}
|
||||
if (\is_bool($content)) {
|
||||
Log::error(sprintf('Attachment #%d may be corrupted: the content could not be decrypted.', $attachment->id));
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
return $content;
|
||||
return $unencryptedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -243,10 +243,10 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
{
|
||||
// this will overwrite all transactions currently in the job.
|
||||
$disk = Storage::disk('upload');
|
||||
$filename = sprintf('%s-%s.crypt.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$filename = sprintf('%s-%s.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$array = [];
|
||||
if ($disk->exists($filename)) {
|
||||
$json = Crypt::decrypt($disk->get($filename));
|
||||
$json = $disk->get($filename);
|
||||
$array = json_decode($json, true);
|
||||
}
|
||||
if (false === $array) {
|
||||
@@ -329,8 +329,8 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
{
|
||||
// this will overwrite all transactions currently in the job.
|
||||
$disk = Storage::disk('upload');
|
||||
$filename = sprintf('%s-%s.crypt.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$json = Crypt::encrypt(json_encode($transactions));
|
||||
$filename = sprintf('%s-%s.json', $job->created_at->format('Ymd'), $job->key);
|
||||
$json = json_encode($transactions);
|
||||
|
||||
// set count for easy access
|
||||
$array = ['count' => count($transactions)];
|
||||
@@ -389,9 +389,8 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
$attachment->size = strlen($content);
|
||||
$attachment->uploaded = false;
|
||||
$attachment->save();
|
||||
$encrypted = Crypt::encrypt($content);
|
||||
|
||||
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
||||
$this->uploadDisk->put($attachment->fileName(), $content);
|
||||
$attachment->uploaded = true; // update attachment
|
||||
$attachment->save();
|
||||
|
||||
@@ -446,8 +445,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
}
|
||||
|
||||
$content = $fileObject->fread($file->getSize());
|
||||
$encrypted = Crypt::encrypt($content);
|
||||
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
||||
$this->uploadDisk->put($attachment->fileName(), $content);
|
||||
$attachment->uploaded = true; // update attachment
|
||||
$attachment->save();
|
||||
|
||||
|
Reference in New Issue
Block a user