From abfa4eae08e3c27fd85b4f0805f7a4d6c7422ff0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 8 May 2020 19:33:49 +0200 Subject: [PATCH] remove white space before parsing omemo bundle base64 --- .../eu/siacs/conversations/parser/IqParser.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/IqParser.java b/src/main/java/eu/siacs/conversations/parser/IqParser.java index ebcdfd8a3..dee740d9f 100644 --- a/src/main/java/eu/siacs/conversations/parser/IqParser.java +++ b/src/main/java/eu/siacs/conversations/parser/IqParser.java @@ -5,6 +5,7 @@ import android.text.TextUtils; import android.util.Log; import android.util.Pair; +import com.google.common.base.CharMatcher; import com.google.common.io.BaseEncoding; import org.whispersystems.libsignal.IdentityKey; @@ -206,7 +207,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { return null; } try { - publicKey = Curve.decodePoint(BaseEncoding.base64().decode(signedPreKeyPublic), 0); + publicKey = Curve.decodePoint(base64decode(signedPreKeyPublic), 0); } catch (final IllegalArgumentException | InvalidKeyException e) { Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Invalid signedPreKeyPublic in PEP: " + e.getMessage()); } @@ -219,7 +220,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { return null; } try { - return BaseEncoding.base64().decode(signedPreKeySignature); + return base64decode(signedPreKeySignature); } catch (final IllegalArgumentException e) { Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : Invalid base64 in signedPreKeySignature"); return null; @@ -232,7 +233,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { return null; } try { - return new IdentityKey(BaseEncoding.base64().decode(identityKey), 0); + return new IdentityKey(base64decode(identityKey), 0); } catch (final IllegalArgumentException | InvalidKeyException e) { Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Invalid identityKey in PEP: " + e.getMessage()); return null; @@ -260,10 +261,14 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Encountered unexpected tag in prekeys list: " + preKeyPublicElement); continue; } + final String preKey = preKeyPublicElement.getContent(); + if (preKey == null) { + continue; + } Integer preKeyId = null; try { preKeyId = Integer.valueOf(preKeyPublicElement.getAttribute("preKeyId")); - final ECPublicKey preKeyPublic = Curve.decodePoint(BaseEncoding.base64().decode(preKeyPublicElement.getContent()), 0); + final ECPublicKey preKeyPublic = Curve.decodePoint(base64decode(preKey), 0); preKeyRecords.put(preKeyId, preKeyPublic); } catch (NumberFormatException e) { Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "could not parse preKeyId from preKey " + preKeyPublicElement.toString()); @@ -274,6 +279,10 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { return preKeyRecords; } + private static byte[] base64decode(String input) { + return BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(input)); + } + public Pair verification(final IqPacket packet) { Element item = getItem(packet); Element verification = item != null ? item.findChild("verification", AxolotlService.PEP_PREFIX) : null;