Skip to content

Commit

Permalink
Rename en/decrypt.sh to en/decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
david-04 committed May 4, 2024
1 parent 05b37ea commit 92b1278
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
!/.gitignore
!/CHANGELOG.md
!/decrypt.bat
!/decrypt.sh
!/decrypt
!/encrypt.bat
!/encrypt.sh
!/encrypt
!/LICENSE
!/README.md
4 changes: 2 additions & 2 deletions .gpg2f/scripts/gpg2f.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ function gpg2f_main() {
function gpg2f_display_syntax_help() {
echo "gpg2f - Symmetric multifactor-encryption with GnuPG"
echo ""
echo "Syntax: encrypt.sh [--debug] [file]"
echo " or: decrypt.sh [--debug] [file]"
echo "Syntax: encrypt [--debug] [file]"
echo " or: decrypt [--debug] [file]"
echo ""
echo "Encrypt stdin to the given [file] or decrypt the given [file] to stdout."
echo "If [file] is not given, encrypt to stdout or decrypt from stdin."
Expand Down
11 changes: 6 additions & 5 deletions .gpg2f/scripts/pass-gpg-shim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function gpg2f_passwordstore_shim_list_secret_keys_with_colons_and_fingerprint()
#-----------------------------------------------------------------------------------------------------------------------

function gpg2f_passwordstore_shim_encrypt() {
gpg2f_passwordstore_shim_encrypt_or_decrypt "encrypt.sh" "$1"
gpg2f_passwordstore_shim_encrypt_or_decrypt "encrypt" "$1"
return $?
}

Expand All @@ -136,14 +136,14 @@ function gpg2f_passwordstore_shim_encrypt() {
#-----------------------------------------------------------------------------------------------------------------------

function gpg2f_passwordstore_shim_decrypt() {
gpg2f_passwordstore_shim_encrypt_or_decrypt "decrypt.sh" "$1"
gpg2f_passwordstore_shim_encrypt_or_decrypt "decrypt" "$1"
return $?
}

#-----------------------------------------------------------------------------------------------------------------------
# Encrypt or decrypt content
#-----------------------------------------------------------------------------------------------------------------------
# $1 ... name of the script ("encrypt.sh" or "decrypt.sh")
# $1 ... name of the script ("encrypt" or "decrypt")
# $2 ... input file (decrypt stdin if not set or an empty string)
#-----------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -184,9 +184,10 @@ function gpg2f_passwordstore_shim_get_absolute_path() {
}

#-----------------------------------------------------------------------------------------------------------------------
# Locate the encrypt.sh script in the closest parent directory of the given file (or the current directory if not set)
# Locate the encrypt or decrypt script in the closest parent directory of the given file (or the current directory if
# not set)
#-----------------------------------------------------------------------------------------------------------------------
# $1 ... name of the script ("encrypt.sh" or "decrypt.sh")
# $1 ... name of the script ("encrypt" or "decrypt")
# $2 ... optional: absolute path of the file to encrypt or decrypt
#-----------------------------------------------------------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.0.3](https://github.com/david-04/gpg2f/releases/tag/v1.0.3) (2024-05-04)

- Rename `encrypt.sh` and `decrypt.sh` to `encrypt` and `decrypt`

## [1.0.2](https://github.com/david-04/gpg2f/releases/tag/v1.0.2) (2024-04-25)

- Automatically include the `.env` file (if it exists in the root directory)
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ git clone --depth 1 https://github.com/david-04/gpg2f.git
Upgrading to a newer release involves either downloading and extracting it over the previous installation or running `git pull` in the cloned repository. After extracting/cloning/updating the application, make the following scripts executable:

```shell
chmod +x decrypt.sh encrypt.sh `find .gpg2f -name '*.sh'`
chmod +x decrypt encrypt `find .gpg2f -name '*.sh'`
```

To verify that all required programs are installed and working, run the command below. When prompted for a password, enter `x` (a single lowercase letter).

```shell
echo "Hello world!" | ./encrypt.sh
echo "Hello world!" | ./encrypt
```

The command might abort with an error like this:
Expand All @@ -61,7 +61,7 @@ gpg2: command not found
By default, `gpg2f` uses the command `gpg2` to run the GNU Privacy Guard. If it's installed under a different name (e.g. `gpg`), open the `settings.sh` and update the `GPG2F_GPG_CMD` variable on top of the file. Then try to encrypt again:

```shell
echo "Hello world!" | ./encrypt.sh
echo "Hello world!" | ./encrypt
```

If everything works, the encrypted content is printed to the terminal:
Expand All @@ -79,10 +79,10 @@ EsLm++P9gVghMSghGXDLsC7DI4M7fqjF5Y1wPdlLSTHaov0=
Now verify, that encrypted content can also be decrypted again:

```shell
echo "Hello world!" | ./encrypt.sh | ./decrypt.sh
echo "Hello world!" | ./encrypt | ./decrypt
```

This should print the original message `Helow world!`
This should print the original message `Hello world!`

## Configuration

Expand Down Expand Up @@ -153,7 +153,7 @@ When encrypting (second variable), `gpg2f` will decrypt the static key and perfo
Try to encrypt a message. This might prompt for the passphrase of `.keys/static-key.gpg` (unless it's already cached) and should then require a touch of the YubiKey:

```shell
echo "Hello world!" | ./encrypt.sh test.gpg
echo "Hello world!" | ./encrypt test.gpg
```

Verify that the content was encrypted correctly:
Expand All @@ -177,7 +177,7 @@ jwkp+RaJEno6EQ9QVMAsTnG9frSVQn/YijjjHGsi4dGr13M=
Unplug the YubiKey and verify that the locally stored backup of the HMAC secret key can be used to decrypt the file. This might again prompt for the passphrases of `.keys/static-key.gpg` and `.keys/hmac-secret-key.gpg`.

```shell
./decrypt.sh test.gpg
./decrypt test.gpg
```

This command should should produce the original `Hello world!` message.
Expand All @@ -195,7 +195,7 @@ export GPG2F_DERIVE_ENCRYPTION_KEY_CMD=("${GPG2F_DERIVE_DECRYPTION_KEY_CMD[@]}")
Verify that it works by en- and decrypting a message:

```shell
echo "Hello world!" | ./encrypt.sh | ./decrypt.sh
echo "Hello world!" | ./encrypt | ./decrypt
```

This might prompt for the passphrase of `.keys/static-key.gpg`. Both operations should also require a touch of the YubiKey. That is, the YubiKey needs to be touched twice to complete the full cycle.
Expand All @@ -218,32 +218,32 @@ The duration is configured in seconds. For example, set it to `600` to cache pas

## Usage

Use `encrypt.sh` (or `encrypt.bat` on Windows) to encrypt content. The plain text is always read from `stdin`. The encrypted content can be written to either `stdout` or a file:
Use `encrypt` (or `encrypt.bat` on Windows) to encrypt content. The plain text is always read from `stdin`. The encrypted content can be written to either `stdout` or a file:

```shell
# Encrypt stdin to stdout
echo "Hello world!" | ./encrypt.sh
echo "Hello world!" | ./encrypt

# Encrypt stdin to a file
echo "Hello world!" | ./encrypt.sh my-file.gpg
echo "Hello world!" | ./encrypt my-file.gpg
```

Use `decrypt.sh` (or `decrypt.bat` on Windows) to decrypt content. The encrypted content can be read from `stdin` or a file and the plain text is always written to `stdout`:
Use `decrypt` (or `decrypt.bat` on Windows) to decrypt content. The encrypted content can be read from `stdin` or a file and the plain text is always written to `stdout`:

```shell
# Decrypt a file to stdou
./decrypt.sh my-file.gpg
./decrypt my-file.gpg

# Decrypt stdin to stdou
cat ./my-file.gpg | ./decrypt.sh
cat ./my-file.gpg | ./decrypt
```

Both commands need to be run from the application's root directory. They can't be invoked from a different directory.

The commands can also be called with the `--debug` option. This causes `gpg2f` to print diagnostic information for trouble-shooting:

```shell
echo "Hello world!" | ./encrypt.sh --debug | ./decrypt.sh --debug
echo "Hello world!" | ./encrypt --debug | ./decrypt --debug
```

Please note that this will not only display derived keys (that are specific to the seed) but also the decrypted static key. It is recommended to create and use temporary keys when trouble-shooting configuration issues.
Expand All @@ -262,9 +262,9 @@ gpg2f
+-- [...] <= custom directories for encrypted files
|
+-- decrypt.bat <= commands to encrypt or decrypt
+-- decrypt.sh
+-- decrypt
+-- encrypt.bat
+-- encrypt.sh
+-- encrypt
|
+-- settings.sh <= configure keys and factors to use
Expand Down
6 changes: 3 additions & 3 deletions decrypt.sh → decrypt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC2317

[[ "$1" == "decrypt.sh" ]] && shift
[[ "$1" == "decrypt" ]] && shift

if [[ ! -f "decrypt.sh" ]]; then
echo "ERROR: decrypt.sh can only be invoked in its own directory (current working directory: $(pwd))" >&2
if [[ ! -f "./decrypt" ]]; then
echo "ERROR: decrypt can only be invoked in its own directory (current working directory: $(pwd))" >&2
return 1 2>/dev/null || exit 1
elif [[ ! -f ".gpg2f/scripts/gpg2f.sh" ]]; then
echo "ERROR: $(pwd)/.gpg2f/scripts/gpg2f.sh does not exist" >&2
Expand Down
2 changes: 1 addition & 1 deletion decrypt.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
set GPG2F_DECRYPT_DIRECTORY=%~dp0
env %GPG2F_DECRYPT_DIRECTORY:\=/%decrypt.sh %*
env %GPG2F_DECRYPT_DIRECTORY:\=/%decrypt %*
6 changes: 3 additions & 3 deletions encrypt.sh → encrypt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash
# shellcheck disable=SC2317

[[ "$1" == "encrypt.sh" ]] && shift
[[ "$1" == "encrypt" ]] && shift

if [[ ! -f "encrypt.sh" ]]; then
echo "ERROR: encrypt.sh can only be invoked in its own directory (current working directory: $(pwd))" >&2
if [[ ! -f "./encrypt" ]]; then
echo "ERROR: encrypt can only be invoked in its own directory (current working directory: $(pwd))" >&2
return 1 2>/dev/null || exit 1
elif [[ ! -f ".gpg2f/scripts/gpg2f.sh" ]]; then
echo "ERROR: $(pwd)/.gpg2f/scripts/gpg2f.sh does not exist" >&2
Expand Down
2 changes: 1 addition & 1 deletion encrypt.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
set GPG2F_ENCRYPT_DIRECTORY=%~dp0
env %GPG2F_ENCRYPT_DIRECTORY:\=/%encrypt.sh %*
env %GPG2F_ENCRYPT_DIRECTORY:\=/%encrypt %*

0 comments on commit 92b1278

Please sign in to comment.