Skip to content

Commit bea1847

Browse files
committed
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. # Conflicts: # CHANGELOG.md # transcrypt
1 parent ac99a93 commit bea1847

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ The format is based on [Keep a Changelog][1], and this project adheres to
88
[1]: https://keepachangelog.com/en/1.0.0/
99
[2]: https://semver.org/spec/v2.0.0.html
1010

11+
## [Unreleased]
12+
13+
### Fixed
14+
15+
- Compatibility fix for LibreSSL versions 3 (and above) especially for MacOS
16+
13 Ventura to more carefully apply a work-around required for OpenSSL 3+
17+
that isn't required for LibreSSL 3+ (#147 #133)
18+
1119
## [2.2.0] - 2022-07-09
1220

1321
### Added

transcrypt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ die() {
112112
exit "$st"
113113
}
114114

115+
# Detect OpenSSL major version 3 or later which requires a compatibility
116+
# work-around to include the prefix 'Salted__' and salt value when encrypting.
117+
#
118+
# Note that the LibreSSL project's version of the openssl command does NOT
119+
# require this work-around for major version 3.
120+
#
121+
# See #133 #147
122+
is_salt_prefix_workaround_required() {
123+
openssl_path=$(git config --get --local transcrypt.openssl-path 2>/dev/null || printf '%s' "$openssl_path")
124+
125+
openssl_project=$($openssl_path version | cut -d' ' -f1)
126+
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
127+
128+
if [ "$openssl_project" == "OpenSSL" ] && [ "$openssl_major_version" -ge "3" ]; then
129+
echo 'true'
130+
else
131+
echo ''
132+
fi
133+
}
134+
115135
# The `decryption -> encryption` process on an unchanged file must be
116136
# deterministic for everything to work transparently. To do that, the same
117137
# salt must be used each time we encrypt the same file. An HMAC has been
@@ -140,8 +160,7 @@ git_clean() {
140160
openssl_path=$(git config --get --local transcrypt.openssl-path)
141161
salt=$("${openssl_path}" dgst -hmac "${filename}:${password}" -sha256 "$tempfile" | tr -d '\r\n' | tail -c16)
142162

143-
openssl_major_version=$($openssl_path version | cut -d' ' -f2 | cut -d'.' -f1)
144-
if [ "$openssl_major_version" -ge "3" ]; then
163+
if [ "$(is_salt_prefix_workaround_required)" == "true" ]; then
145164
# Encrypt the file to base64, ensuring it includes the prefix 'Salted__' with the salt. #133
146165
(
147166
echo -n "Salted__" && echo -n "$salt" | xxd -r -p &&
@@ -310,8 +329,7 @@ run_safety_checks() {
310329
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
311330
done
312331
# 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
332+
if [ "$(is_salt_prefix_workaround_required)" == "true" ]; then
315333
cmd="xxd"
316334
command -v "$cmd" >/dev/null || die 'required command "%s" was not found' "$cmd"
317335
fi

0 commit comments

Comments
 (0)