From 9241f845e860d7dc13e42d8f87b9532463dfbfcb Mon Sep 17 00:00:00 2001 From: benton Date: Wed, 28 Jul 2021 16:54:55 -0500 Subject: [PATCH] password is passed to libgourou SECURELY --- flake.lock | 6 +++--- knock | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 85cf6ac..91c9d7c 100644 --- a/flake.lock +++ b/flake.lock @@ -27,11 +27,11 @@ ] }, "locked": { - "lastModified": 1627404663, - "narHash": "sha256-SnuVDohY/jnoN1oUGtYZBgDAqdVvETB6yuEuUiwzIOA=", + "lastModified": 1627508403, + "narHash": "sha256-JHOxPSJSaS+0NTUkNv6a9oI8g30pBuCDC+JwtZBaq3U=", "owner": "BentonEdmondson", "repo": "libgourou-utils", - "rev": "67e6e7ba08832c716ea156d80c9b3b26adb3cfd2", + "rev": "f16d3df200134209a1e2e530db056b3cd715425d", "type": "github" }, "original": { diff --git a/knock b/knock index 0ee3a4e..1449fff 100644 --- a/knock +++ b/knock @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import os, sys, argparse, subprocess, magic +import os, sys, argparse, subprocess, magic, shutil from pathlib import Path from getpass import getpass @@ -20,18 +20,34 @@ if not args.acsm_file.exists(): if args.epub_file.exists(): sys.exit(f'ERROR: {str(args.epub_file)} already exists.') +if args.drm_file.exists(): + sys.exit(f'ERROR: {str(args.drm_file)} must be moved or deleted.') + if not args.adobe_dir.exists(): print('This device is not registered with Adobe.') email = input("Enter your Adobe account's email address: ") password = getpass("Enter your Adobe account's password: ") print('Registering this device with Adobe...') - subprocess.run([ + result = subprocess.run([ 'adept-register', '-u', email, - '-p', password, '-O', str(args.adobe_dir) - ], check=True) + ], input=password.encode(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if result.stdout.decode().strip().startswith('Exception code : 0x1003'): + shutil.rmtree(str(args.adobe_dir)) + sys.exit('ERROR: Incorrect password') + + if result.stdout.decode().strip().startswith('Exception code : 0x500a'): + shutil.rmtree(str(args.adobe_dir)) + sys.exit('ERROR: No internet access') + + if result.returncode != 0 or not args.adobe_dir.exists() or result.stdout.decode().strip().startswith('Exception code : '): + if args.adobe_dir.exists(): + shutil.rmtree(str(args.adobe_dir)) + print('ERROR: ', file=sys.stderr) + sys.exit(result) print('Downloading the EPUB file from Adobe...') @@ -44,6 +60,9 @@ result = subprocess.run([ '-f', str(args.acsm_file) ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) +if result.stdout.decode().strip().startswith('Exception code : 0x500a'): + sys.exit('ERROR: No internet access') + if result.returncode != 0 or not args.drm_file.exists(): print('ERROR: ', file=sys.stderr) sys.exit(result)