From 8f4b7686c94c52563c29f100cd25599ac08a7bb2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 30 Aug 2015 11:11:54 +0200 Subject: [PATCH] catch invalid base64 on omemo key decoding --- .../java/eu/siacs/conversations/parser/IqParser.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/IqParser.java b/src/main/java/eu/siacs/conversations/parser/IqParser.java index 44e4bc08..f6446cfd 100644 --- a/src/main/java/eu/siacs/conversations/parser/IqParser.java +++ b/src/main/java/eu/siacs/conversations/parser/IqParser.java @@ -149,7 +149,12 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { if(signedPreKeySignature == null) { return null; } - return Base64.decode(signedPreKeySignature.getContent(),Base64.DEFAULT); + try { + return Base64.decode(signedPreKeySignature.getContent(), Base64.DEFAULT); + } catch (IllegalArgumentException e) { + Log.e(Config.LOGTAG,AxolotlService.LOGPREFIX+" : Invalid base64 in signedPreKeySignature"); + return null; + } } public IdentityKey identityKey(final Element bundle) { @@ -160,7 +165,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { } try { identityKey = new IdentityKey(Base64.decode(identityKeyElement.getContent(), Base64.DEFAULT), 0); - } catch (InvalidKeyException e) { + } catch (InvalidKeyException | IllegalArgumentException e) { Log.e(Config.LOGTAG,AxolotlService.LOGPREFIX+" : "+"Invalid identityKey in PEP: "+e.getMessage()); } return identityKey; @@ -191,7 +196,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { try { ECPublicKey preKeyPublic = Curve.decodePoint(Base64.decode(preKeyPublicElement.getContent(), Base64.DEFAULT), 0); preKeyRecords.put(preKeyId, preKeyPublic); - } catch (InvalidKeyException e) { + } catch (InvalidKeyException | IllegalArgumentException e) { Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX+" : "+"Invalid preKeyPublic (ID="+preKeyId+") in PEP: "+ e.getMessage()+", skipping..."); continue; }