Skip to content

Commit d5b4bab

Browse files
committed
Revert ill-judged attempt to auto-fix faulty encrypted files with doubled "Salted" prefix #158
The automatic fix for mistakenly double-salted encrypted files seems to be causing file- and system-dependent failures for people, and is almost certainly not worth this hassle, or the performance overhead, since I haven't heard of anyone having a double-salted file to recover. Reverting this now as a bad idea, to return the `smudge` operation back to its original implementation which is massively simpler and hopefully no longer sometimes broken. This reverts commits: - f709d47. - b380f2c.
1 parent f09d825 commit d5b4bab

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The requirements to run transcrypt are minimal:
5555
- Bash
5656
- Git
5757
- OpenSSL
58-
- `column` and `hexdump` commands (on Ubuntu/Debian install `bsdmainutils`)
58+
- `column` command (on Ubuntu/Debian install `bsdmainutils`)
5959
- `xxd` command if using OpenSSL version 3
6060
(on Ubuntu/Debian is included with `vim`)
6161

transcrypt

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -175,40 +175,13 @@ git_clean() {
175175
fi
176176
}
177177

178-
# shellcheck disable=SC2005,SC2155
179178
git_smudge() {
180179
tempfile=$(mktemp 2>/dev/null || mktemp -t tmp)
181180
trap 'rm -f "$tempfile"' EXIT
182181
cipher=$(git config --get --local transcrypt.cipher)
183182
password=$(git config --get --local transcrypt.password)
184183
openssl_path=$(git config --get --local transcrypt.openssl-path)
185-
186-
# Write stdin to $tempfile, while skimming the first bytes at the same time
187-
local firstbytes=$(tee "$tempfile" | head -c8 | LC_ALL=C tr -d '\0')
188-
# If the first bytes are "Salted", then the file is encrypted
189-
if [[ $firstbytes == "U2FsdGVk" ]]; then
190-
# Fix for file mistakenly encrypted with double "Salted" prefixes due to #147
191-
# that causes garbage characters at top of decrypted files.
192-
#
193-
# Check file header, which we already know starts with "Salted", to see if
194-
# it has exactly the same "Salted__XYZ" prefix mistakenly repeated twice.
195-
# Base64 decode gives raw bytes, hexdump gives bytes as ASCII hex characters.
196-
local header_as_hex=$(echo "$(head -c48 <"$tempfile")" | openssl base64 -d | hexdump -ve '1/1 "%02x"')
197-
local first_salt_prefix=$(echo "$header_as_hex" | cut -b 1-32) # First 32 chars
198-
local maybe_second_salt_prefix=$(echo "$header_as_hex" | cut -b 33-64) # Second 32 chars
199-
200-
# If the salted prefix is repeated -- and not empty, to avoid mistaken match if
201-
# base64 decoding fails -- remove the first occurrence before decrypting...
202-
if [[ "$first_salt_prefix" && "$first_salt_prefix" == "$maybe_second_salt_prefix" ]]; then
203-
openssl base64 -d <"$tempfile" | tail -c+17 | ENC_PASS=$password "$openssl_path" enc -d "-${cipher}" -md MD5 -pass env:ENC_PASS 2>/dev/null
204-
# ...otherwise decrypt as normal
205-
else
206-
ENC_PASS=$password "$openssl_path" enc -d -a "-${cipher}" -md MD5 -pass env:ENC_PASS <"$tempfile" 2>/dev/null
207-
fi
208-
# If the first bytes are not "Salted", the file is not encrypted so output it unchanged
209-
else
210-
cat "$tempfile"
211-
fi
184+
tee "$tempfile" | ENC_PASS=$password "$openssl_path" enc -d "-${cipher}" -md MD5 -pass env:ENC_PASS -a 2>/dev/null || cat "$tempfile"
212185
}
213186

214187
git_textconv() {

0 commit comments

Comments
 (0)