Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Delete multichunk from cache if decryption failed. Related to #59
Browse files Browse the repository at this point in the history
  • Loading branch information
binwiederhier committed Sep 10, 2014
1 parent dd3f3ae commit daacbad
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions syncany-lib/src/main/java/org/syncany/operations/Downloader.java
Expand Up @@ -70,17 +70,31 @@ public void downloadAndDecryptMultiChunks(Set<MultiChunkId> unknownMultiChunkIds
logger.log(Level.INFO, " + Downloading multichunk " + multiChunkId + " ...");
transferManager.download(remoteMultiChunkFile, localEncryptedMultiChunkFile);

logger.log(Level.INFO, " + Decrypting multichunk " + multiChunkId + " ...");
InputStream multiChunkInputStream = config.getTransformer().createInputStream(new FileInputStream(localEncryptedMultiChunkFile));
OutputStream decryptedMultiChunkOutputStream = new FileOutputStream(localDecryptedMultiChunkFile);
try {
logger.log(Level.INFO, " + Decrypting multichunk " + multiChunkId + " ...");
InputStream multiChunkInputStream = config.getTransformer().createInputStream(new FileInputStream(localEncryptedMultiChunkFile));
OutputStream decryptedMultiChunkOutputStream = new FileOutputStream(localDecryptedMultiChunkFile);

IOUtils.copy(multiChunkInputStream, decryptedMultiChunkOutputStream);

decryptedMultiChunkOutputStream.close();
multiChunkInputStream.close();

IOUtils.copy(multiChunkInputStream, decryptedMultiChunkOutputStream);

decryptedMultiChunkOutputStream.close();
multiChunkInputStream.close();

logger.log(Level.FINE, " + Locally deleting multichunk " + multiChunkId + " ...");
localEncryptedMultiChunkFile.delete();
}
catch (IOException e) {
// Security: Deleting the multichunk if the decryption/extraction failed is important!
// If it is not deleted, the partially decrypted multichunk will reside in the
// local cache and the next 'down' will try to use it. If this is the only
// multichunk that has been tampered with, other changes might be applied to the
// file system! See https://github.com/syncany/syncany/issues/59#issuecomment-55154793

logger.log(Level.FINE, " -> FAILED: Decryption/extraction of multichunk failed, deleting " + multiChunkId + " ...");
localDecryptedMultiChunkFile.delete();
}
finally {
logger.log(Level.FINE, " + Locally deleting multichunk " + multiChunkId + " ...");
localEncryptedMultiChunkFile.delete();
}
}
}

Expand Down

0 comments on commit daacbad

Please sign in to comment.