Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/1.21.0' into release/1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SessionHero01 committed Mar 6, 2025
2 parents c5912c3 + 3b9cfd9 commit 84d775c
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions app/src/main/java/org/thoughtcrime/securesms/logging/LogFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,37 @@ String readAll() throws IOException {

String readEntry() throws IOException {
try {
// Read the IV and length
Util.readFully(inputStream, ivBuffer);
Util.readFully(inputStream, intBuffer);
} catch (EOFException e) {
// End of file reached before a full header could be read.
return null;
}

int length = Conversions.byteArrayToInt(intBuffer);
byte[] ciphertext = ciphertextBuffer.get(length);
int length = Conversions.byteArrayToInt(intBuffer);
byte[] ciphertext = ciphertextBuffer.get(length);

try {
Util.readFully(inputStream, ciphertext, length);
} catch (EOFException e) {
// Incomplete ciphertext – likely due to a partially written record.
return null;
}

try {
synchronized (CIPHER_LOCK) {
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secret, "AES"), new IvParameterSpec(ivBuffer));
byte[] plaintext = cipher.doFinal(ciphertext, 0, length);
return new String(plaintext);
}
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
throw new AssertionError(e);
try {
synchronized (CIPHER_LOCK) {
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secret, "AES"), new IvParameterSpec(ivBuffer));
byte[] plaintext = cipher.doFinal(ciphertext, 0, length);
return new String(plaintext);
}
} catch (EOFException e) {
} catch (BadPaddingException e) {
// Bad padding likely indicates a corrupted or incomplete entry.
// Instead of throwing an error, treat this as the end of the log.
return null;
} catch (InvalidKeyException | InvalidAlgorithmParameterException
| IllegalBlockSizeException e) {
throw new AssertionError(e);
}
}
}
Expand Down

0 comments on commit 84d775c

Please sign in to comment.