Skip to content

Commit

Permalink
Merge branch 'master' of github.com:guardianproject/orbot
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Jul 25, 2022
2 parents ebb8511 + 0a2f445 commit 35ca3c4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
Expand Down Expand Up @@ -89,17 +92,34 @@ public boolean unzip(String outputPath) {
}
}

private static final List<String> ONION_SERVICE_CONFIG_FILES = Arrays.asList("config.json",
"hostname",
"hs_ed25519_public_key",
"hs_ed25519_secret_key");

private boolean extractFromZipInputStream(String outputPath, ZipInputStream zis) {
File outputDir = new File(outputPath);
try {
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;

new File(outputPath).mkdirs();
outputDir.mkdirs();

while ((ze = zis.getNextEntry()) != null) {
String filename = ze.getName();

if (!ONION_SERVICE_CONFIG_FILES.contains(filename)) { // *any* kind of foreign file
File[] writtenFiles = outputDir.listFiles();
if (writtenFiles != null) {
for (File writtenFile: writtenFiles) {
writtenFile.delete();
}
}
outputDir.delete();
return false;
}

// Need to create directories if not exists, or it will generate an Exception...
if (ze.isDirectory()) {
File fmd = new File(outputPath + "/" + filename);
Expand Down
Loading

0 comments on commit 35ca3c4

Please sign in to comment.