Skip to content

Commit ca6a467

Browse files
authored
Fix compatibility with LibreSSL v3+ openssl command and MacOS Ventura (#148 #147)
Detect OpenSSL major version 3 or later which requires a compatibility work-around to include the prefix 'Salted__' and salt value when encrypting, without applying this work-around to the LibreSSL project's version of the `openssl` command which does NOT require this work-around for major version 3.
1 parent e08c359 commit ca6a467

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ The format is based on [Keep a Changelog][1], and this project adheres to
1717
normal repository users. See `--context=` / `-C` / `--list-context` arguments
1818
and documentation for this advanced feature.
1919

20+
### Fixed
21+
22+
- Compatibility fix for LibreSSL versions 3 (and above) especially for MacOS
23+
13 Ventura to more carefully apply a work-around required for OpenSSL 3+
24+
that isn't required for LibreSSL 3+ (#147 #133)
25+
2026
## [2.2.0] - 2022-07-09
2127

2228
### Added

transcrypt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ derive_context_config_group() {
154154
fi
155155
}
156156

157+
# Detect OpenSSL major version 3 or later which requires a compatibility
158+
# work-around to include the prefix 'Salted__' and salt value when encrypting.
159+
#
160+
# Note that the LibreSSL project's version of the openssl command does NOT
161+
# require this work-around for major version 3.
162+
#
163+
# See #133 #147
164+
is_salt_prefix_workaround_required() {
165+
openssl_path=$(git config --get --local transcrypt.openssl-path 2>/dev/null || printf '%s' "$openssl_path")
166+
167+
openssl_project=$($openssl_path version | cut -d' ' -f1)
168+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
169+
170+
if [ "$openssl_project" == "OpenSSL" ] && [ "$openssl_major_version" -ge "3" ]; then
171+
echo 'true'
172+
else
173+
echo ''
174+
fi
175+
}
176+
157177
# The `decryption -> encryption` process on an unchanged file must be
158178
# deterministic for everything to work transparently. To do that, the same
159179
# salt must be used each time we encrypt the same file. An HMAC has been
@@ -186,8 +206,7 @@ git_clean() {
186206
openssl_path=$(git config --get --local transcrypt.openssl-path)
187207
salt=$("${openssl_path}" dgst -hmac "${filename}:${password}" -sha256 "$tempfile" | tr -d '\r\n' | tail -c16)
188208

189-
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
190-
if [ "$openssl_major_version" -ge "3" ]; then
209+
if [ "$(is_salt_prefix_workaround_required)" == "true" ]; then
191210
# Encrypt the file to base64, ensuring it includes the prefix 'Salted__' with the salt. #133
192211
(
193212
echo -n "Salted__" && echo -n "$salt" | xxd -r -p &&
@@ -371,8 +390,7 @@ run_safety_checks() {
371390
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
372391
done
373392
# check for extra `xxd` dependency when running against OpenSSL version 3+
374-
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
375-
if [ "$openssl_major_version" -ge "3" ]; then
393+
if [ "$(is_salt_prefix_workaround_required)" == "true" ]; then
376394
cmd="xxd"
377395
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
378396
fi

0 commit comments

Comments
 (0)