aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-12-20 16:12:12 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-12-20 16:12:12 +0100
commite5fff42b10ba21bffa68c4c091e7c6126f8f0652 (patch)
tree03d866f9d67981ba353db2c15313cf2f3b5a7917 /src/main
parentfbbf1a37b47b3967699bdb88ac31f5959b34dba6 (diff)
added omemo padding but disabled by Config.java flag
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java1
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java20
2 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index dbd27baf..fd8dc7be 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -82,6 +82,7 @@ public final class Config {
public static final long OMEMO_AUTO_EXPIRY = 7 * MILLISECONDS_IN_DAY;
public static final boolean REMOVE_BROKEN_DEVICES = false;
+ public static final boolean OMEMO_PADDING = false;
public static final boolean DISABLE_PROXY_LOOKUP = false; //useful to debug ibb
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
index 981b93ec..3fcd0fcf 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
@@ -162,7 +162,7 @@ public class XmppAxolotlMessage {
IvParameterSpec ivSpec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
- this.ciphertext = cipher.doFinal(plaintext.getBytes());
+ this.ciphertext = cipher.doFinal(Config.OMEMO_PADDING ? getPaddedBytes(plaintext) : plaintext.getBytes());
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
| IllegalBlockSizeException | BadPaddingException | NoSuchProviderException
| InvalidAlgorithmParameterException e) {
@@ -170,6 +170,22 @@ public class XmppAxolotlMessage {
}
}
+ private static byte[] getPaddedBytes(String plaintext) {
+ int plainLength = plaintext.getBytes().length;
+ int pad = Math.max(64,(plainLength / 32 + 1) * 32) - plainLength;
+ SecureRandom random = new SecureRandom();
+ int left = random.nextInt(pad);
+ int right = pad - left;
+ StringBuilder builder = new StringBuilder(plaintext);
+ for(int i = 0; i < left; ++i) {
+ builder.insert(0,random.nextBoolean() ? "\t" : " ");
+ }
+ for(int i = 0; i < right; ++i) {
+ builder.append(random.nextBoolean() ? "\t" : " ");
+ }
+ return builder.toString().getBytes();
+ }
+
public Jid getFrom() {
return this.from;
}
@@ -239,7 +255,7 @@ public class XmppAxolotlMessage {
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
String plaintext = new String(cipher.doFinal(ciphertext));
- plaintextMessage = new XmppAxolotlPlaintextMessage(plaintext, session.getFingerprint());
+ plaintextMessage = new XmppAxolotlPlaintextMessage(Config.OMEMO_PADDING ? plaintext.trim() : plaintext, session.getFingerprint());
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException