Skip to content

Commit 23d91a8

Browse files
committed
Improved backup efficiency and security.
1 parent 83e055e commit 23d91a8

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Backup Shield simply listens for when the .zip-file generated by Laravel-backup
1717

1818
## Installation
1919

20-
`composer require olssonm/laravel-backup-shield`
20+
```bash
21+
composer require olssonm/laravel-backup-shield
22+
```
2123

2224
Requires `PHP: "^7.0"` and `laravel/framework: "^5.3"`.
2325

@@ -58,7 +60,11 @@ Set your type of encryption. Available options are:
5860
`\Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_192` (AES 192)
5961
`\Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_256` (AES 256)
6062

61-
Note that macOS among other does *not* support the Winzip AES-encryption methods as standard. You might have to buy a separate app and/or license to decrypt and open the protected file. However, if you have the option for AES 256 you should go with that as ZipCrypto may be weak.
63+
**Important information regarding encryption**
64+
65+
Using the `ENCRYPTION_DEFAULT` (PKWARE/ZipCrypto) crypto gives you the best portability as most operating systems can natively unzip the file – however, ZipCrypto might be weak. The Winzip AES-methods on the other hand might require a separate app and/or licence to be able to unzip depending on your OS; suggestions for macOS are [Keka](http://www.kekaosx.com/en/) and [Stuffit Expander](https://itunes.apple.com/us/app/stuffit-expander-16/id919269455).
66+
67+
Also to note is that when zipping very large files ZipCrypto might be very inefficient as the entire data-set will have to be loaded into memory to perform the encryption, if the zipped file's content is bigger than your available RAM you *will* run out of memory.
6268

6369
## Testing
6470

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"spatie/laravel-backup": "~4.0|~5.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "~5.4 || ~6.0 || ~7.0",
27+
"phpunit/phpunit": "~5.4 || ~6.0 || ~7.1",
2828
"orchestra/testbench": "^3.3"
2929
},
3030
"autoload": {

src/Factories/Password.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ class Password
1818
*/
1919
function __construct(string $path)
2020
{
21-
consoleOutput()->comment('Applying password and encryption to zipped file...');
21+
consoleOutput()->info('Applying password and encryption to zip...');
2222

23-
// Create a new zip, add the existing from spatie/backup and encrypt
23+
// Create a new zip, add the zip from spatie/backup, encrypt and resave
2424
$zipFile = new ZipFile();
25-
$zipFile->addFile($path, 'backup.zip');
25+
$zipFile->addFile($path, 'backup.zip', ZipFile::METHOD_DEFLATED);
2626
$zipFile->setPassword(config('backup-shield.password'), config('backup-shield.encryption'));
2727
$zipFile->saveAsFile($path);
2828
$zipFile->close();
2929

30-
// $zip = (new ZipFile())->openFile($path);
31-
// $zip->setPassword(config('backup-shield.password'), config('backup-shield.encryption'));
32-
// $zip->saveAsFile($path);
33-
34-
consoleOutput()->comment('Applied password and encryption to zipped file.');
30+
consoleOutput()->info('Applied password and encryption to zip.');
3531

3632
$this->path = $path;
3733
}

tests/BackupShieldTests.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Olssonm\BackupShield\Tests;
44

55
use Spatie\Backup\Events\BackupZipWasCreated;
6+
use PhpZip\ZipFile;
67

78
use Artisan;
89

@@ -52,15 +53,15 @@ public function test_config_file_is_installed()
5253
public function test_listener_return_data()
5354
{
5455
// Set parameters for testing
55-
$path = __DIR__ . '/resources/test-big.zip';
56+
$path = __DIR__ . '/resources/test.zip';
5657
$pathTest = __DIR__ . '/resources/processed.zip';
5758

5859
// Make backup
5960
copy($path, $pathTest);
6061

6162
// Manually set config
6263
config()->set('backup-shield.password', 'W2psdtBz9KWX49tccsr6mYwevyciTdJnJjLjtKSGkVTN1hFLH7YuaMsCBFo7AsAn');
63-
config()->set('backup-shield.encruption', \Olssonm\BackupShield\Encryption::ENCRYPTION_DEFAULT);
64+
config()->set('backup-shield.encryption', \Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_256);
6465

6566
$data = event(new BackupZipWasCreated($pathTest));
6667

@@ -71,12 +72,21 @@ public function test_listener_return_data()
7172
public function test_encryption_protection()
7273
{
7374
// Test that the archive actually is encrypted and password protected
75+
$path = __DIR__ . '/resources/processed.zip';
76+
77+
$zipFile = (new ZipFile())->openFile($path);
78+
$zipInfo = $zipFile->getAllInfo();
79+
80+
$this->assertEquals(true, $zipInfo['backup.zip']->isEncrypted());
81+
$this->assertEquals('backup.zip', $zipInfo['backup.zip']->getName());
82+
$this->assertEquals(config('backup-shield.encryption'), $zipInfo['backup.zip']->getEncryptionMethod());
7483
}
7584

7685
/** Teardown */
7786
public static function tearDownAfterClass()
7887
{
79-
// Delete config-file
88+
// Delete config and test-files
89+
unlink(__DIR__ . '/resources/processed.zip');
8090
unlink(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/config/backup-shield.php');
8191
parent::tearDownAfterClass();
8292
}

0 commit comments

Comments
 (0)