Skip to content

Commit 8be50df

Browse files
committed
Avoid null bytes decryption work-around for files with doubled "Salted" prefix due to #147
Improve the work-around for files incorrectly encrypted with doubled "Salted" prefixes due to #147 to avoid null byte warnings – and possibly errors – by checking prefix data as hex-encoded values instead of raw bytes which could contain null characters that are not well handled in bash scripts. This should avoid warnings like the following during decryption: warning: command substitution: ignored null byte in input Unfortunately the need for hex-encoding of bytes adds a new requirement for the `hexdump` command.
1 parent b8b564e commit 8be50df

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Diff for: CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ system, you must also run the `--upgrade` command in each repository:
4343
- When transcrypt refuses to do work in a dirty repository, print a list of
4444
changed files to help the user understand and fix the issue.
4545

46+
### Changed
47+
48+
- The `hexdump` command is now required by Transcrypt. It will be installed
49+
already on many systems, or comes with the `bsdmainutils` package on
50+
Ubuntu/Debian that was already required to get the `column` command.
51+
4652
### Fixed
4753

54+
- Avoid null byte warnings when decrypting certain files, caused by a work-
55+
around in 2.2.1 to repair files that could have been incorrectly encrypted
56+
with 2.2.0 due to issue #147
4857
- Prevent `cd` commands printing out excess details when `CDPATH` is set (#156)
4958

5059
## [2.2.1] - 2023-02-11

Diff for: README.md

+1-1
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` command (on Ubuntu/Debian install `bsdmainutils`)
58+
- `column` and `hexdump` commands (on Ubuntu/Debian install `bsdmainutils`)
5959
- `xxd` command if using OpenSSL version 3
6060
(on Ubuntu/Debian is included with `vim`)
6161

Diff for: transcrypt

+5-4
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,11 @@ git_smudge() {
240240
# that causes garbage characters at top of decrypted files.
241241
#
242242
# Check file header, which we already know starts with "Salted", to see if
243-
# it has exactly the same "Salted__XYZ" prefix mistakenly repeated twice
244-
local header_decoded=$(echo "$(head -c48 <"$tempfile")" | openssl base64 -d)
245-
local first_salt_prefix=$(echo "$header_decoded" | cut -b 1-16) # First 16 bytes
246-
local maybe_second_salt_prefix=$(echo "$header_decoded" | cut -b 17-32) # Second 16 bytes
243+
# it has exactly the same "Salted__XYZ" prefix mistakenly repeated twice.
244+
# Base64 decode gives raw bytes, hexdump gives bytes as ASCII hex characters.
245+
local header_as_hex=$(echo "$(head -c48 <"$tempfile")" | openssl base64 -d | hexdump -ve '1/1 "%02x"')
246+
local first_salt_prefix=$(echo "$header_as_hex" | cut -b 1-32) # First 32 chars
247+
local maybe_second_salt_prefix=$(echo "$header_as_hex" | cut -b 33-64) # Second 32 chars
247248

248249
# If the salted prefix is repeated -- and not empty, to avoid mistaken match if
249250
# base64 decoding fails -- remove the first occurrence before decrypting...

0 commit comments

Comments
 (0)