go back to 16 byte IVs for OMEMO

Daniel Gultsch created

clients like Dino can’t handle 12 byte IVs

Change summary

src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java     |  2 
src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java | 27 
2 files changed, 13 insertions(+), 16 deletions(-)

Detailed changes

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;

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());
 	}