From ce46b36c339b33538de2312942ccf2a9fe8264c0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 4 Oct 2018 22:32:37 +0200 Subject: [PATCH] go back to 16 byte IVs for OMEMO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clients like Dino can’t handle 12 byte IVs --- .../crypto/axolotl/AxolotlService.java | 2 +- .../crypto/axolotl/XmppAxolotlMessage.java | 27 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 53b5a9ab5..2b7b3f2b9 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -550,7 +550,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { } else { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": own device " + session.getFingerprint() + " was active " + hours + " hours ago"); } - } + } //TODO print last activation diff } } return devices; 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 1852bf183..33c28c3d0 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java @@ -4,15 +4,12 @@ import android.util.Base64; import android.util.Log; import android.util.SparseArray; - import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; @@ -30,12 +27,12 @@ import rocks.xmpp.addr.Jid; public class XmppAxolotlMessage { public static final String CONTAINERTAG = "encrypted"; - public static final String HEADER = "header"; - public static final String SOURCEID = "sid"; - public static final String KEYTAG = "key"; - public static final String REMOTEID = "rid"; - public static final String IVTAG = "iv"; - public static final String PAYLOAD = "payload"; + private static final String HEADER = "header"; + private static final String SOURCEID = "sid"; + private static final String KEYTAG = "key"; + private static final String REMOTEID = "rid"; + private static final String IVTAG = "iv"; + private static final String PAYLOAD = "payload"; private static final String KEYTYPE = "AES"; private static final String CIPHERMODE = "AES/GCM/NoPadding"; @@ -53,7 +50,7 @@ public class XmppAxolotlMessage { private final String plaintext; private final String fingerprint; - public XmppAxolotlPlaintextMessage(String plaintext, String fingerprint) { + XmppAxolotlPlaintextMessage(String plaintext, String fingerprint) { this.plaintext = plaintext; this.fingerprint = fingerprint; } @@ -73,7 +70,7 @@ public class XmppAxolotlMessage { private final byte[] key; private final byte[] iv; - public XmppAxolotlKeyTransportMessage(String fingerprint, byte[] key, byte[] iv) { + XmppAxolotlKeyTransportMessage(String fingerprint, byte[] key, byte[] iv) { this.fingerprint = fingerprint; this.key = key; this.iv = iv; @@ -143,7 +140,7 @@ public class XmppAxolotlMessage { } } - public XmppAxolotlMessage(Jid from, int sourceDeviceId) { + XmppAxolotlMessage(Jid from, int sourceDeviceId) { this.from = from; this.sourceDeviceId = sourceDeviceId; this.keys = new SparseArray<>(); @@ -168,7 +165,7 @@ public class XmppAxolotlMessage { private static byte[] generateIv() { SecureRandom random = new SecureRandom(); - byte[] iv = new byte[12]; + byte[] iv = new byte[16]; random.nextBytes(iv); return iv; } @@ -177,7 +174,7 @@ public class XmppAxolotlMessage { return ciphertext != null; } - public void encrypt(String plaintext) throws CryptoFailedException { + void encrypt(String plaintext) throws CryptoFailedException { try { SecretKey secretKey = new SecretKeySpec(innerKey, KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(iv); @@ -276,7 +273,7 @@ public class XmppAxolotlMessage { return session.processReceiving(encryptedKey); } - public XmppAxolotlKeyTransportMessage getParameters(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException { + XmppAxolotlKeyTransportMessage getParameters(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException { return new XmppAxolotlKeyTransportMessage(session.getFingerprint(), unpackKey(session, sourceDeviceId), getIV()); }