Capture UnicodeDecodeError if decrypting with wrong key
Change-Id: If4904c0eeac396eee7082d19784e440991131297
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/osm_common/dbbase.py b/osm_common/dbbase.py
index d199dde..09eddbc 100644
--- a/osm_common/dbbase.py
+++ b/osm_common/dbbase.py
@@ -236,7 +236,11 @@
encrypted_msg = b64decode(value)
cipher = AES.new(secret_key)
decrypted_msg = cipher.decrypt(encrypted_msg)
- unpadded_private_msg = decrypted_msg.decode().rstrip('\0')
+ try:
+ unpadded_private_msg = decrypted_msg.decode().rstrip('\0')
+ except UnicodeDecodeError:
+ raise DbException("Cannot decrypt information. Are you using same COMMONKEY in all OSM components?",
+ http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
return unpadded_private_msg