From 3ecd10a200c32b151cc8a9dd95a0d7674a7ab4a1 Mon Sep 17 00:00:00 2001 From: tcsenpai Date: Thu, 8 Feb 2024 19:06:48 +0100 Subject: [PATCH] Simplified the whole procedure and updated documentation --- README.md | 28 +++++++------------------ first_run.sh | 3 --- install.sh | 15 +++++++++++++ public_key_saver.py => public_key_saver | 1 + string_decryptor | 2 +- string_encryptor | 3 ++- 6 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 first_run.sh rename public_key_saver.py => public_key_saver (78%) mode change 100644 => 100755 diff --git a/README.md b/README.md index 45211d2..bcbbe8e 100644 --- a/README.md +++ b/README.md @@ -47,27 +47,17 @@ As hardware keys (namely FIDO2 keys) can expose hmac_secret as an extension, and - Ensure you have miniconda, anaconda or anyway conda - Execute the install.sh script -- Activate the created env (hmaenv, you may have to specify the full path) +- You can either activate the environment (optionally) or just run the binaries that are configured to use the newly created environment - Enjoy -## Manual start +## Manual start (even outside conda if you have Python <= 3.10) - Install requirements.txt - Enjoy ## First run -You should be able to run - - ./first_run.sh - -Or - - bash first_run.sh - -In either case, the script simply runs the same script in bins. - -That script will then detect your hardware key with hmac_secret extension and will create a password-protected .keyfile in the bins directory. +Once enrolled with the install.sh script or by manually executing src/bin/first_run, you will have a password-protected .keyfile in the bins directory. That .keyfile will be used by the various scripts. @@ -76,10 +66,14 @@ That .keyfile will be used by the various scripts. The present repository contains various easy to use examples in the examples folder. Once you have finished setting up your environment (either with the install.sh script or with conda or manually), you can grasp a quick view of this library by executing the examples below. +The examples provided allows everybody to use this library programmatically. + ### Standalone tools You can also use the standalone tools in the root folder to encrypt / decrypt files and strings. +Please note that the tools are just an utility and may not be suited for large data inputs. + ### Documentation This is the documentation for hmacrypt.py library (you can find it in src). @@ -157,12 +151,9 @@ Parameters: - filepath (string); the path to the file to be decrypted - outpath (string); the path to the decrypted file to be saved + ### Examples -#### public_key_saver.py - -This is a simple tool that infers a RSA keypair from the hmac_secret provided and the password provided, and saves the public key in this folder. - #### string_encryption_example.py The script encodes and encrypt a string using the same inferred RSA keypair as above and then decrypts it. @@ -171,9 +162,6 @@ The script encodes and encrypt a string using the same inferred RSA keypair as a The script creates, encodes and encrypts a simple text file, then decrypts it using the same keypair as above. -#### file_encryptor.py - -This is a creativity test for you: it is a generic file encryptor that uses the above method and is not optimized (for large files for example). You can build from there. ## Known Issues diff --git a/first_run.sh b/first_run.sh deleted file mode 100644 index 056cd38..0000000 --- a/first_run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cd src/bins || exit -./first_run diff --git a/install.sh b/install.sh index 61f0660..b117314 100755 --- a/install.sh +++ b/install.sh @@ -1,2 +1,17 @@ #!/bin/bash + +echo "> Creating a new conda environment..." conda env create -f environment.yml -p ./hmacenv + +# Asking for user input +echo "> Do you want to enroll your device now? (y/N)" +read enroll +if [ "$enroll" = "Y" ] || [ "$enroll" = "y" ]; then + echo "> Enrolling your device..." + cd src/bins || exit + ./first_run +else + echo "> Skipping enrollment..." + echo "> To (re)enroll your device later, run the following command:" + echo "> cd src/bins && ./first_run" +fi diff --git a/public_key_saver.py b/public_key_saver old mode 100644 new mode 100755 similarity index 78% rename from public_key_saver.py rename to public_key_saver index ba74302..12ce8af --- a/public_key_saver.py +++ b/public_key_saver @@ -1,2 +1,3 @@ +#!./hmacenv/bin/python import src.hmacrypt as hmacrypt hmacrypt.inferKeys(hidePrivate=True, savePublic=True) \ No newline at end of file diff --git a/string_decryptor b/string_decryptor index b1f4913..c3e9f19 100755 --- a/string_decryptor +++ b/string_decryptor @@ -1,4 +1,4 @@ -#!/bin/python +#!./hmacenv/bin/python import src.hmacrypt as hmacrypt import sys diff --git a/string_encryptor b/string_encryptor index 7e2665a..578e31e 100755 --- a/string_encryptor +++ b/string_encryptor @@ -1,4 +1,5 @@ -#!/bin/python +#!./hmacenv/bin/python + import src.hmacrypt as hmacrypt import sys