Skip to content

Commit c77f489

Browse files
committed
Merge branch 'main' into alternative-enhancement
# By Adrian Dimitrov (1) and James Murty (1) # Via GitHub * main: Use core attributesFile from worktree (#137) Document `xxd` requirement, and make optional with OpenSSL < 3 (#138) # Conflicts: # transcrypt
2 parents 28b7581 + 3041bc7 commit c77f489

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

CHANGELOG.md

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

4343
- Remain compatible with OpenSSL versions 3 and above which changes the way
44-
explicit salt values are expressed in ciphertext (#133)
44+
explicit salt values are expressed in ciphertext, requires `xxd` command (#133)
4545
- Ensure Git index is up-to-date before checking for dirty repo, to avoid
4646
failures seen in CI systems where the repo seems dirty when it isn't. (#37)
4747
- 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: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,21 @@ realpath() {
7373

7474
_openssl_encrypt() {
7575
# In 3.x openssl disabled output of the salt prefix, which we need for determinism.
76-
# We take control over outputting the the prefix 'Salted__' with the salt
76+
# For 3.x we take control over outputting the the prefix 'Salted__' with the salt
7777
# to ensure it is always included regardless of the OpenSSL version. #133
78-
(
79-
# Always prepend encrypted ciphertext with "Salted__" prefix and binary salt value
80-
printf "Salted__" && printf "%s" "$final_salt" | xxd -r -p &&
81-
# Encrypt file to binary ciphertext
82-
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" "${pbkdf2_args[@]}" -in "$tempfile" |
83-
# Strip "Salted__" prefix and salt value if also added by OpenSSL (version < 3)
84-
LC_ALL=C sed -e "s/^\(Salted__.\{8\}\)\(.*\)/\2/"
85-
) | base64
78+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
79+
if [ "$openssl_major_version" -ge "3" ]; then
80+
# Encrypt the file to base64, ensuring it includes the prefix 'Salted__' with the salt. #133
81+
(
82+
printf "Salted__" && printf "%s" "$final_salt" | xxd -r -p &&
83+
# Encrypt file to binary ciphertext
84+
ENC_PASS=$password "$openssl_path" enc -e "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" "${pbkdf2_args[@]}" -in "$tempfile"
85+
) |
86+
base64
87+
else
88+
# Encrypt file to base64 ciphertext
89+
ENC_PASS=$password "$openssl_path" enc -e -a "-${cipher}" -md "${digest}" -pass env:ENC_PASS -S "$final_salt" "${pbkdf2_args[@]}" -in "$tempfile"
90+
fi
8691
}
8792

8893
_openssl_decrypt() {
@@ -295,7 +300,7 @@ gather_repo_metadata() {
295300

296301
# the current git repository's gitattributes file
297302
local CORE_ATTRIBUTES
298-
CORE_ATTRIBUTES=$(git config --get --local --path core.attributesFile 2>/dev/null || printf '')
303+
CORE_ATTRIBUTES=$(git config --get --local --path core.attributesFile 2>/dev/null || git config --get --path core.attributesFile 2>/dev/null || printf '')
299304
if [[ $CORE_ATTRIBUTES ]]; then
300305
readonly GIT_ATTRIBUTES=$CORE_ATTRIBUTES
301306
elif [[ $IS_BARE == 'true' ]] || [[ $IS_VCSH == 'true' ]]; then
@@ -530,6 +535,12 @@ run_safety_checks() {
530535
for cmd in {column,grep,mktemp,"${openssl_path}",sed,tee}; do
531536
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
532537
done
538+
# check for extra `xxd` dependency when running against OpenSSL version 3+
539+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
540+
if [ "$openssl_major_version" -ge "3" ]; then
541+
cmd="xxd"
542+
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
543+
fi
533544

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

0 commit comments

Comments
 (0)