Skip to content

Commit 98636a5

Browse files
authored
Merge pull request #630 from guardicore/hotfix/fix-monkey-password-encoding
Python 3 hashing requires bytes, not string
2 parents 9b7d797 + d03ee3d commit 98636a5

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

monkey/common/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
MAJOR = "1"
66
MINOR = "8"
7-
PATCH = "0"
7+
PATCH = "1"
88
build_file_path = Path(__file__).parent.joinpath("BUILD")
99
with open(build_file_path, "r") as build_file:
1010
BUILD = build_file.read()

monkey/monkey_island/cc/environment/__init__.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABCMeta, abstractmethod
22
from datetime import timedelta
33
import os
4-
from Crypto.Hash import SHA3_512
4+
import hashlib
55

66
__author__ = 'itay.mizeretz'
77

@@ -45,10 +45,11 @@ def is_debug(self):
4545
def get_auth_expiration_time(self):
4646
return self._AUTH_EXPIRATION_TIME
4747

48-
def hash_secret(self, secret):
49-
h = SHA3_512.new()
50-
h.update(secret)
51-
return h.hexdigest()
48+
@staticmethod
49+
def hash_secret(secret):
50+
hash_obj = hashlib.sha3_512()
51+
hash_obj.update(secret.encode('utf-8'))
52+
return hash_obj.hexdigest()
5253

5354
def get_deployment(self):
5455
return self._get_from_config('deployment', 'unknown')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from monkey_island.cc.auth import User
2+
from monkey_island.cc.testing.IslandTestCase import IslandTestCase
3+
from monkey_island.cc.environment.aws import AwsEnvironment
4+
5+
import hashlib
6+
7+
8+
class TestAwsEnvironment(IslandTestCase):
9+
def test_get_auth_users(self):
10+
env = AwsEnvironment()
11+
# This is "injecting" the instance id to the env. This is the UTs aren't always executed on the same AWS machine
12+
# (might not be an AWS machine at all). Perhaps it would have been more elegant to create a Mock, but not worth it for
13+
# this small test.
14+
env._instance_id = "i-666"
15+
hash_obj = hashlib.sha3_512()
16+
hash_obj.update(b"i-666")
17+
auth_users = env.get_auth_users()
18+
assert isinstance(auth_users, list)
19+
assert len(auth_users) == 1
20+
auth_user = auth_users[0]
21+
assert isinstance(auth_user, User)
22+
assert auth_user.id == 1
23+
assert auth_user.username == "monkey"
24+
assert auth_user.secret == hash_obj.hexdigest()
25+
26+

0 commit comments

Comments
 (0)