[TRUEZIP-360] "Enter key for writing" popup shouldn't be shown Created: 13/Mar/15  Updated: 13/Mar/15

Status: Open
Project: TrueZIP
Component/s: TrueZIP Kernel
Affects Version/s: TrueZIP 7.7.8
Fix Version/s: None

Type: Bug Priority: Major
Reporter: lbinkiewicz Assignee: Christian Schlichtherle
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I've noticed that "Enter key for writing" popup appears while it shoudn't.
Attached file should explain the issue.



 Comments   
Comment by lbinkiewicz [ 13/Mar/15 ]

package issue;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.Charset;

import de.schlichtherle.truezip.crypto.param.AesKeyStrength;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TConfig;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileWriter;
import de.schlichtherle.truezip.fs.FsController;
import de.schlichtherle.truezip.fs.FsDriverProvider;
import de.schlichtherle.truezip.fs.FsModel;
import de.schlichtherle.truezip.fs.FsOutputOption;
import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
import de.schlichtherle.truezip.fs.archive.zip.ZipDriverEntry;
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
import de.schlichtherle.truezip.util.BitField;
import de.schlichtherle.truezip.zip.WinZipAesParameters;
import de.schlichtherle.truezip.zip.ZipCryptoParameters;
import de.schlichtherle.truezip.zip.ZipKeyException;

public class TrueZipTest {

final class CustomWinZipAesParameters implements WinZipAesParameters {
final byte[] password;

CustomWinZipAesParameters(final byte[] password)

{ this.password = password.clone(); }

@Override
public byte[] getWritePassword(String name) throws ZipKeyException

{ return password.clone(); }

@Override
public byte[] getReadPassword(String name, boolean invalid)
throws ZipKeyException

{ if (invalid) throw new ZipKeyException(name + " (invalid password)"); return password.clone(); }

@Override
public AesKeyStrength getKeyStrength(String arg0)
throws ZipKeyException

{ return AesKeyStrength.BITS_256; }

@Override
public void setKeyStrength(String name, AesKeyStrength keyStrength)
throws ZipKeyException

{ // We have been using only 128 bits to create archive entries. assert AesKeyStrength.BITS_256 == keyStrength; }

}

final class CustomZipDriver extends ZipDriver {
final ZipCryptoParameters param;

public CustomZipDriver(byte[] password)

{ super(IOPoolLocator.SINGLETON); param = new CustomWinZipAesParameters(password); }

@Override
protected ZipCryptoParameters zipCryptoParameters(FsModel model,
Charset charset)

{ return param; }

@Override
public <M extends FsModel> FsController<M> decorate(
FsController<M> controller)

{ return controller; }

@Override
protected boolean process(ZipDriverEntry input, ZipDriverEntry output)

{ return false; }

}

private void setConfig1()

{ final TConfig config = TConfig.get(); FsDriverProvider provider = new TArchiveDetector( TArchiveDetector.ALL.toString()); config.setOutputPreferences(config.getOutputPreferences().clear( FsOutputOption.ENCRYPT)); config.setArchiveDetector(new TArchiveDetector(provider, ".zip")); }

private void setConfig2(String password)

{ final TConfig config = TConfig.get(); FsDriverProvider provider = new TArchiveDetector( TArchiveDetector.ALL.toString()); config.setOutputPreferences(config.getOutputPreferences().or( BitField.of(FsOutputOption.ENCRYPT))); config.setArchiveDetector(new TArchiveDetector(provider, ".zip", new CustomZipDriver(password.getBytes()))); }

private File createSampleFile(String dir, String zipFile, String innerFile)
throws IOException {
File f = new TFile(dir, zipFile);
File file = new TFile(f.getPath() + File.separator + innerFile);
Writer writer = new TFileWriter(file, true, Charset.forName("UTF-8"));
try

{ writer.write("TEST"); }

finally

{ writer.close(); }

return f;

}

public static void main(String[] args) throws IOException,
InterruptedException {
String workingDir = "/home/lukasz/ar1";
String zipName = "a.zip";
String innerFile = "a.txt";

TrueZipTest tzt = new TrueZipTest();

File finit = new File(workingDir, zipName);
if (finit.exists())

{ finit.delete(); System.out.println(finit.exists()); }

/*UNCOMMENT
tzt.setConfig2("test2");
File f0 = tzt.createSampleFile(workingDir, zipName, innerFile);
TFile.rm_r(f0);
System.out.println(f0.exists());
*/

// create archive without pass
tzt.setConfig1();
File f1 = tzt.createSampleFile(workingDir, zipName, innerFile);
TFile.rm_r(f1);
System.out.println(f1.exists());
//

// create archive with pass
tzt.setConfig2("test");
File f2 = tzt.createSampleFile(workingDir, zipName, innerFile);
TFile.rm_r(f2);
System.out.println(f2.exists());

// create archive with pass
tzt.setConfig2("test2");
File f3 = tzt.createSampleFile(workingDir, zipName, innerFile);
TFile.rm_r(f3);
System.out.println(f3.exists());

tzt.setConfig1();
File f4 = tzt.createSampleFile(workingDir, zipName, innerFile);
TFile.rm_r(f4);
System.out.println(f4.exists());

}

}

Comment by lbinkiewicz [ 13/Mar/15 ]

This issue occurs only while first file is created as not encrypted, If You uncomment this section:
/*UNCOMMENT
tzt.setConfig2("test2");
File f0 = tzt.createSampleFile(workingDir, zipName, innerFile);
TFile.rm_r(f0);
System.out.println(f0.exists());
*/
There is no popup displayed.





Generated at Tue Jul 07 10:08:49 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.