diff --git a/packages/simplexmq/lib/src/crypto.dart b/packages/simplexmq/lib/src/crypto.dart index 0ce266dd06..1a18471ead 100644 --- a/packages/simplexmq/lib/src/crypto.dart +++ b/packages/simplexmq/lib/src/crypto.dart @@ -43,11 +43,7 @@ Uint8List _randomBytes(int len, Random seedSource) { final paddingByte = '#'.codeUnitAt(0); -const int _macBytes = 16; -const int _macBits = _macBytes * 8; - -Uint8List encryptAES(AESKey key, Uint8List iv, int blockSize, Uint8List data) { - final padTo = blockSize - _macBytes; +Uint8List encryptAES(AESKey key, Uint8List iv, int padTo, Uint8List data) { if (data.length >= padTo) throw ArgumentError('large message'); final padded = Uint8List(padTo); padded.setAll(0, data); @@ -60,8 +56,7 @@ Uint8List decryptAES(AESKey key, Uint8List iv, Uint8List encryptedAndTag) => GCMBlockCipher _makeGCMCipher(AESKey key, Uint8List iv, bool encrypt) => GCMBlockCipher(AESFastEngine()) - ..init( - encrypt, AEADParameters(KeyParameter(key._key), _macBits, iv, empty)); + ..init(encrypt, AEADParameters(KeyParameter(key._key), 128, iv, empty)); FortunaRandom _secureFortunaRandom() => FortunaRandom()..seed(KeyParameter(secureRandomBytes(32))); diff --git a/packages/simplexmq/lib/src/transport.dart b/packages/simplexmq/lib/src/transport.dart index ab8227e7ba..0cf35a77fd 100644 --- a/packages/simplexmq/lib/src/transport.dart +++ b/packages/simplexmq/lib/src/transport.dart @@ -126,7 +126,6 @@ class SMPTransportClient { final data = unwordsN([sig, t, empty]); final r = _sentCommands[corrId] = _Request(queueId); await _writeEncrypted(data); - print('block sent'); return r.completer.future; } @@ -143,8 +142,6 @@ class SMPTransportClient { while (true) { final block = await _readEncrypted(); final t = _parseBrokerTransmission(block); - print('block received'); - print(t); if (t.corrId == '') { yield t; } else { @@ -291,14 +288,13 @@ class SMPTransportClient { Future _readEncrypted() async { final block = await _conn.read(blockSize); - print('encrypted received'); final iv = _nextIV(_rcvKey); return decryptAES(_rcvKey.aesKey, iv, block); } Future _writeEncrypted(Uint8List data) { final iv = _nextIV(_sndKey); - final block = encryptAES(_sndKey.aesKey, iv, blockSize, data); + final block = encryptAES(_sndKey.aesKey, iv, blockSize - 16, data); return _conn.write(block); } diff --git a/packages/simplexmq_io/test/transport_test.dart b/packages/simplexmq_io/test/transport_test.dart index 3044998939..65314827a8 100644 --- a/packages/simplexmq_io/test/transport_test.dart +++ b/packages/simplexmq_io/test/transport_test.dart @@ -18,6 +18,7 @@ void main() { test('should create SMP queue and send message', () async { final conn1 = await SocketTransport.connect('localhost', 5223); final alice = await SMPTransportClient.connect(conn1, keyHash: keyHash); + final aliceMessages = alice.messageStream(); final aliceKeys = generateRSAkeyPair(); final rcvKeyBytes = encodeRsaPubKey(aliceKeys.publicKey); @@ -26,12 +27,13 @@ void main() { // final bobKeys = generateRSAkeyPair(); // final sndKeyStr = encode64(encodeRsaPubKey(bobKeys.publicKey)); - // print('we are here'); + // input stream is not processed without this listen + aliceMessages.listen((_) {}); final resp = await alice.sendSMPCommand( aliceKeys.privateKey, empty, NEW(rcvKeyBytes)); - print(resp); + expect(resp.command is IDS, true); }); - // }); - }, skip: 'requires SMP server on port 5223'); + }); + // }, skip: 'requires SMP server on port 5223'); }