From 81ce0cec65f359513447d7f313725ae27af1625f Mon Sep 17 00:00:00 2001 From: Thai Dinh Le Date: Sun, 6 Jun 2021 23:53:25 +0200 Subject: [PATCH] Update README + Documentations --- README.md | 13 ++- example/lib/main.dart | 24 +++- lib/src/appframework/transfer_manager.dart | 13 ++- lib/src/network/aodv/aodv_manager.dart | 3 +- .../network/datalinkmanager/wrapper_ble.dart | 1 - .../network/datalinkmanager/wrapper_wifi.dart | 2 - lib/src/presentation/constants.dart | 65 ++--------- lib/src/presentation/crypto_engine.dart | 40 +++---- .../presentation/presentation_manager.dart | 8 +- lib/src/presentation/reply.dart | 6 +- lib/src/presentation/request.dart | 16 +-- .../presentation/secure_group_controller.dart | 108 +++++++----------- 12 files changed, 118 insertions(+), 181 deletions(-) diff --git a/README.md b/README.md index 485ea17..1ed9fa1 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,16 @@ The ad hoc library supports the following operations: - Broadcast data in plain-text to all directly connected neighbors - Broadcast encrypted data to all directly connected neighbors - Revoke its certificate (private key compromised) -- Create a secure group in the ad hoc network -- Join an existing secure group in the ad hoc network -- Leave an existing secure group in the ad hoc network +- Create a secure group +- Join an existing secure group +- Leave an existing secure group +- Send encrypted data to an existing secure group - Provides notifications of specific events related to the library (e.g., connection established, or data received) ## Application Example -See example. \ No newline at end of file +## example + +- [Source code](example) + +An example showing how to use the library APIs. \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index e55e536..e19ed28 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -28,6 +28,7 @@ class _AdHocMusicClientState extends State { static const PLAYLIST = 0; static const REQUEST = 1; static const REPLY = 2; + static const TRANSFER = 3; static const NONE = 'none'; @@ -37,9 +38,9 @@ class _AdHocMusicClientState extends State { final List> _playlist = List.empty(growable: true); final HashMap> _globalPlaylist = HashMap(); final HashMap _localPlaylist = HashMap(); + final HashMap _isTransfering = HashMap(); final Set timestamps = {}; - // bool _peerRequest = false; bool _requested = false; bool _display = false; String _selected = NONE; @@ -47,7 +48,7 @@ class _AdHocMusicClientState extends State { @override void initState() { super.initState(); - _manager.enableBle(3600); + // _manager.enableBle(3600); _manager.eventStream.listen(_processAdHocEvent); _manager.open = true; } @@ -311,6 +312,7 @@ class _AdHocMusicClientState extends State { PlatformFile file; if (_localPlaylist.containsKey(name)) { + found = true; bytes = _localPlaylist[name].bytes; } else { for (final entry in _globalPlaylist.entries) { @@ -332,6 +334,13 @@ class _AdHocMusicClientState extends State { break; } else { var message = HashMap(); + message = HashMap(); + message.putIfAbsent('type', () => TRANSFER); + message.putIfAbsent('name', () => name); + _manager.sendMessageTo(message, peer.label); + + message.clear(); + message.putIfAbsent('type', () => REPLY); message.putIfAbsent('name', () => name); message.putIfAbsent('song', () => bytes); @@ -341,7 +350,6 @@ class _AdHocMusicClientState extends State { break; case REPLY: - print(data); var name = data['name'] as String; var song = Uint8List.fromList((data['song'] as List).cast()); @@ -360,6 +368,11 @@ class _AdHocMusicClientState extends State { setState(() => _requested = false); break; + case TRANSFER: + var name = data['name'] as String; + _isTransfering.putIfAbsent(name, () => true); + break; + default: } } @@ -434,9 +447,10 @@ class _AdHocMusicClientState extends State { _manager.broadcast(message); setState(() => _requested = true); + _isTransfering.putIfAbsent(_selected, () => false); - Timer(Duration(seconds: 450), () { - if (_requested == true) { + Timer(Duration(seconds: 30), () { + if (_requested == true && _isTransfering[_selected] == false) { _manager.sendMessageTo(message, peerName); } }); diff --git a/lib/src/appframework/transfer_manager.dart b/lib/src/appframework/transfer_manager.dart index e1c911d..ebae60e 100644 --- a/lib/src/appframework/transfer_manager.dart +++ b/lib/src/appframework/transfer_manager.dart @@ -425,15 +425,24 @@ class TransferManager { break; case INTERNAL_EXCEPTION: - data = event.payload as Object; + data = event.payload as Exception; _controller.add(Event(AdHocType.onInternalException, data: data)); break; case GROUP_STATUS: + data = event.payload as int; + + _controller.add(Event(AdHocType.onGroupInfo, data: data)); break; - case GROUP_KEY_UPDATED: + case GROUP_DATA: + var payload = event.payload as List; + + device = payload.first as AdHocDevice; + data = payload.last as Object; + + _controller.add(Event(AdHocType.onGroupDataReceived, device: device, data: data)); break; default: diff --git a/lib/src/network/aodv/aodv_manager.dart b/lib/src/network/aodv/aodv_manager.dart index ed445ff..d97fcfa 100644 --- a/lib/src/network/aodv/aodv_manager.dart +++ b/lib/src/network/aodv/aodv_manager.dart @@ -22,6 +22,7 @@ import 'package:adhoc_plugin/src/network/exceptions/aodv_unknown_dest.dart'; import 'package:adhoc_plugin/src/network/exceptions/aodv_unknown_type.dart'; import 'package:adhoc_plugin/src/presentation/certificate_repository.dart'; import 'package:adhoc_plugin/src/presentation/constants.dart'; +import 'package:flutter/foundation.dart'; /// Class representing the core of the AODV protocol. It manages all the @@ -170,7 +171,7 @@ class AodvManager { } if (display) { - print(buffer.toString()); + debugPrint(buffer.toString()); } } diff --git a/lib/src/network/datalinkmanager/wrapper_ble.dart b/lib/src/network/datalinkmanager/wrapper_ble.dart index 5b4f051..44ea5cd 100644 --- a/lib/src/network/datalinkmanager/wrapper_ble.dart +++ b/lib/src/network/datalinkmanager/wrapper_ble.dart @@ -346,7 +346,6 @@ class WrapperBle extends WrapperNetwork { /// /// The [message] represents a message send through the network. void _processMsgReceived(final MessageAdHoc message) { - print(message.toString()); switch (message.header.messageType) { case CONNECT_SERVER: // Recover this own node MAC and BLE address diff --git a/lib/src/network/datalinkmanager/wrapper_wifi.dart b/lib/src/network/datalinkmanager/wrapper_wifi.dart index c535101..6ecb6a3 100644 --- a/lib/src/network/datalinkmanager/wrapper_wifi.dart +++ b/lib/src/network/datalinkmanager/wrapper_wifi.dart @@ -380,8 +380,6 @@ class WrapperWifi extends WrapperNetwork { /// /// The [message] represents a message send through the network. void _processMsgReceived(MessageAdHoc message) async { - print(message.toString()); - switch (message.header.messageType) { case CONNECT_SERVER: // Save the mapping of remote IP address with its remote MAC address diff --git a/lib/src/presentation/constants.dart b/lib/src/presentation/constants.dart index 5ec9299..441b658 100644 --- a/lib/src/presentation/constants.dart +++ b/lib/src/presentation/constants.dart @@ -22,57 +22,14 @@ const CERT_REP = 305; // Reply to certificate request const CERT_REVOCATION = 306; // Certificate revocation notification // Constants for group management -const GROUP_PROBE = 307; // Group probe -const GROUP_STATUS = 308; // Group status notification -const GROUP_LEAVE = 309; // Group left notification -const GROUP_JOIN = 3010; // Group join notification -const GROUP_KEY_UPDATED = 311; // Group key update notification - -// Probe duration -const NET_DELAY = 3000; // 3 minutes - -enum CryptoTask { - /// Isoalte initialisation - initialisation, - - /// Encryption tag - encryption, - - /// Decryption tag - decryption, - - /// Group encryption & decryption tag - group_data, -} - -enum SecureGroup { - /// Group key computation - key, - - /// Group formation initiation - init, - - /// Group formation reply - reply, - - /// List of group member's label - list, - - /// Public Diffie-Hellman share received - share, - - /// Group join notification - join, - - /// Group join request to leader - join_req, - - /// Group join reply of leader - join_rep, - - /// Group leave notification - leave, - - /// Group data - data -} +const GROUP_STATUS = 307; +const GROUP_LEAVE = 308; +const GROUP_JOIN = 309; +const GROUP_KEY = 310; +const GROUP_INIT = 311; +const GROUP_REPLY = 312; +const GROUP_LIST = 313; +const GROUP_SHARE = 314; +const GROUP_JOIN_REQ = 315; +const GROUP_JOIN_REP = 316; +const GROUP_DATA = 318; diff --git a/lib/src/presentation/crypto_engine.dart b/lib/src/presentation/crypto_engine.dart index 150b4f3..6500c9d 100644 --- a/lib/src/presentation/crypto_engine.dart +++ b/lib/src/presentation/crypto_engine.dart @@ -42,7 +42,7 @@ class CryptoEngine { /// Initializes internal parameters. Future initialize() async { _stream.listen((reply) { - if (reply.rep == CryptoTask.initialisation) { + if (reply.rep == INITIALISATION) { _sendPorts[reply.data[0] as int] = reply.data[1] as SendPort; } }); @@ -62,11 +62,7 @@ class CryptoEngine { // Create and initialize a RSA key generator final keyGen = RSAKeyGenerator() - ..init( - ParametersWithRandom(RSAKeyGeneratorParameters(BigInt.parse('65537'), bitLength, 64), - _random(), - ), - ); + ..init(ParametersWithRandom(RSAKeyGeneratorParameters(BigInt.parse('65537'), bitLength, 64), _random())); // Generate the pair of key final pair = keyGen.generateKeyPair(); @@ -87,21 +83,15 @@ class CryptoEngine { /// performed. /// /// Returns the encrypted data as a list of dynamic objects. - Future> encrypt( - Uint8List data, {RSAPublicKey? publicKey, crypto.SecretKey? sharedKey} - ) { + Future> encrypt(Uint8List data, {RSAPublicKey? publicKey, crypto.SecretKey? sharedKey}) { Completer completer = Completer>(); // Send request to encryption isolate - if (publicKey != null) { - _sendPorts[ENCRYPTION]!.send(Request(CryptoTask.encryption, data, publicKey: publicKey)); - } else { - _sendPorts[ENCRYPTION]!.send(Request(CryptoTask.group_data, data, sharedKey: sharedKey)); - } + _sendPorts[ENCRYPTION]!.send(Request(data, publicKey: publicKey, sharedKey: sharedKey)); // Listen to the reply of the encryption isolate _stream.listen((reply) { - if (reply.rep == CryptoTask.encryption) { + if (reply.rep == ENCRYPTION) { try { completer.complete(reply.data as List); } catch (exception) {} @@ -124,15 +114,11 @@ class CryptoEngine { Completer completer = Completer(); // Send request to decryption isolate - if (sharedKey == null) { - _sendPorts[DECRYPTION]!.send(Request(CryptoTask.decryption, data, privateKey: _privateKey)); - } else { - _sendPorts[DECRYPTION]!.send(Request(CryptoTask.group_data, data, sharedKey: sharedKey)); - } + _sendPorts[DECRYPTION]!.send(Request(data, privateKey: _privateKey, sharedKey: sharedKey)); // Listen to the reply of the decryption isolate _stream.listen((reply) { - if (reply.rep == CryptoTask.decryption) { + if (reply.rep == DECRYPTION) { try { completer.complete(Uint8List.fromList((reply.data as List).cast())); } catch (exception) {} @@ -209,7 +195,7 @@ class CryptoEngine { /// The [port] is used to communicate with the isolate. void processEncryption(SendPort port) { var _receivePort = ReceivePort(); - port.send(Reply(CryptoTask.initialisation, [ENCRYPTION, _receivePort.sendPort])); + port.send(Reply(INITIALISATION, [ENCRYPTION, _receivePort.sendPort])); final algorithm = crypto.Chacha20.poly1305Aead(); @@ -219,7 +205,7 @@ void processEncryption(SendPort port) { _receivePort.listen((request) async { var req = request as Request; - if (req.req == CryptoTask.encryption) { + if (req.sharedKey == null) { encryptor = OAEPEncoding(RSAEngine()) ..init(true, PublicKeyParameter(request.publicKey!)); @@ -239,7 +225,7 @@ void processEncryption(SendPort port) { reply[SECRET_KEY] = encryptedKey; reply[SECRET_DATA] = secretBox.concatenation(); - port.send(Reply(CryptoTask.encryption, reply)); + port.send(Reply(ENCRYPTION, reply)); }); } @@ -248,7 +234,7 @@ void processEncryption(SendPort port) { /// The [port] is used to communicate with the isolate. void processDecryption(SendPort port) { var _receivePort = ReceivePort(); - port.send(Reply(CryptoTask.initialisation, [DECRYPTION, _receivePort.sendPort])); + port.send(Reply(INITIALISATION, [DECRYPTION, _receivePort.sendPort])); final algorithm = crypto.Chacha20.poly1305Aead(); @@ -259,7 +245,7 @@ void processDecryption(SendPort port) { var req = request as Request; var reply = request.data as List; - if (req.req == CryptoTask.decryption) { + if (req.sharedKey == null) { decryptor = OAEPEncoding(RSAEngine()) ..init(false, PrivateKeyParameter(request.privateKey!)); @@ -285,7 +271,7 @@ void processDecryption(SendPort port) { await algorithm.decrypt(secretBox, secretKey: secretKey), ); - port.send(Reply(CryptoTask.decryption, decrypted)); + port.send(Reply(DECRYPTION, decrypted)); }); } diff --git a/lib/src/presentation/presentation_manager.dart b/lib/src/presentation/presentation_manager.dart index 828b8ba..e12822f 100644 --- a/lib/src/presentation/presentation_manager.dart +++ b/lib/src/presentation/presentation_manager.dart @@ -235,18 +235,14 @@ class PresentationManager { _groupController.eventStream.listen((event) { switch (event.type) { - case DATA_RECEIVED: // TODO: change to group data? - _controller.add(event); + case DATA_RECEIVED: + _controller.add(event..type = GROUP_DATA); break; case GROUP_STATUS: _controller.add(event); break; - case GROUP_KEY_UPDATED: - _controller.add(event); - break; - default: } }); diff --git a/lib/src/presentation/reply.dart b/lib/src/presentation/reply.dart index 1c71456..152efef 100644 --- a/lib/src/presentation/reply.dart +++ b/lib/src/presentation/reply.dart @@ -1,10 +1,8 @@ -import 'package:adhoc_plugin/src/presentation/constants.dart'; - /// Class representing the reply of the encryption/decryption isolate to a /// request of encryption/decryption. class Reply { - Object data; - CryptoTask rep; + final int rep; + final Object data; /// Creates a [Reply] object. /// diff --git a/lib/src/presentation/request.dart b/lib/src/presentation/request.dart index 31a807b..dc51adc 100644 --- a/lib/src/presentation/request.dart +++ b/lib/src/presentation/request.dart @@ -1,22 +1,18 @@ -import 'package:adhoc_plugin/src/presentation/constants.dart'; import 'package:cryptography/cryptography.dart'; import 'package:pointycastle/pointycastle.dart'; /// Class representing a request for encryption/decryption to the /// encryption/decryption isolate. class Request { - RSAPublicKey? publicKey; - RSAPrivateKey? privateKey; - SecretKey? sharedKey; - CryptoTask req; - Object data; + final RSAPublicKey? publicKey; + final RSAPrivateKey? privateKey; + final SecretKey? sharedKey; + final Object data; /// Creates a [Request] object. /// - /// The type of encryption of the [data] is defined by [req]. - /// - /// Depending on the type, the cryptographic key needs to be set: [privateKey], + /// The decryption is done with regard to the given key. [privateKey] is used /// for decryption, [publicKey] for encryption, and [sharedKey] for group /// encryption/decryption. - Request(this.req, this.data, {this.privateKey, this.publicKey, this.sharedKey}); + Request(this.data, {this.privateKey, this.publicKey, this.sharedKey}); } diff --git a/lib/src/presentation/secure_group_controller.dart b/lib/src/presentation/secure_group_controller.dart index 801f032..6331e97 100644 --- a/lib/src/presentation/secure_group_controller.dart +++ b/lib/src/presentation/secure_group_controller.dart @@ -115,8 +115,7 @@ class SecureGroupController { _memberLabel.add(_ownLabel); var message = SecureData( - SecureGroup.init.index, - [timestamp, _groupOwner, _p.toString(), _g.toString()] + GROUP_INIT, [timestamp, _groupOwner, _p.toString(), _g.toString()] ); if (members == null) { @@ -129,7 +128,7 @@ class SecureGroupController { _aodvManager.sendMessageTo(label, message); } - Timer(Duration(seconds: NET_DELAY), _timerExpired); + Timer(Duration(seconds: _expiryTime), _timerExpired); } } @@ -141,7 +140,7 @@ class SecureGroupController { } // Send a group join request - var msg = SecureData(SecureGroup.join.index, []); + var msg = SecureData(GROUP_JOIN, []); _datalinkManager.broadcastObject(msg); } @@ -155,7 +154,7 @@ class SecureGroupController { _isGroupFormed = false; // Send a leave group notification - var msg = SecureData(SecureGroup.leave.index, []); + var msg = SecureData(GROUP_LEAVE, []); _aodvManager.sendMessageTo(_groupOwner!, msg); // Reset cryptographic parameters @@ -186,7 +185,7 @@ class SecureGroupController { ); // Send encrypted message to group member - var _data = SecureData(SecureGroup.data.index, encrypted); + var _data = SecureData(GROUP_DATA, encrypted); for (final String? label in _memberLabel) { if (label != _ownLabel) { _aodvManager.sendMessageTo(label!, _data); @@ -217,7 +216,7 @@ class SecureGroupController { /// Triggers the start of the group key agreement. void _timerExpired() { - var message = SecureData(SecureGroup.list.index, [_memberLabel]); + var message = SecureData(GROUP_LIST, [_memberLabel]); for (final label in _memberLabel) { if (label != _ownLabel) { @@ -228,7 +227,7 @@ class SecureGroupController { var y = _computeDHShare(); _DHShare.putIfAbsent(_ownLabel, () => y); - message = SecureData(SecureGroup.share.index, [y.toString()]); + message = SecureData(GROUP_SHARE, [y.toString()]); for (final label in _memberLabel) { if (label != _ownLabel) { @@ -361,22 +360,19 @@ class SecureGroupController { /// Computes the group key. /// /// The way the group key is computed is defined by [type]. - void _computeGroupKey(SecureGroup type, [String? label]) async { + void _computeGroupKey(int type, [String? label]) async { var groupKeySum = BigInt.zero; var groupKeyHash = BigInt.zero; - var operation = ''; switch (type) { - case SecureGroup.init: + case GROUP_INIT: groupKeySum += _k!; for (final label in _CRTShare.keys) { groupKeySum ^= (_CRTShare[label]! % _memberShare[label]!); } - - operation = 'formation'; break; - case SecureGroup.join: + case GROUP_JOIN: groupKeyHash = await _computeGroupKeyHash(); if (label == null) { @@ -384,18 +380,14 @@ class SecureGroupController { } else { groupKeySum = groupKeyHash ^ (_CRTShare[label]! % _memberShare[label]!); } - - operation = 'join'; break; - case SecureGroup.leave: + case GROUP_LEAVE: if (_groupOwner == _ownLabel) { groupKeySum ^= _k!; } else { groupKeySum ^= (_CRTShare[_groupOwner]! % _memberShare[_groupOwner]!); } - - operation = 'leave'; break; default: @@ -416,10 +408,8 @@ class SecureGroupController { if (_isGroupFormed == false) { _isGroupFormed = true; - _controller.add(AdHocEvent(GROUP_STATUS, true)); + _controller.add(AdHocEvent(GROUP_STATUS, type)); } - - _controller.add(AdHocEvent(GROUP_KEY_UPDATED, operation)); } @@ -427,20 +417,17 @@ class SecureGroupController { /// /// The data is retrieved from the [event] payload. void _processDataReceived(AdHocEvent event) async { + var pdu = SecureData.fromJson((event.payload as List)[1] as Map); var sender = (event.payload as List)[0] as AdHocDevice; var senderLabel = sender.label!; - var pdu = SecureData.fromJson( - (event.payload as List)[1] as Map - ); - if (pdu.type > SecureGroup.values.length) { + if (pdu.type > GROUP_STATUS) { return; } - var type = SecureGroup.values[pdu.type]; var payload = pdu.payload as List; - switch (type) { - case SecureGroup.init: + switch (event.type) { + case GROUP_INIT: var timestamp = payload[0] as String; if (!_setFloodEvents.contains(timestamp)) { _setFloodEvents.add(timestamp); @@ -464,17 +451,17 @@ class SecureGroupController { _p = BigInt.parse(payload[2] as String); _g = BigInt.parse(payload[3] as String); // Reply to the group formation - var msg = SecureData(SecureGroup.reply.index, []); + var msg = SecureData(GROUP_REPLY, []); _aodvManager.sendMessageTo(senderLabel, msg); break; - case SecureGroup.reply: + case GROUP_REPLY: if (!_memberLabel.contains(senderLabel)) { _memberLabel.add(senderLabel); } break; - case SecureGroup.list: + case GROUP_LIST: // Get all the label of the group member _memberLabel.addAll((payload[0] as List).cast()); @@ -483,7 +470,7 @@ class SecureGroupController { _DHShare.putIfAbsent(_ownLabel, () => y); // Broadcast it to group member - var msg = SecureData(SecureGroup.share.index, [y.toString()]); + var msg = SecureData(GROUP_SHARE, [y.toString()]); for (final label in _memberLabel) { if (label != _ownLabel) { _aodvManager.sendMessageTo(label, msg); @@ -491,7 +478,7 @@ class SecureGroupController { } break; - case SecureGroup.share: + case GROUP_SHARE: // Store the public Diffie-Hellman share of group memeber var yj = BigInt.parse(payload[0] as String); _DHShare.putIfAbsent(senderLabel, () => yj); @@ -505,35 +492,31 @@ class SecureGroupController { var mij = _computeMemberShare(senderLabel, yj); var crtij = _computeCRTShare(senderLabel, yj, mij); - var msg = SecureData( - SecureGroup.key.index, [SecureGroup.init.index, crtij.toString()] - ); + var msg = SecureData(GROUP_KEY, [GROUP_INIT, crtij.toString()]); _aodvManager.sendMessageTo(senderLabel, msg); } } break; - case SecureGroup.key: + case GROUP_KEY: // Store the solution of the CRT system of congruence - var tag = SecureGroup.values[payload[0] as int]; var crtji = BigInt.parse(payload[1] as String); - _CRTShare.putIfAbsent(senderLabel, () => crtji); - _recovered += 1; + _CRTShare.putIfAbsent(senderLabel, () { _recovered += 1; return crtji; }); // Compute the group key if (_recovered == _memberLabel.length) { - _computeGroupKey(tag); + _computeGroupKey(GROUP_INIT); } break; - case SecureGroup.join: + case GROUP_JOIN: // Send the group join request to the group owner - var msg = SecureData(SecureGroup.join_req.index, [senderLabel]); + var msg = SecureData(GROUP_JOIN_REQ, [senderLabel]); _aodvManager.sendMessageTo(_groupOwner!, msg); break; - case SecureGroup.join_req: + case GROUP_JOIN_REQ: // Group owner responds to the group join request received var joiningMember = payload[0] as String; _memberLabel.add(joiningMember); @@ -552,14 +535,12 @@ class SecureGroupController { values.add(value.toString()); }); - var msg = SecureData( - SecureGroup.join_rep.index, [groupKeyHash.toString(), labels, values] - ); + var msg = SecureData(GROUP_JOIN_REP, [groupKeyHash.toString(), labels, values]); _aodvManager.sendMessageTo(joiningMember, msg); break; - case SecureGroup.join_rep: + case GROUP_JOIN_REP: // New member proceeds with the protocol from Step 3. if (payload.length == 3) { // Hash of group key @@ -582,31 +563,30 @@ class SecureGroupController { var mij = _computeMemberShare(label, _DHShare[label]!); var crtij = _computeCRTShare(label, _DHShare[label]!, mij); - var msg = SecureData( - SecureGroup.join_rep.index, [y.toString(), crtij.toString()] - ); + var msg = SecureData(GROUP_JOIN_REP, [y.toString(), crtij.toString()]); _aodvManager.sendMessageTo(label, msg); } } // Compute group key - _computeGroupKey(SecureGroup.join, null); + _computeGroupKey(GROUP_JOIN, null); } else { // Old member updating the group key var yj = BigInt.parse(payload[0] as String); var mij = _computeMemberShare(senderLabel, yj); var crtij = BigInt.parse(payload[1] as String); + // Store the value send by the joining member _DHShare.putIfAbsent(senderLabel, () => yj); _memberShare.putIfAbsent(senderLabel, () => mij); _CRTShare.putIfAbsent(senderLabel, () => crtij); + // Compute group key - _computeGroupKey(SecureGroup.join, senderLabel); + _computeGroupKey(GROUP_JOIN, senderLabel); } break; - case SecureGroup.leave: - // Group owner redraw new key share and broadcast it to remaining group - // member + case GROUP_LEAVE: + // Group owner redraw new key share and broadcast it to remaining group member if (_groupOwner == _ownLabel) { _memberLabel.remove(senderLabel); _k = null; @@ -619,14 +599,14 @@ class SecureGroupController { var crtij = _computeCRTShare(label, yj, mij); var msg = SecureData( - SecureGroup.leave.index, [senderLabel, crtij.toString()] + GROUP_LEAVE, [senderLabel, crtij.toString()] ); _aodvManager.sendMessageTo(label, msg); } } // Compute group key - _computeGroupKey(SecureGroup.leave); + _computeGroupKey(GROUP_LEAVE); } else { // Remove value of leaving member var leavingMember = payload[0] as String; @@ -637,18 +617,16 @@ class SecureGroupController { // Compute group key _CRTShare[_groupOwner!] = BigInt.parse(payload[1] as String); - _computeGroupKey(SecureGroup.leave); + _computeGroupKey(GROUP_LEAVE); } break; - case SecureGroup.data: + case GROUP_DATA: // Decrypt group data received - var decrypted = await _engine.decrypt( - payload, sharedKey: _groupKey! - ); + var decrypted = await _engine.decrypt(payload, sharedKey: _groupKey!); // Notify upper layers of group data received - _controller.add(AdHocEvent(DATA_RECEIVED, decrypted)); + _controller.add(AdHocEvent(DATA_RECEIVED, [sender, decrypted])); break; default: