Skip to content

Commit f709d47

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 4f18a3a commit f709d47

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ system, you must also run the `--upgrade` command in each repository:
3232
$ transcrypt --upgrade
3333
```
3434

35+
## [Unreleased]
36+
37+
### Changed
38+
39+
- The `hexdump` command is now required by Transcrypt. It will be installed
40+
already on many systems, or comes with the `bsdmainutils` package on
41+
Ubuntu/Debian that was already required to get the `column` command.
42+
43+
### Fixed
44+
45+
- Avoid null byte warnings when decrypting certain files, caused by a work-
46+
around in 2.2.1 to repair files that could have been incorrectly encrypted
47+
with 2.2.0 due to issue #147
48+
3549
## [2.2.1] - 2023-02-11
3650

3751
### Fixed

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` 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

transcrypt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ git_smudge() {
191191
# that causes garbage characters at top of decrypted files.
192192
#
193193
# 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-
local header_decoded=$(echo "$(head -c48 <"$tempfile")" | openssl base64 -d)
196-
local first_salt_prefix=$(echo "$header_decoded" | cut -b 1-16) # First 16 bytes
197-
local maybe_second_salt_prefix=$(echo "$header_decoded" | cut -b 17-32) # Second 16 bytes
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
198199

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

0 commit comments

Comments
 (0)