Skip to content

Commit

Permalink
KRAUS-8: Refactored krausening-python to leverage Habushu 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoniec1 committed Aug 4, 2022
1 parent d29c304 commit ecd8b70
Show file tree
Hide file tree
Showing 21 changed files with 349 additions and 103 deletions.
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,56 @@
# Node artifact files
node_modules/
dist/

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/

# JetBrains IDE
.idea/
*.iml

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

*.pydevproject
.classpath
.project
.settings/

# Pyenv
.python-version

# Local Poetry configuration
poetry.toml
212 changes: 212 additions & 0 deletions krausening-python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions krausening-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "krausening"
version = "11.dev"
description = "Python implementation of Krausening"
authors = ["Your Name <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = "3.9.9"
javaproperties = "^0.8.1"
pycryptodome = "^3.14.1"

[tool.poetry.dev-dependencies]
behave = "^1.2.6"
nose = "^1.3.7"
black = "^22.6.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
15 changes: 0 additions & 15 deletions krausening-python/requirements.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,27 @@ class LogManager:
"""
Class for handling logging.
"""

__instance = None

__log_format = '%(asctime)s %(levelname)s %(name)s: %(message)s'
__date_format = '%Y/%m/%d %H:%M:%S'
__log_format = "%(asctime)s %(levelname)s %(name)s: %(message)s"
__date_format = "%Y/%m/%d %H:%M:%S"
__formatter = logging.Formatter(fmt=__log_format, datefmt=__date_format)
__handler = logging.StreamHandler()
__handler.setFormatter(__formatter)


@staticmethod
def get_instance():
if LogManager.__instance is None:
LogManager()
return LogManager.__instance


def __init__(self):
if LogManager.__instance is not None:
raise Exception('Class is a singleton')
raise Exception("Class is a singleton")
else:
LogManager.__instance = self


def get_logger(self, name: str) -> logging.Logger:
logger = logging.getLogger(name)
logger.addHandler(LogManager.__handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import os
from Crypto.Cipher import DES

class PropertyEncryptor():
'''

class PropertyEncryptor:
"""
Class to mimic the standard Jasypt string encryption/decryption.
Modified from: https://github.com/binsgit/PBEWithMD5AndDES/blob/master/python/PBEWithMD5AndDES_2.py
See https://bitbucket.org/cpointe/krausening/src/dev/ for details on encrypting values with Jasypt.
'''
"""

def encrypt(self, msg: str, password: bytes) -> bytes:
salt = os.urandom(8)
Expand All @@ -23,7 +24,6 @@ def encrypt(self, msg: str, password: bytes) -> bytes:
enc_text = crypter.encrypt(msg)
return base64.b64encode(salt + enc_text)


def decrypt(self, msg: str, password: bytes) -> str:
msg_bytes = base64.b64decode(msg)
salt = msg_bytes[:8]
Expand All @@ -32,8 +32,7 @@ def decrypt(self, msg: str, password: bytes) -> str:
crypter = DES.new(dk, DES.MODE_CBC, iv)
text = crypter.decrypt(enc_text)
# remove the padding at the end, if any
return re.sub(r'[\x01-\x08]','',text.decode('utf-8'))

return re.sub(r"[\x01-\x08]", "", text.decode("utf-8"))

def get_derived_key(self, password: bytes, salt: bytes, count: int) -> tuple:
key = password + salt
Expand Down
Loading

0 comments on commit ecd8b70

Please sign in to comment.