From 03608960c0a6650349dd1e1c2631c97a62be22ca Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 23 Jun 2020 16:48:04 -0500 Subject: [PATCH] fix bug in test_lan_learn and handle errors better in encryption plugin --- static-data/default-plugins/encrypt/main.py | 12 +++++++++++- tests/test_lan_learn.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/static-data/default-plugins/encrypt/main.py b/static-data/default-plugins/encrypt/main.py index 8fd53fe2..feed4b03 100755 --- a/static-data/default-plugins/encrypt/main.py +++ b/static-data/default-plugins/encrypt/main.py @@ -22,12 +22,17 @@ import logger, config, threading, time, datetime, sys import ujson as json +from nacl.exceptions import TypeError as NaclTypeError from onionrutils import stringvalidators, bytesconverter from onionrcrypto import encryption, keypair, signing, getourkeypair import onionrexceptions, onionrusers + import locale locale.setlocale(locale.LC_ALL, '') + +import binascii + plugin_name = 'encrypt' class PlainEncryption: @@ -110,7 +115,12 @@ class PlainEncryption: return def on_decrypt_cmd(api, data=None): - PlainEncryption(api).decrypt() + try: + PlainEncryption(api).decrypt() + except binascii.Error: + logger.error("Invalid ciphertext padding", terminal=True) + except NaclTypeError: + logger.error("Ciphertext too short.", terminal=True) def on_encrypt_cmd(api, data=None): PlainEncryption(api).encrypt() diff --git a/tests/test_lan_learn.py b/tests/test_lan_learn.py index 25816ef7..ed548ecc 100644 --- a/tests/test_lan_learn.py +++ b/tests/test_lan_learn.py @@ -40,7 +40,7 @@ class TestLanLearn(unittest.TestCase): sock.close() test_list = [test_ip] - Thread(target=learn_services, args=[test_list], daemon=True).start() + Thread(target=learn_services, daemon=True).start() bettersleep.better_sleep(3) multicast() self.assertIn(test_ip, test_list)