- decrypt whole file, don't stop if enough data has been read from underlying fs

- write "length = 0" into file header until everything is encrypted

(tested on windows, everything is fine here)
This commit is contained in:
Sebastian Stenzel
2016-02-22 23:06:02 +01:00
parent 5b22806bbc
commit c03bdd8425
2 changed files with 2 additions and 8 deletions

View File

@@ -32,7 +32,6 @@ import javax.crypto.SecretKey;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import org.apache.commons.codec.binary.Hex;
import org.cryptomator.crypto.engine.AuthenticationFailedException;
import org.cryptomator.crypto.engine.FileContentCryptor;
import org.cryptomator.crypto.engine.FileContentDecryptor;
@@ -49,7 +48,6 @@ class FileContentDecryptorImpl implements FileContentDecryptor {
private final Supplier<Mac> hmacSha256;
private final FileHeader header;
private final boolean authenticate;
private final LongAdder ciphertextBytesScheduledForDecryption = new LongAdder();
private final LongAdder cleartextBytesDecrypted = new LongAdder();
private ByteBuffer ciphertextBuffer = ByteBuffer.allocate(CHUNK_SIZE);
private long chunkNumber = 0;
@@ -68,14 +66,10 @@ class FileContentDecryptorImpl implements FileContentDecryptor {
@Override
public void append(ByteBuffer ciphertext) throws InterruptedException {
long numChunksNeeded = (contentLength() - 1) / PAYLOAD_SIZE + 1;
long numCiphertextBytesNeeded = numChunksNeeded * CHUNK_SIZE;
if (ciphertext == FileContentCryptor.EOF || ciphertextBytesScheduledForDecryption.sum() >= numCiphertextBytesNeeded) {
if (ciphertext == FileContentCryptor.EOF) {
submitCiphertextBuffer();
submitEof();
} else {
ciphertextBytesScheduledForDecryption.add(ciphertext.remaining());
while (ciphertext.hasRemaining()) {
ByteBuffers.copy(ciphertext, ciphertextBuffer);
submitCiphertextBufferIfFull();

View File

@@ -40,7 +40,7 @@ class CryptoWritableFile implements WritableFile {
private void initialize(long firstCleartextByte) {
encryptor = cryptor.createFileContentEncryptor(Optional.empty(), firstCleartextByte);
file.position(cryptor.getHeaderSize()); // skip header size, header is written on close
writeHeader(); // write header with "zero content length" to avoid read access while still writing
writeTask = executorService.submit(new CiphertextWriter(file, encryptor));
}