mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-19 17:16:53 -04:00
- 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:
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user