From e321220a6206db69da563d8fea7e51cf9d0d71d9 Mon Sep 17 00:00:00 2001
From: Shay Nehmad <shay.nehmad@guardicore.com>
Date: Tue, 28 Apr 2020 16:42:24 +0300
Subject: [PATCH 1/2] Python 3 hashing requires bytes, not string

Also moved to standard lib implementation with hashlib instead of Crypto, and added UT to the problematic function
---
 .../monkey_island/cc/environment/__init__.py  | 11 ++++----
 .../monkey_island/cc/environment/test_aws.py  | 26 +++++++++++++++++++
 2 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 monkey/monkey_island/cc/environment/test_aws.py

diff --git a/monkey/monkey_island/cc/environment/__init__.py b/monkey/monkey_island/cc/environment/__init__.py
index ec7c7a0f4..195778e16 100644
--- a/monkey/monkey_island/cc/environment/__init__.py
+++ b/monkey/monkey_island/cc/environment/__init__.py
@@ -1,7 +1,7 @@
 from abc import ABCMeta, abstractmethod
 from datetime import timedelta
 import os
-from Crypto.Hash import SHA3_512
+import hashlib
 
 __author__ = 'itay.mizeretz'
 
@@ -45,10 +45,11 @@ class Environment(object, metaclass=ABCMeta):
     def get_auth_expiration_time(self):
         return self._AUTH_EXPIRATION_TIME
 
-    def hash_secret(self, secret):
-        h = SHA3_512.new()
-        h.update(secret)
-        return h.hexdigest()
+    @staticmethod
+    def hash_secret(secret):
+        hash_obj = hashlib.sha3_512()
+        hash_obj.update(secret.encode('utf-8'))
+        return hash_obj.hexdigest()
 
     def get_deployment(self):
         return self._get_from_config('deployment', 'unknown')
diff --git a/monkey/monkey_island/cc/environment/test_aws.py b/monkey/monkey_island/cc/environment/test_aws.py
new file mode 100644
index 000000000..222e97530
--- /dev/null
+++ b/monkey/monkey_island/cc/environment/test_aws.py
@@ -0,0 +1,26 @@
+from monkey_island.cc.auth import User
+from monkey_island.cc.testing.IslandTestCase import IslandTestCase
+from monkey_island.cc.environment.aws import AwsEnvironment
+
+import hashlib
+
+
+class TestAwsEnvironment(IslandTestCase):
+    def test_get_auth_users(self):
+        env = AwsEnvironment()
+        # This is "injecting" the instance id to the env. This is the UTs aren't always executed on the same AWS machine
+        # (might not be an AWS machine at all). Perhaps it would have been more elegant to create a Mock, but not worth it for
+        # this small test.
+        env._instance_id = "i-666"
+        hash_obj = hashlib.sha3_512()
+        hash_obj.update(b"i-666")
+        auth_users = env.get_auth_users()
+        assert isinstance(auth_users, list)
+        assert len(auth_users) == 1
+        auth_user = auth_users[0]
+        assert isinstance(auth_user, User)
+        assert auth_user.id == 1
+        assert auth_user.username == "monkey"
+        assert auth_user.secret == hash_obj.hexdigest()
+
+

From d03ee3d245e3e09a9da05b3f9844e8548505b6a6 Mon Sep 17 00:00:00 2001
From: Shay Nehmad <shay.nehmad@guardicore.com>
Date: Tue, 28 Apr 2020 16:54:19 +0300
Subject: [PATCH 2/2] Update patch version

Bugfix change to master == new patch :congratulations:
---
 monkey/common/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/monkey/common/version.py b/monkey/common/version.py
index 9d60e636c..fd706d909 100644
--- a/monkey/common/version.py
+++ b/monkey/common/version.py
@@ -4,7 +4,7 @@ from pathlib import Path
 
 MAJOR = "1"
 MINOR = "8"
-PATCH = "0"
+PATCH = "1"
 build_file_path = Path(__file__).parent.joinpath("BUILD")
 with open(build_file_path, "r") as build_file:
     BUILD = build_file.read()