diff --git a/.gitignore b/.gitignore index 60cc5b0..0376d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ # coverage .coverage + +.fake \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/=3.6 b/=3.6 new file mode 100644 index 0000000..d0a863a --- /dev/null +++ b/=3.6 @@ -0,0 +1,838 @@ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # Compiled python modules. +tribution folder. +/dist/ +/build/ + +# Python egg metadata, regenerated from source files by setuptools. +/*.egg-info +/*.egg +/.eggs/ + +# pipenv lockfile +/P@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ *.pyc +bash: *.pyc: command not found +ipfile.lock + +# coverage +.coverage + +.fake@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # Setuptools distribution folder. +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ /dist/ +bash: /dist/: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ /build/ +bash: /build/: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # Python egg metadata, regenerated from source files by setuptools. +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ /*.egg-info +bash: /*.egg-info: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ /*.egg +bash: /*.egg: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ /.eggs/ +bash: /.eggs/: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # pipenv lockfile +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ /Pipfile.lock +bash: /Pipfile.lock: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # coverage +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ .coverage +bash: .coverage: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ .fake +bash: .fake: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ [build-system] +bash: [build-system]: command not found +heel +build-backend = "setuptools.build_meta" + +[coverage:run] +source = . +omit = + tests/* + setup.py + didww_encrypt/__main__.py + examples/* + +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ requires = +[flake8] +exclude = .git,.idea,__pycache__,.eggs,bubash: requires: command not found +ild,dist,*.egg-info,.github +max-complexity = 10 +max-line-length = 120 +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ setuptools>=42 +bash: setuptools: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ wheel +usage: wheel [-h] {unpack,pack,convert,tags,version,help} ... + +positional arguments: + {unpack,pack,convert,tags,version,help} + commands + unpack Unpack wheel + pack Repack wheel + convert Convert egg or wininst to wheel + tags Add or replace the tags on a wheel + version Print version and exit + help Show this help + +options: + -h, --help show this help message and exit +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ build-backend = "setuptools.build_meta" +bash: build-backend: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ [coverage:run] +bash: [coverage:run]: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ source = . +bash: =: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ omit = +bash: omit: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ tests/* +bash: tests/__init__.py: Permission denied +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ setup.py +bash: setup.py: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ didww_encrypt/__main__.py +bash: didww_encrypt/__main__.py: Permission denied +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ examples/* +bash: examples/upload_encrypted_file.py: Permission denied +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ [flake8] +bash: [flake8]: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ exclude = .git,.idea,__pycache__,.eggs,build,dist,*.egg-info,.github +bash: exclude: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ max-complexity = 10 +bash: max-complexity: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ max-line-length = 120 +bash: max-line-length: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ [build-system] +bash: [build-system]: command not found +heel +build-backend = "setuptools.build_meta" + +[coverage:run] +source = . +omit = + tests/* + setup.py + didww_encrypt/__main__.py + examples/* + +[flake8] +exclude = .git,.idea,__pycache__,.eggs,build,dist,*.egg-info,.github +max-complexity = 10 +max-line-length = 120 +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ requires = +bash: requires: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ setuptools>=42 +bash: setuptools: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ wheel +usage: wheel [-h] {unpack,pack,convert,tags,version,help} ... + +positional arguments: + {unpack,pack,convert,tags,version,help} + commands + unpack Unpack wheel + pack Repack wheel + convert Convert egg or wininst to wheel + tags Add or replace the tags on a wheel + version Print version and exit + help Show this help + +options: + -h, --help show this help message and exit +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ build-backend = "setuptools.build_meta" +bash: build-backend: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ [coverage:run] +bash: [coverage:run]: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ source = . +bash: =: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ omit = +bash: omit: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ tests/* +bash: tests/__init__.py: Permission denied +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ setup.py +bash: setup.py: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ didww_encrypt/__main__.py +bash: didww_encrypt/__main__.py: Permission denied +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ examples/* +bash: examples/upload_encrypted_file.py: Permission denied +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ [flake8] +bash: [flake8]: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ exclude = .git,.idea,__pycache__,.eggs,build,dist,*.egg-info,.github +bash: exclude: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ max-complexity = 10 +bash: max-complexity: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ max-line-length = 120 +bash: max-line-length: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from .command_line import main +-m didww_encrypt")) +from: can't read /var/mail/.command_line +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ exit(main("python -m didww_encrypt")) +bash: syntax error near unexpected token `main' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ """Encrypt file for DIDWW API 3 +> +> usage: didww_encrypt [-h] [-i [INPUT]] [-o [OUTPUT]] [-f] (-m [{sandbox,production}] | -u [URI]) +> +> Encrypt file for DIDWW API 3 +> +> optional arguments: +> -h, --help show this help message and exit +> -i [INPUT], --input [INPUT] +> use input pipe when not passed +> -o [OUTPUT], --output [OUTPUT] +> use output pipe when not passed +> -f, --fingerprint return fingerprint for public keys +> -m [{sandbox,production}], --mode [{sandbox,production}] +> which DIDWW server use for public keys fetching +> -u [URI], --uri [URI] +> custom URI for public keys fetching +> """ +import sys +import argparse +import io +import urllib +from . import Encrypt, MODES + + +def main(prog="didww_encrypt", args=None): + parser = argparse.Argbash: $'Encrypt file for DIDWW API 3\n\nusage: didww_encrypt [-h] [-i [INPUT]] [-o [OUTPUT]] [-f] (-m [{sandbox,production}] | -u [URI])\n\nEncrypt file for DIDWW API 3\n\noptional arguments:\n -h, --help show this help message and exit\n -i [INPUT], --input [INPUT]\n use input pipe when not passed\n -o [OUTPUT], --output [OUTPUT]\n use output pipe when not passed\n -f, --fingerprint return fingerprint for public keys\n -m [{sandbox,production}], --mode [{sandbox,production}]\n which DIDWW server use for public keys fetching\n -u [URI], --uri [URI]\n custom URI for public keys fetching\n': command not found +umentParser(prog=prog, description=__doc__) + parser.add_argument( + "-i", + "--input", + nargs="?", + dest="input", + type=argparse.FileType("rb"), + help="use i@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +nput pipe when not passed", + ) + parser.add_argument( + "-o", + "--output", + nargs="?", + dest="output", + type=argparse.FileType("wb"), + help="use output pi@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import os +pe when not passed", + default=sys.stdout.bubash: import: command not found +ffer, + ) + parser.add_argument( + "-f", + "--fingerprint", + action="store_true", + dest="fingerprint", + help="return fingerprint for public keys", + default=@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import sys +bash: import: command not found +False, + ) + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument( + "-m", + "--mode", + nargs="?", + dest="mode", + type=str, + ch@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import argparse +bash: import: command not found +oices=MODES, + help="which DIDWW server use for public keys fetching", + ) + group.add_argument( + "-u", + "--uri", + nargs="?", + dest="uri", + type=str, + help="custom URI for public keys fetching", + @ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import io +bash: import: command not found + ) + options = parser.parse_args(args) + # if no fingerprint option and no input option and stdin connected to pipeline + # then use stdin as input + if not options.fingerprint and options.inp@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import urllib +bash: import: command not found +ut is None: + if sys.stdin.isatty(): + sys.stderr.write("input file or pipe data must be provided\n") + return 2 + else: + options.input = sys.stdin.buffer + + try: + __process_command_line(options) + @ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from . import Encrypt, MODES + return 0 + except urllib.error.HTTPError as error: + sys.stderr.write( + f"failed to fetch keys from {error.url}: {error.code} {error.msg}\n" + ) + return 3 + + fi@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +nally: + if isinstance(options.input, io.BufferedReader): + options.input.close() + if isinstance(options.output, io.BufferedWriter): + options.output.close() + + +def __p@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +rocess_command_line(options): + encryptor = Encrypt.new(mode=options.mode, uri=options.uri) + if options.fingerprint: + result = (encryptor.fingerprint + os.linesep).encode("ascii") + else@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def main(prog="didww_encrypt", args=None): +bash: syntax error near unexpected token `(' +: + result = encryptor.encrypt(options.input.read()) + options.output.write(result) +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ parser = argparse.ArgumentParser(prog=prog, description=__doc__) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ parser.add_argument( +bash: syntax error near unexpected token `newline' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "-i", +bash: -i,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "--input", +bash: --input,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ nargs="?", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ dest="input", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ type=argparse.FileType("rb"), +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ help="use input pipe when not passed", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ parser.add_argument( +bash: syntax error near unexpected token `newline' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "-o", +bash: -o,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "--output", +bash: --output,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ nargs="?", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ dest="output", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ type=argparse.FileType("wb"), +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ help="use output pipe when not passed", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ default=sys.stdout.buffer, +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ parser.add_argument( +bash: syntax error near unexpected token `newline' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "-f", +bash: -f,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "--fingerprint", +bash: --fingerprint,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ action="store_true", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ dest="fingerprint", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ help="return fingerprint for public keys", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ default=False, +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ group = parser.add_mutually_exclusive_group(required=True) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ group.add_argument( +bash: syntax error near unexpected token `newline' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "-m", +bash: -m,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "--mode", +bash: --mode,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ nargs="?", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ dest="mode", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ type=str, +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ choices=MODES, +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ help="which DIDWW server use for public keys fetching", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ group.add_argument( +bash: syntax error near unexpected token `newline' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "-u", +bash: -u,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "--uri", +bash: --uri,: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ nargs="?", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ dest="uri", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ type=str, +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ help="custom URI for public keys fetching", +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ options = parser.parse_args(args) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # if no fingerprint option and no input option and stdin connected to pipeline +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ # then use stdin as input +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if not options.fingerprint and options.input is None: +> if sys.stdin.isatty(): +bash: syntax error near unexpected token `:' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ sys.stderr.write("input file or pipe data must be provided\n") +bash: syntax error near unexpected token `"input file or pipe data must be provided\n"' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return 2 +bash: return: can only `return' from a function or sourced script +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ else: +bash: else:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ options.input = sys.stdin.buffer +bash: options.input: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ try: +bash: try:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ __process_command_line(options) +bash: syntax error near unexpected token `options' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return 0 +bash: return: can only `return' from a function or sourced script +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ except urllib.error.HTTPError as error: +bash: except: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ sys.stderr.write( +bash: syntax error near unexpected token `newline' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ f"failed to fetch keys from {error.url}: {error.code} {error.msg}\n" +bash: ffailed to fetch keys from {error.url}: {error.code} {error.msg}\n: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return 3 +bash: return: can only `return' from a function or sourced script +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ finally: +bash: finally:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if isinstance(options.input, io.BufferedReader): +bash: syntax error near unexpected token `options.input,' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ options.input.close() +> if isinstance(options.output, io.BufferedWriter): +bash: syntax error near unexpected token `options.output,' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ options.output.close() +> +> +> def __process_command_line(options): +bash: syntax error near unexpected token `def' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encryptor = Encrypt.new(mode=options.mode, uri=options.uri) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if options.fingerprint: +> result = (encryptor.fingerprint + os.linesep).encode("ascii") +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ else: +bash: else:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ result = encryptor.encrypt(options.input.read()) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ options.output.write(result) +bash: syntax error near unexpected token `result' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from didww_encrypt.fingerprint import calculate_fingerprint +from: can't read /var/mail/didww_encrypt.fingerprint +rypt +from didww_encrypt.fetching import fetch_public_keys +from . import MODE_SANDBOX, MODE_PRODUCTION, URI_SANDBOX, URI_PRODUCTION + + +class DIDWW_Encrypt: + def __init__(self, pubkey_a: str, pubkey_b@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from didww_encrypt.encryption import encrypt +: str): + self.pubkey_a = pubkey_a + sfrom: can't read /var/mail/didww_encrypt.encryption +elf.pubkey_b = pubkey_b + self.fingerprint = calculate_fingerprint(self.pubkey_a, self.pubkey_b) + + def encrypt(self, data_bytes: bytes) -> by@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from didww_encrypt.fetching import fetch_public_keys +tes: + return encrypt(data_bytes, self.pubkefrom: can't read /var/mail/didww_encrypt.fetching +y_a, self.pubkey_b) + + +def new(mode: str = None, uri: str = None) -> DIDWW_Encrypt: + if uri is not None: + pubkey_a, pubkey_b = fetch_public_keys(uri) + elif mode == MODE_SANDBOX: + pu@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from . import MODE_SANDBOX, MODE_PRODUCTION, URI_SANDBOX, URI_PRODUCTION +bkey_a, pubkey_b = fetch_public_keys(URI_SANDBOX) + elif mode == MODE_PRODUCTION: + pubkey_a, pubkey_b = fetch_public_keys(URI_PRODUCTION) + else: + raise ValueError("Valid mode, or ur@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +i must be provided") + + return DIDWW_Encrypt(pubkey_a, pubkey_b) +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ class DIDWW_Encrypt: +bash: class: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def __init__(self, pubkey_a: str, pubkey_b: str): +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ self.pubkey_a = pubkey_a +bash: self.pubkey_a: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ self.pubkey_b = pubkey_b +bash: self.pubkey_b: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ self.fingerprint = calculate_fingerprint(self.pubkey_a, self.pubkey_b) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def encrypt(self, data_bytes: bytes) -> bytes: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return encrypt(data_bytes, self.pubkey_a, self.pubkey_b) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def new(mode: str = None, uri: str = None) -> DIDWW_Encrypt: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if uri is not None: +> pubkey_a, pubkey_b = fetch_public_keys(uri) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ elif mode == MODE_SANDBOX: +bash: syntax error near unexpected token `elif' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ pubkey_a, pubkey_b = fetch_public_keys(URI_SANDBOX) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ elif mode == MODE_PRODUCTION: +bash: syntax error near unexpected token `elif' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ pubkey_a, pubkey_b = fetch_public_keys(URI_PRODUCTION) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ else: +bash: else:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ raise ValueError("Valid mode, or uri must be provided") +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return DIDWW_Encrypt(pubkey_a, pubkey_b) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Cipher import AES, PKCS1_OAEP +from: can't read /var/mail/Cryptodome.Cipher Cryptodome.Hash import SHA256 +from Cryptodome.Pub +licKey import RSA +from Cryptodome.Random import get_random_bytes +from Cryptodome.Util.Padding import pad +from Cryptodome.Signature import pss + + +def en@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Hash import SHA256 +crypt_rsa_oaep(data: bytes, pubkey: str) -> bytes:from: can't read /var/mail/Cryptodome.Hash + + key = RSA.import_key(pubkey) + cipher_rsa = PKCS1_OAEP.new( + key=key, hashAlgo=SHA256, mgfunc=lambda x, y: pss.MGF1(x, y, SHA256) + ) +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.PublicKey import RSA + return cipher_rsa.encrypt(data) + + +def encrypt(from: can't read /var/mail/Cryptodome.PublicKey +data: bytes, pubkey_a: str, pubkey_b: str) -> bytes: + """Encrypt data with public keys + + :param data: data that you want to encrypt + :param pubkey_a: first RSA public key + :param pubkey_b:@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Random import get_random_bytes + second RSA public key + :return: encrypted datfrom: can't read /var/mail/Cryptodome.Random +a + """ + aes_key = get_random_bytes(32) # AES 256 + aes_iv = get_random_bytes(AES.block_size) + cipher = AES.new(aes_key, AES.MODE_CBC, aes_@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Util.Padding import pad +ES.block_size)) + aes_key_iv = aes_key + aes_iv +from: can't read /var/mail/Cryptodome.Util.Padding + encrypted_aes_key_iv_a = encrypt_rsa_oaep(aes_key_iv, pubkey_a) + encrypted_aes_key_iv_b = encrypt_rsa_oaep(aes_key_iv, pubkey_b) + return enc@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Signature import pss +rypted_aes_key_iv_a + encrypted_aes_key_iv_b + encfrom: can't read /var/mail/Cryptodome.Signature +rypted_aes +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def encrypt_rsa_oaep(data: bytes, pubkey: str) -> bytes: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ key = RSA.import_key(pubkey) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ cipher_rsa = PKCS1_OAEP.new( +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ key=key, hashAlgo=SHA256, mgfunc=lambda x, y: pss.MGF1(x, y, SHA256) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return cipher_rsa.encrypt(data) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def encrypt(data: bytes, pubkey_a: str, pubkey_b: str) -> bytes: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ """Encrypt data with public keys +> +> :param data: data that you want to encrypt +> :param pubkey_a: first RSA public key +> :param pubkey_b: second RSA public key +> :return: encrypted data +> """ +bash: $'Encrypt data with public keys\n\n :param data: data that you want to encrypt\n :param pubkey_a: first RSA public key\n :param pubkey_b: second RSA public key\n :return: encrypted data\n ': command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ aes_key = get_random_bytes(32) # AES 256 +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ aes_iv = get_random_bytes(AES.block_size) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ cipher = AES.new(aes_key, AES.MODE_CBC, aes_iv) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encrypted_aes = cipher.encrypt(pad(data, AES.block_size)) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ aes_key_iv = aes_key + aes_iv +bash: aes_key_iv: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encrypted_aes_key_iv_a = encrypt_rsa_oaep(aes_key_iv, pubkey_a) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encrypted_aes_key_iv_b = encrypt_rsa_oaep(aes_key_iv, pubkey_b) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return encrypted_aes_key_iv_a + encrypted_aes_key_iv_b + encrypted_aes +bash: return: encrypted_aes_key_iv_a: numeric argument required +bash: return: can only `return' from a function or sourced script +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Cipher import AES, PKCS1_OAEP +from: can't read /var/mail/Cryptodome.Cipher + Cryptodome.Hash import SHA256 +from Cryptodome.PublicKey import RSA +from Cryptodome.Random import get_random_bytes +from Cryptodome.Util.Padding import pad +from Cryptodome.Signature import pss + + +def en@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Hash import SHA256 +crypt_rsa_oaep(data: bytes, pubkey: str) -> bytes:from: can't read /var/mail/Cryptodome.Hash + + key = RSA.import_key(pubkey) + cipher_rsa = PKCS1_OAEP.new( + key=key, hashAlgo=SHA256, mgfunc=lambda x, y: pss.MGF1(x, y, SHA256) + ) +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.PublicKey import RSA + return cipher_rsa.encrypt(data) + + +def encrypt(from: can't read /var/mail/Cryptodome.PublicKey +data: bytes, pubkey_a: str, pubkey_b: str) -> bytes: + """Encrypt data with public keys + + :param data: data that you want to encrypt + :param p@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Random import get_random_bytes +ubkey_a: first RSA public key + :param pubkey_b:from: can't read /var/mail/Cryptodome.Random + second RSA public key + :return: encrypted data + """ + aes_key = get_random_bytes(32) # AES 256 + aes_iv = get_random_bytes(AES.block_size@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Util.Padding import pad +) + cipher = AES.new(aes_key, AES.MODE_CBC, aes_from: can't read /var/mail/Cryptodome.Util.Padding +iv) + encrypted_aes = cipher.encrypt(pad(data, AES.block_size)) + aes_key_iv = aes_key + aes_iv + encrypted_aes_key_iv_a = encrypt_rsa_oaep(aes_key_iv, pubkey_a) + encrypted_aes_key_iv_b = encrypt_rsa_oaep(aes_key_iv, pubkey_b) + return encrypted_aes_key_iv_a + encrypted_aes_key_iv_b + enc@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Signature import pss +rypted_aes +from: can't read /var/mail/Cryptodome.Signature +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def encrypt_rsa_oaep(data: bytes, pubkey: str) -> bytes: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ key = RSA.import_key(pubkey) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ cipher_rsa = PKCS1_OAEP.new( +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ key=key, hashAlgo=SHA256, mgfunc=lambda x, y: pss.MGF1(x, y, SHA256) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return cipher_rsa.encrypt(data) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def encrypt(data: bytes, pubkey_a: str, pubkey_b: str) -> bytes: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ """Encrypt data with public keys +> +> :param data: data that you want to encrypt +> :param pubkey_a: first RSA public key +> :param pubkey_b: second RSA public key +> :return: encrypted data +> """ +bash: $'Encrypt data with public keys\n\n :param data: data that you want to encrypt\n :param pubkey_a: first RSA public key\n :param pubkey_b: second RSA public key\n :return: encrypted data\n ': command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ aes_key = get_random_bytes(32) # AES 256 +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ aes_iv = get_random_bytes(AES.block_size) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ cipher = AES.new(aes_key, AES.MODE_CBC, aes_iv) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encrypted_aes = cipher.encrypt(pad(data, AES.block_size)) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ aes_key_iv = aes_key + aes_iv +bash: aes_key_iv: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encrypted_aes_key_iv_a = encrypt_rsa_oaep(aes_key_iv, pubkey_a) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ encrypted_aes_key_iv_b = encrypt_rsa_oaep(aes_key_iv, pubkey_b) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return encrypted_aes_key_iv_a + encrypted_aes_key_iv_b + encrypted_aes +bash: return: encrypted_aes_key_iv_a: numeric argument required +bash: return: can only `return' from a function or sourced script +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from base64 import b64decode +from: import SHA1 + +SEPARATOR = ":::" + + +def pubkey_pem_tocan't read /var/mail/base64 +_bin(pubkey: str) -> bytes: + key = pubkey.replace(r"\r\n", r"\n") + if key[-1:] != "\n": + key += "\n" + pem = "".join(key.split("\n")[1:@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from Cryptodome.Hash import SHA1 +-2]) + return b64decode(pem.encode("ascii")) + + +dfrom: can't read /var/mail/Cryptodome.Hash +ef fingerprint_for(pubkey: bytes) -> str: + digest = SHA1.new(pubkey) + return digest.hexdigest() + + +def calculate_fingerprint(pubkey_a: str, pubke@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +y_b: str) -> str: + fingerprint_a = fingerprint_for(pubkey_pem_to_bin(pubkey_a)) + fingerprint_b = fingerprint_for(pubkey_pem_to_bin(pubkey_b)) + return "".join([fingerprint_a, SEPARATOR, finger@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ SEPARATOR = ":::" +bash: SEPARATOR: command not found +print_b]) +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def pubkey_pem_to_bin(pubkey: str) -> bytes: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ key = pubkey.replace(r"\r\n", r"\n") +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if key[-1:] != "\n": +> key += "\n" +> pem = "".join(key.split("\n")[1:-2]) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return b64decode(pem.encode("ascii")) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def fingerprint_for(pubkey: bytes) -> str: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ digest = SHA1.new(pubkey) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return digest.hexdigest() +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ def calculate_fingerprint(pubkey_a: str, pubkey_b: str) -> str: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ fingerprint_a = fingerprint_for(pubkey_pem_to_bin(pubkey_a)) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ fingerprint_b = fingerprint_for(pubkey_pem_to_bin(pubkey_b)) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ return "".join([fingerprint_a, SEPARATOR, fingerprint_b]) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import os +crypt import Encrypt, MODE_SANDBOX + +file_path = osbash: import: command not found +.environ.get("FILE_PATH") +if file_path is None: + sys.stderr.write("Please provide FILE_PATH\n") + exit(1) + +with open(file_path, mode="rb") as f: + data = f.read() + +enc = Encrypt.new(MODE_SANDBOX) +enc_data = enc.encrypt(data) + +api_key = os.environ.get("DIDWW_API_KEY") +if api_key is None: + sys.stderr.write("Please provide DIDWW_API_KEY\n") + exit(1) + +response = requests.post( + "https://sandbox-api.didww.com/v3/encrypted_files", + headers={"Api-Key": api_key}, + files={"encrypted_files[items][][file]": enc_data}, + data={ + "encrypted_files[encryption_fingerprint]": enc.fingerprint, + "encrypted_files[items][][description]": "python lib", + }, +) +print(f"Response: {response.status_code} #{response.json()}") +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import sys +bash: import: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ import requests +bash: import: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ from didww_encrypt import Encrypt, MODE_SANDBOX +from: can't read /var/mail/didww_encrypt +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ file_path = os.environ.get("FILE_PATH") +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if file_path is None: +> sys.stderr.write("Please provide FILE_PATH\n") +bash: syntax error near unexpected token `"Please provide FILE_PATH\n"' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ exit(1) +bash: syntax error near unexpected token `1' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ with open(file_path, mode="rb") as f: +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ data = f.read() +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ enc = Encrypt.new(MODE_SANDBOX) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ enc_data = enc.encrypt(data) +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ api_key = os.environ.get("DIDWW_API_KEY") +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ if api_key is None: +> sys.stderr.write("Please provide DIDWW_API_KEY\n") +bash: syntax error near unexpected token `"Please provide DIDWW_API_KEY\n"' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ exit(1) +bash: syntax error near unexpected token `1' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ response = requests.post( +bash: syntax error near unexpected token `(' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "https://sandbox-api.didww.com/v3/encrypted_files", +bash: https://sandbox-api.didww.com/v3/encrypted_files,: No such file or directory +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ headers={"Api-Key": api_key}, +bash: api_key},: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ files={"encrypted_files[items][][file]": enc_data}, +bash: enc_data},: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ data={ +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "encrypted_files[encryption_fingerprint]": enc.fingerprint, +bash: encrypted_files[encryption_fingerprint]:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ "encrypted_files[items][][description]": "python lib", +bash: encrypted_files[items][][description]:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ }, +bash: },: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ) +bash: syntax error near unexpected token `)' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ print(f"Response: {response.status_code} #{response.json()}") +bash: syntax error near unexpected token `f"Response: {response.status_code} #{response.json()}"' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ { +> "private_key_a": "-----BEGIN RSA PRIVATE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nrotjjCGccO0jEIl6AqBQu/axLpq6QqX12lfGaIKa+kKZvMab06iiqdyfNg==\n-----END RSA PRIVATE KEY-----\n" +> } +bash: private_key_a:: command not found +bash: private_key_b:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ { +> "data": [ +> { +> "id": "dcf2bfcb-a1d0-3b58-bbf0-3ec22a510ba8", +> "type": "public_keys", +> "attributes": { +> "key": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0eHGTVjy2s+uOfFteMoB\nT6TXa0Ra20weFoA/dQB2SsCvZ2zAOJqDuqbjFPdcRPp0TwR0rmDDHaLzV/d8EwF2\nXiX9+9lwEGivn4PCz0A49gelNthD2dFR/TxyiVVdRsiaPeGJKVZTkYO3FhCKBpXe\nL2h1t+yhIQGGYZjh/fGgahJf2PKzDapHO4p8MZK8KCUBIN5z20cYblRyt39gdHul\nsqGvERDUwYdgiEAFv5Y9yyVFUeMmeiswImLj8yHnVdwc2+5jEtWEeGzkZ0LNQCby\nnynlGwzkDXcQ98Pm00XDcvPwPk91dBvZvhA/G2n2zXp8WA+MLOkWIi015Lqy4doa\n807DYfJW+600c1P0YaOI/pgGO9dGllpFGcZBxoNN5ZMUUOjTmrXYUNYTGSZh93gd\nlGP3rlhvAlui17CUW2pLpl4CaSUDJWXQZyJH/ILZ+HMVgOMsc7eyZDLWyWWaNlJg\nEKSVNF3A8zx8oCtu+LjNPTqaiRvc3BI/ISRvb6r99v5oozCVQ/QIT24AxMLdmy01\nxOhXuDq48uoUTWssquuOnfFdF1WaK3c+AlaomX39re/rj4pvIB0ZlzuVN+LGG5WK\nYb6jCitvl8lnw9yTBZKZeU1+IFBvWgN72o4B+Y/qjZJ5N0pCK+ZSrIeLo8Pse/S6\nQIULNIKq3VuvLgliDcsOzIMCAwEAAQ==\n-----END PUBLIC KEY-----\n" +> } +> }, +> { +> "id": "f40e1176-a4ff-36e6-b2ed-c2c2d18097a3", +> "type": "public_keys", +> "attributes": { +> "key": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA9L57/eAXG5ILm1CKjDpz\nUqqEOq45OyIGXr4lYPPL090C8ulDHkqd8I4Zn1k0ZVLL1SC/mtWaE4+k5jrrQTQN\n3pFVDraUsI+ugvtyCwH0IViW0UaASkT26BQwdzN9/iGJACoL1pAOzQaEpBW9LtLB\nkgdNYHKZD++RD0gskbkhuaBM5yLx6sK2vES49GhCCog/qGkq9ogZIuXN9UMZpqgv\ntF9sBNLixGNxvsz7svxlaPFKim1eetVgWa53KTuypUJcnNWFJdft4NhmOabHfc4M\n3IyCtkrkkRmmoaYKr3ZK2fCYIRaUxyEv+YWM3ISV1ZkEEqlRtH2dybOotkxkJpOt\n3AKMk86FXrcgMmspf34wN8uFXVrtZht6XkbWWwjlG+I48V1SPM7SK9BrnDQNgoJe\nd5LhjyK4dNTJo+XM2C65iwKDc5OzQX+VS9mS5uSKzn9rDOkpjjMLqWxDdmK4X7uZ\nZMkFtDcuf0vYKuMcOQ4w1NH+FcFO1XPtKftIiLLY0SafUIqGEbt1bf0A/whLpTNE\nrc1WI1V8+DsYhqZqWDINbqNXS1/iRahiXPanmszR6npkxqdvtMsdM5FJJIz7x9a/\noPNqkDzHWZPwpZCdZO4mijx2CIcMqh8Y2NXlMI/FDlO/qUgmFz1gf9Fm41HLmFzS\n5LG5KbxmgbPJlM3Q8s6TAl0CAwEAAQ==\n-----END PUBLIC KEY-----\n" +> } +> } +bash: data:: command not found +bash: id:: command not found +bash: type:: command not found +bash: attributes:: command not found +bash: key:: command not found +bash: },: command not found +bash: id:: command not found +bash: type:: command not found +bash: attributes:: command not found +bash: key:: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ ] +bash: ]: command not found +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ } +bash: syntax error near unexpected token `}' +@ellipsis52 ➜ /workspaces/didww_encrypt_python (main) $ \ No newline at end of file diff --git a/=42 b/=42 new file mode 100644 index 0000000..e69de29 diff --git a/Encrypt b/Encrypt new file mode 100644 index 0000000..50b1d22 --- /dev/null +++ b/Encrypt @@ -0,0 +1,4 @@ +for: cannot open `for' (No such file or directory) +DIDWW: cannot open `DIDWW' (No such file or directory) +API: cannot open `API' (No such file or directory) +3: cannot open `3' (No such file or directory) diff --git a/README.md b/README.md index 09349c9..cd56f78 100644 --- a/README.md +++ b/README.md @@ -1,132 +1,2 @@ -# DIDWW Encrypt Python 3 SDK - -[![github_actions](https://github.com/didww/didww_encrypt_python/actions/workflows/tests.yml/badge.svg)](https://github.com/didww/didww_encrypt_python/actions) -[![codecov](https://codecov.io/gh/didww/didww_encrypt_python/branch/main/graph/badge.svg)](https://codecov.io/gh/didww/didww_encrypt_python) - -This is Python 3 module and CLI to encrypt file for DIDWW API 3. - -File encrypted with mode `sandbox` could be uploaded to `POST https://sandbox-api.didww.com/v3/encrypted_files`. - -File encrypted with mode `production` could be uploaded to `POST https://api.didww.com/v3/encrypted_files`. - -see [DIDWW Documentation](https://doc.didww.com) for details. - -## Requirements - -Python `>=3.6` - -## Dependencies - -[PyCryptodomex](https://pypi.org/project/pycryptodomex/) - -## Install - -```shell -pip install didww_encrypt -``` - -## Usage - -### Inside python -```python -from didww_encrypt import Encrypt, MODE_PRODUCTION - - -with open("doc.pdf", mode="rb") as f: - data = f.read() - -enc = Encrypt.new(MODE_PRODUCTION) -enc_data = enc.encrypt(data) -enc_filename = "doc.pdf.enc" -with open(enc_filename, mode="wb") as f: - f.write(enc_data) - -print(f"encrypted file saved: {enc_filename}") -print(f"fingerprint: {enc.fingerprint}") -``` - -### Shell - -``` -usage: didww_encrypt [-h] [-i [INPUT]] [-o [OUTPUT]] [-f] (-m [{sandbox,production}] | -u [URI]) - -Encrypt file for DIDWW API 3 - -optional arguments: - -h, --help show this help message and exit - -i [INPUT], --input [INPUT] - use input pipe when not passed - -o [OUTPUT], --output [OUTPUT] - use output pipe when not passed - -f, --fingerprint return fingerprint for public keys - -m [{sandbox,production}], --mode [{sandbox,production}] - which DIDWW server use for public keys fetching - -u [URI], --uri [URI] - custom URI for public keys fetching -``` - -You can pass input and output files as params -```shell -$ didww_encrypt -i ./doc.pdf -o ./doc.pdf.enc -m sandbox -``` - -Or using pipe -```shell -$ cat ./doc.pdf | didww_encrypt -m production > ./doc.pdf.enc -``` - -Also script could be run via `python -m` -```shell -$ python -m didww_encrypt -i ./doc.pdf -o ./doc.pdf.enc -m production -$ cat ./doc.pdf | python -m didww_encrypt -m sandbox > ./doc.pdf.enc -``` - -To print fingerprint use `-f` option instead of `-i` -```shell -$ didww_encrypt -f -m sandbox -c74684d7863639169c21c4d04747f8d6fa05cfe3:::7c56fd5d2e1f2ada18765d936e74712037aea7eb -``` - -Or you can save it to a file -```shell -$ didww_encrypt -f -m sandbox -o fingerprint.txt -``` - -**Keep in mind** that shell script returns fingerprint with newline which should be omitted when send it to `/v3/encrypted_files`. - -## Additional information - -both shell script and module function `Encrypt.new` respects `http_proxy` env variable when fetching public keys. - -```shell -http_proxy="http://myproxy.example.com:1234" didww_encrypt -m sandbox -``` - -## Development - -### Install dependencies - -```shell -pip install -r requirements.txt -pip install -r tests/requirements.txt -``` - -### Run tests -```shell -python -m unittest -v -``` - -### Run tests with coverage -```shell -coverage run -m unittest -v -``` - -### Lint with flake8 -```shell -flake8 . --count --show-source --statistics -``` - -### Fix code format with Black -```shell -black . -``` +# didww_encrypt_python +File encryption for DIDWW API 3 diff --git a/doc.pdf.enc b/doc.pdf.enc new file mode 100644 index 0000000..65e60ba Binary files /dev/null and b/doc.pdf.enc differ diff --git a/fingerprint.txt b/fingerprint.txt new file mode 100644 index 0000000..498830a --- /dev/null +++ b/fingerprint.txt @@ -0,0 +1 @@ +66b91934f62a92153c2e86d87e6599703aa82051:::9c82ff6d35e15691c8d8f5a9d297ef5f5b4c1ba5