From bd2e59e9e0711e803bd805d16cd1bca5f998647f Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 17 Jan 2015 22:14:45 +0100 Subject: [PATCH] devicechannel: decrypt encrypted data --- src/devicechannel.vala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/devicechannel.vala b/src/devicechannel.vala index b767a53..5d4af8b 100644 --- a/src/devicechannel.vala +++ b/src/devicechannel.vala @@ -142,6 +142,23 @@ class DeviceChannel : Object { } private void handle_encrypted_packet(Packet pkt) { + // Ecypted packets have 'data' member in body. The 'data' + // member is an array of strings, each string is base64 + // encoded data, of length appropriate for channel ecryption + // method. + Json.Array arr = pkt.body.get_array_member("data"); + if (arr == null) { + critical("missing data member in encrypted packet"); + return; + } + var msgbytes = new ByteArray(); + arr.foreach_element((a, i, node) => { + debug("node data: %s", node.get_string()); + uchar[] data = Base64.decode(node.get_string()); + var dbytes = new Bytes.take(data); + Bytes decrypted = this._crypt.decrypt(dbytes); + msgbytes.append(decrypted.get_data()); + }); } } \ No newline at end of file