Skip to content

Commit a258dc4

Browse files
authored
Document xxd requirement, and make optional with OpenSSL < 3 (#138)
1 parent 029ba93 commit a258dc4

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The format is based on [Keep a Changelog][1], and this project adheres to
3030
### Fixed
3131

3232
- Remain compatible with OpenSSL versions 3 and above which changes the way
33-
explicit salt values are expressed in ciphertext (#133)
33+
explicit salt values are expressed in ciphertext, requires `xxd` command (#133)
3434
- Ensure Git index is up-to-date before checking for dirty repo, to avoid
3535
failures seen in CI systems where the repo seems dirty when it isn't. (#37)
3636
- Respect Git `core.hooksPath` setting when installing the pre-commit hook. (#104)

INSTALL.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ The requirements to run transcrypt are minimal:
55
- Bash
66
- Git
77
- OpenSSL
8+
- `column` command (on Ubuntu/Debian install `bsdmainutils`)
9+
- `xxd` command if using OpenSSL version 3
10+
(on Ubuntu/Debian is included with `vim`)
11+
12+
...and optionally:
13+
14+
- GnuPG - for secure configuration import/export
815

916
You also need access to the _transcrypt_ script itself...
1017

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ The requirements to run transcrypt are minimal:
5656
- Git
5757
- OpenSSL
5858
- `column` command (on Ubuntu/Debian install `bsdmainutils`)
59+
- `xxd` command if using OpenSSL version 3
60+
(on Ubuntu/Debian is included with `vim`)
5961

6062
...and optionally:
6163

transcrypt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,20 @@ git_clean() {
139139
password=$(git config --get --local transcrypt.password)
140140
openssl_path=$(git config --get --local transcrypt.openssl-path)
141141
salt=$("${openssl_path}" dgst -hmac "${filename}:${password}" -sha256 "$tempfile" | tr -d '\r\n' | tail -c16)
142-
# Encrypt the file to base64, ensuring it always includes the prefix 'Salted__' with the salt. #133
143-
(
144-
# Always prepend encrypted ciphertext with "Salted__" prefix and binary salt value
145-
echo -n "Salted__" && echo -n "$salt" | xxd -r -p &&
146-
# Encrypt file to binary ciphertext
147-
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md MD5 -pass env:ENC_PASS -S "$salt" -in "$tempfile" |
148-
# Strip "Salted__" prefix and salt value if also added by OpenSSL (version < 3)
149-
LC_ALL=C sed -e "s/^\(Salted__.\{8\}\)\(.*\)/\2/"
150-
) |
151-
base64
142+
143+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
144+
if [ "$openssl_major_version" -ge "3" ]; then
145+
# Encrypt the file to base64, ensuring it includes the prefix 'Salted__' with the salt. #133
146+
(
147+
echo -n "Salted__" && echo -n "$salt" | xxd -r -p &&
148+
# Encrypt file to binary ciphertext
149+
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md MD5 -pass env:ENC_PASS -S "$salt" -in "$tempfile"
150+
) |
151+
base64
152+
else
153+
# Encrypt file to base64 ciphertext
154+
ENC_PASS=$password "$openssl_path" enc -e -a "-${cipher}" -md MD5 -pass env:ENC_PASS -S "$salt" -in "$tempfile"
155+
fi
152156
fi
153157
}
154158

@@ -305,6 +309,12 @@ run_safety_checks() {
305309
for cmd in {column,grep,mktemp,"${openssl_path}",sed,tee}; do
306310
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
307311
done
312+
# check for extra `xxd` dependency when running against OpenSSL version 3+
313+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
314+
if [ "$openssl_major_version" -ge "3" ]; then
315+
cmd="xxd"
316+
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
317+
fi
308318

309319
# ensure the repository is clean (if it has a HEAD revision) so we can force
310320
# checkout files without the destruction of uncommitted changes

0 commit comments

Comments
 (0)