From 787bcf77528f42e7b86d194b9365febb39a8b5ed Mon Sep 17 00:00:00 2001 From: Yassine El Khadiri Date: Tue, 30 Oct 2018 22:13:33 +0100 Subject: [PATCH] Fix backup MAC checking. if(MessageDigest.isEqual(ourMac, theirMac) was always returning false since ourMac was of length 32 and theirMac was of length 10. --- .../thoughtcrime/securesms/backup/FullBackupImporter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java b/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java index 206806d8e9..77ec1f53e7 100644 --- a/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java +++ b/src/org/thoughtcrime/securesms/backup/FullBackupImporter.java @@ -283,7 +283,7 @@ public class FullBackupImporter extends FullBackupBase { out.close(); - byte[] ourMac = mac.doFinal(); + byte[] ourMac = ByteUtil.trim(mac.doFinal(), 10); byte[] theirMac = new byte[10]; try { @@ -293,7 +293,7 @@ public class FullBackupImporter extends FullBackupBase { throw new IOException(e); } - if (MessageDigest.isEqual(ourMac, theirMac)) { + if (!MessageDigest.isEqual(ourMac, theirMac)) { //destination.delete(); throw new IOException("Bad MAC"); } @@ -314,9 +314,9 @@ public class FullBackupImporter extends FullBackupBase { System.arraycopy(frame, frame.length - 10, theirMac, 0, theirMac.length); mac.update(frame, 0, frame.length - 10); - byte[] ourMac = mac.doFinal(); + byte[] ourMac = ByteUtil.trim(mac.doFinal(), 10); - if (MessageDigest.isEqual(ourMac, theirMac)) { + if (!MessageDigest.isEqual(ourMac, theirMac)) { throw new IOException("Bad MAC"); }