Skip to content
Snippets Groups Projects
Commit 7980bc68 authored by Radoslav Bodó's avatar Radoslav Bodó
Browse files

rclone crypt: refactor obscure to use cryptography package

parent 12b2f025
No related branches found
No related tags found
No related merge requests found
all: lint all: lint
install: install:
apt-get -y install awscli make rclone yamllint apt-get -y install awscli make python3-cryptography rclone yamllint
venv: venv:
apt-get -y install python3-venv apt-get -y install python3-venv
...@@ -9,6 +9,13 @@ venv: ...@@ -9,6 +9,13 @@ venv:
venv/bin/pip install -U pip venv/bin/pip install -U pip
venv/bin/pip install -r requirements.lock venv/bin/pip install -r requirements.lock
venv-refresh:
apt-get -y install python3-venv
rm -r venv
python3 -m venv venv
venv/bin/pip install -U pip
venv/bin/pip install -r requirements.txt
freeze: freeze:
@pip freeze | grep -v '^pkg[-_]resources=' @pip freeze | grep -v '^pkg[-_]resources='
......
# runtime # runtime
pycryptodome cryptography
# dev # dev
flake8 flake8
......
...@@ -10,8 +10,8 @@ from pathlib import Path ...@@ -10,8 +10,8 @@ from pathlib import Path
from subprocess import run as subrun from subprocess import run as subrun
import yaml import yaml
from Crypto.Cipher import AES from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from Crypto.Random import get_random_bytes from cryptography.hazmat.backends import default_backend
def is_sublist(needle, haystack): def is_sublist(needle, haystack):
...@@ -36,11 +36,13 @@ def rclone_obscure_password(plaintext, iv=None): ...@@ -36,11 +36,13 @@ def rclone_obscure_password(plaintext, iv=None):
# https://github.com/rclone/rclone/blob/master/fs/config/obscure/obscure.go # https://github.com/rclone/rclone/blob/master/fs/config/obscure/obscure.go
# https://github.com/maaaaz/rclonedeobscure # https://github.com/maaaaz/rclonedeobscure
# GTP translate to python cryptography
secret_key = b"\x9c\x93\x5b\x48\x73\x0a\x55\x4d\x6b\xfd\x7c\x63\xc8\x86\xa9\x2b\xd3\x90\x19\x8e\xb8\x12\x8a\xfb\xf4\xde\x16\x2b\x8b\x95\xf6\x38" secret_key = b"\x9c\x93\x5b\x48\x73\x0a\x55\x4d\x6b\xfd\x7c\x63\xc8\x86\xa9\x2b\xd3\x90\x19\x8e\xb8\x12\x8a\xfb\xf4\xde\x16\x2b\x8b\x95\xf6\x38"
if not iv: if not iv:
iv = get_random_bytes(AES.block_size) iv = os.urandom(16)
cipher = AES.new(key=secret_key, mode=AES.MODE_CTR, initial_value=iv, nonce=b'') encryptor = Cipher(algorithms.AES(secret_key), modes.CTR(iv), backend=default_backend()).encryptor()
data = iv + cipher.encrypt(plaintext.encode()) data = iv + encryptor.update(plaintext.encode()) + encryptor.finalize()
return base64.urlsafe_b64encode(data).decode().rstrip("=") return base64.urlsafe_b64encode(data).decode().rstrip("=")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment