Bug #79634 [Com]: Could not open password protected zip archive
| From: | freshprince dot 2b at gmx dot net | Date: | Tue, 26 May 2020 08:53:27 +0000 |
| Subject: | Bug #79634 [Com]: Could not open password protected zip archive | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227168@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79634&edit=1
ID: 79634
Comment by: freshprince dot 2b at gmx dot net
Reported by: freshprince dot 2b at gmx dot net
Summary: Could not open password protected zip archive
Status: Feedback
Type: Bug
Package: Zip Related
Operating System: Mac
PHP Version: 7.4.6
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> 'unsupported compression method 99'
Is the output of a working zip archive (without line breaks) and the archive with the infinite
password prompt.
A try with the 7-zip[1] was working as expected with all zip archives.
Should not be there a way to create and extract a password protected zip archive, without any
additional tools? Or do I understand it wrong?
[1] <http://www.koozie.org/blog/2014/08/creating-aes256-encrypted-zip-archive-files-mac-command-line/#aes256-encrypted-zip-files>
Previous Comments:
------------------------------------------------------------------------
[2020-05-26 07:12:36] cmb@php.net
> 'unsupported compression method 99'
Compression method 99 is AE-x encryption[1], and apparently this
is not properly supported by your Zip tools. Please try with
7-zip[2].
[1] <https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT>
section 4.4.5
[2] <http://www.koozie.org/blog/2014/08/creating-aes256-encrypted-zip-archive-files-mac-command-line/#aes256-encrypted-zip-files>
------------------------------------------------------------------------
[2020-05-26 06:45:27] freshprince dot 2b at gmx dot net
Description:
------------
I was creating a zip archive with php 7.4.6 (lib-zip version 1.6.1) without any problems.
Now I try to protect these zip archive with a password. Not just for encrypting with php, but in
general. I found this tutorial
(https://odan.github.io/2018/02/18/creating-encrypted-zip-files-with-password-in-php.html). It does
what it should, but I could not read the files of the zip archive any more. If I doubleclick on the
archive, the password prompt opens up, but it does not work with the password from the source code.
I also copy and pasted it to prevent any keyboard struggle.
One problem is, that there is no password prompt, if all files are empty.
Same code works for files without line breaks (oneliner), but the error occurs, if the file has
multiple lines.
Maybe I'm doing something wrong?
I also posted the question on https://stackoverflow.com/questions/61908181/could-not-open-password-protected-zip-archive
maybe there are further information later.
Test script:
---------------
<?php
$zip = new ZipArchive();
$filePath = sprintf('%s/test/', __DIR__);
$fileName = 'test.zip';
$absoluteFilePath = sprintf('%s/%s', __DIR__, $fileName);
$excludeFolderNames = [
'.',
'..',
$fileName,
];
$zipFlag = ZipArchive::CREATE;
if (file_exists($absoluteFilePath)) {
$zipFlag = ZipArchive::OVERWRITE;
}
$createFile = $zip->open($absoluteFilePath, $zipFlag);
if (true !== $createFile) {
throw new RuntimeException(sprintf('could not open file in "%s" with: %s',
$fileName, $createFile));
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filePath));
$password = 'top-secret';
if (!$zip->setPassword($password)) {
throw new RuntimeException('Set password failed');
}
/** @var SplFileInfo $value */
foreach ($iterator as $key => $value) {
if (in_array($value->getFilename(), $excludeFolderNames)) {
continue;
}
$cleanFilePath = realpath($key);
if (!$cleanFilePath) {
throw new RuntimeException(sprintf('could not create real path from filepath: %s',
$key));
}
$zipName = str_replace($filePath, '', $cleanFilePath);
if (!$zip->addFile($cleanFilePath, $zipName)) {
throw new RuntimeException(sprintf('Add file failed: %s', $cleanFilePath));
}
if (!$zip->setEncryptionName($zipName, ZipArchive::EM_AES_256)) {
throw new RuntimeException(sprintf('Set encryption failed: %s', $zipName));
}
}
$zip->close();
Expected result:
----------------
A password protected zip archive, which can be unpacked in a operating system.
Actual result:
--------------
On every try to unpack the ziparchive the password prompt comes up again and again.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79634&edit=1