From ff855cf0526678284381eb7b4f3aad3d48baeac1 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sun, 18 Jan 2015 19:11:31 +0100 Subject: [PATCH] devicechannel: check for decryption errors --- src/devicechannel.vala | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/devicechannel.vala b/src/devicechannel.vala index 0ba7b19..d556a8d 100644 --- a/src/devicechannel.vala +++ b/src/devicechannel.vala @@ -179,15 +179,25 @@ class DeviceChannel : Object { return; } + bool failed = false; var msgbytes = new ByteArray(); arr.foreach_element((a, i, node) => { + // exit early + if (failed == true) + return; + debug("node data: %s", node.get_string()); // encrypted data is base64 encoded uchar[] data = Base64.decode(node.get_string()); var dbytes = new Bytes.take(data); - ByteArray decrypted = this._crypt.decrypt(dbytes); - debug("data length: %zu", decrypted.data.length); - msgbytes.append(decrypted.data); + try { + ByteArray decrypted = this._crypt.decrypt(dbytes); + debug("data length: %zu", decrypted.data.length); + msgbytes.append(decrypted.data); + } catch (Error e) { + critical("decryption failed: %s", e.message); + failed = true; + } }); // data should be complete now debug("total length of packet data: %zu", msgbytes.len);