soarecostin / file-vault

A Laravel package for encrypting and decrypting files of any size
MIT License
184 stars 63 forks source link

streamDecrypt ignoring "disk" #10

Open richard-aio opened 3 years ago

richard-aio commented 3 years ago

When streaming the response from an S3 instance (DigitalOcean Spaces, using S3 driver), the disk is ignored and FileValue attempts to ready directly from the local disk:

        $encFilePath = $tomeUser->tome->id . '/' . $image->filename . '.enc';

        // Return the Image
        return response()->streamDownload(function () use ($image, $tomeUser, $encFilePath) {
            return FileVault::key($tomeUser->tome->key)
                ->disk('spaces')
                ->streamDecrypt($encFilePath);
        }, $image->filename);

As you can see in the log file, FileVault is using fopen() in my local directory:

[2020-12-26 14:24:19] local.ERROR: fopen(1/1608990767-5fe7402fa827b.png.enc): failed to open stream: No such file or directory {"userId":1,"exception":"[object] (ErrorException(code: 0): fopen(1/1608990767-5fe7402fa827b.png.enc): failed to open stream: No such file or directory at /Users/{name}/sites/{project}/vendor/soarecostin/file-vault/src/FileEncrypter.php:181)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'fopen(1/1608990...', '/Users/{user}/...', 181, Array)
#1 /Users/{user}/sites/{project}/vendor/soarecostin/file-vault/src/FileEncrypter.php(181): fopen('1/1608990767-5f...', 'r', false, Resource id #13)
#2 /Users/{user}/sites/{project}/vendor/soarecostin/file-vault/src/FileEncrypter.php(128): SoareCostin\\FileVault\\FileEncrypter->openSourceFile('1/1608990767-5f...')
#3 /Users/{user}/sites/{project}/vendor/soarecostin/file-vault/src/FileVault.php(161): SoareCostin\\FileVault\\FileEncrypter->decrypt('1/1608990767-5f...', 'php://output')
#4 /Users/{user}/sites/{project}/app/Http/Controllers/ImageController.php(73): SoareCostin\\FileVault\\FileVault->streamDecrypt('1/1608990767-5f...')
#5 /Users/{user}/sites/{project}/vendor/symfony/http-foundation/StreamedResponse.php(109): App\\Http\\Controllers\\ImageController->App\\Http\\Controllers\\{closure}()
#6 /Users/{user}/sites/{project}/vendor/symfony/http-foundation/Response.php(394): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#7 /Users/{user}/sites/{project}/vendor/laravel/framework/src/Illuminate/Support/HigherOrderTapProxy.php(34): Symfony\\Component\\HttpFoundation\\Response->send()
#8 /Users/{user}/sites/{project}/public/index.php(53): Illuminate\\Support\\HigherOrderTapProxy->__call('send', Array)
#9 /Users/{user}/.composer/vendor/laravel/valet/server.php(214): require('/Users/{user}/...')
#10 {main}
"} 
richard-aio commented 3 years ago

I can see the issue is that "s3" is hard coded in the solution as the disk name, instead of using the configuration for the disk driver.

If I get time over the next few days I will submit a pull request to resolve the issue.