From 7e77801aa4996f6afdd70d190932a9ae9c5ec82a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20H=C3=B6rist?= <philipp@hoerist.com>
Date: Fri, 17 Jan 2020 22:40:45 +0100
Subject: [PATCH] [omemo] Add back 12 byte IV read support for aesgcm links

---
 omemo/file_crypto.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/omemo/file_crypto.py b/omemo/file_crypto.py
index 8419155c..37d40a26 100644
--- a/omemo/file_crypto.py
+++ b/omemo/file_crypto.py
@@ -169,10 +169,19 @@ class FileDecryption:
             raise ValueError('Invalid fragment')
 
         fragment = binascii.unhexlify(fragment)
-        key = fragment[16:]
-        iv = fragment[:16]
-        if len(key) != 32 or len(iv) != 16:
-            raise ValueError('Invalid fragment')
+        size = len(fragment)
+        # Clients started out with using a 16 byte IV but long term
+        # want to swtich to the more performant 12 byte IV
+        # We have to support both
+        if size == 48:
+            key = fragment[16:]
+            iv = fragment[:16]
+        elif size == 44:
+            key = fragment[12:]
+            iv = fragment[:12]
+        else:
+            raise ValueError('Invalid fragment size: %s' % size)
+
         return key, iv
 
     @staticmethod
-- 
GitLab