aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java31
1 files changed, 29 insertions, 2 deletions
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 2d6bba55..1f532370 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java
@@ -3,7 +3,6 @@ package eu.siacs.conversations.crypto.axolotl;
import android.util.Base64;
import android.util.Log;
-import org.whispersystems.libaxolotl.protocol.CiphertextMessage;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -24,6 +23,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import eu.siacs.conversations.Config;
+import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -42,6 +42,7 @@ public class XmppAxolotlMessage {
private byte[] innerKey;
private byte[] ciphertext = null;
+ private byte[] authtagPlusInnerKey = null;
private byte[] iv = null;
private final Map<Integer, XmppAxolotlSession.AxolotlKey> keys;
private final Jid from;
@@ -166,6 +167,14 @@ public class XmppAxolotlMessage {
Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec);
this.ciphertext = cipher.doFinal(Config.OMEMO_PADDING ? getPaddedBytes(plaintext) : plaintext.getBytes());
+ if (Config.PUT_AUTH_TAG_INTO_KEY && this.ciphertext != null) {
+ this.authtagPlusInnerKey = new byte[16+16];
+ byte[] ciphertext = new byte[this.ciphertext.length - 16];
+ System.arraycopy(this.ciphertext,0,ciphertext,0,ciphertext.length);
+ System.arraycopy(this.ciphertext,ciphertext.length,authtagPlusInnerKey,16,16);
+ System.arraycopy(this.innerKey,0,authtagPlusInnerKey,0,this.innerKey.length);
+ this.ciphertext = ciphertext;
+ }
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
| IllegalBlockSizeException | BadPaddingException | NoSuchProviderException
| InvalidAlgorithmParameterException e) {
@@ -202,7 +211,12 @@ public class XmppAxolotlMessage {
}
public void addDevice(XmppAxolotlSession session) {
- XmppAxolotlSession.AxolotlKey key = session.processSending(innerKey);
+ XmppAxolotlSession.AxolotlKey key;
+ if (authtagPlusInnerKey != null) {
+ key = session.processSending(authtagPlusInnerKey);
+ } else {
+ key = session.processSending(innerKey);
+ }
if (key != null) {
keys.put(session.getRemoteAddress().getDeviceId(), key);
}
@@ -254,6 +268,19 @@ public class XmppAxolotlMessage {
byte[] key = unpackKey(session, sourceDeviceId);
if (key != null) {
try {
+
+ if (key.length >= 32) {
+ int authtaglength = key.length - 16;
+ Log.d(Config.LOGTAG,"found auth tag as part of omemo key");
+ byte[] newCipherText = new byte[key.length - 16 + ciphertext.length];
+ byte[] newKey = new byte[16];
+ System.arraycopy(ciphertext, 0, newCipherText, 0, ciphertext.length);
+ System.arraycopy(key, 16, newCipherText, ciphertext.length, authtaglength);
+ System.arraycopy(key,0,newKey,0,newKey.length);
+ ciphertext = newCipherText;
+ key = newKey;
+ }
+
Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER);
SecretKeySpec keySpec = new SecretKeySpec(key, KEYTYPE);
IvParameterSpec ivSpec = new IvParameterSpec(iv);