Skip to content

Commit a3a77c2

Browse files
committed
Merge branch '2.2'
* 2.2: Release 2.2.1 Run tests for PR changes even if it doesn't target `main` Detect and fix decryption of files encrypted with doubled "Salted" prefixes due to #147 Fix compatibility with LibreSSL v3+ `openssl` command and MacOS Ventura (#148 #147) # Conflicts: # CHANGELOG.md # transcrypt
2 parents 1efd070 + 4f18a3a commit a3a77c2

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

.github/workflows/run-bats-core-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches: [main]
77
# Run tests for all pull request changes targeting main
88
pull_request:
9-
branches: [main]
9+
branches: "**"
1010

1111
jobs:
1212

CHANGELOG.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@ 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+
## Steps to Upgrade
12+
13+
To upgrade _transcrypt_ it is not enough to have a newer version on your
14+
system, you must also run the `--upgrade` command in each repository:
15+
16+
1. Check the version of _transcrypt_ on your system:
17+
18+
```bash
19+
$ transcrypt --version
20+
```
21+
22+
2. Check the version of _transcrypt_ in your Git repository, which may be
23+
different:
24+
25+
```bash
26+
$ .git/crypt/transcrypt --version
27+
```
28+
29+
3. Upgrade the version of _transcrypt_ in your Git repository:
30+
31+
```
32+
$ transcrypt --upgrade
33+
```
34+
1135
## [Unreleased]
1236

1337
### Added
@@ -17,10 +41,12 @@ The format is based on [Keep a Changelog][1], and this project adheres to
1741
normal repository users. See `--context=` / `-C` / `--list-context` arguments
1842
and documentation for this advanced feature.
1943

44+
## [2.2.1] - 2023-02-11
45+
2046
### Fixed
2147

2248
- 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+
49+
13 Ventura, to more carefully apply a work-around required for OpenSSL 3+
2450
that isn't required for LibreSSL 3+ (#147 #133)
2551
- Fix errors applying a stash containing a secret file that needs to be merged
2652
with staged changes to the same file (#150)
@@ -254,7 +280,8 @@ Since the v0.9.7 release, these are the notable improvements made to transcrypt:
254280

255281
## [0.9.4] - 2014-03-03
256282

257-
[unreleased]: https://github.com/elasticdog/transcrypt/compare/v2.2.0...HEAD
283+
[unreleased]: https://github.com/elasticdog/transcrypt/compare/v2.2.1...HEAD
284+
[2.2.1]: https://github.com/elasticdog/transcrypt/compare/v2.2.0...v2.2.1
258285
[2.2.0]: https://github.com/elasticdog/transcrypt/compare/v2.1.0...v2.2.0
259286
[2.1.0]: https://github.com/elasticdog/transcrypt/compare/v2.0.0...v2.1.0
260287
[2.0.0]: https://github.com/elasticdog/transcrypt/compare/v1.1.0...v2.0.0

transcrypt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ git_clean() {
222222
fi
223223
}
224224

225+
# shellcheck disable=SC2005,SC2155
225226
git_smudge() {
226227
tempfile=$(mktemp 2>/dev/null || mktemp -t tmp)
227228
trap 'rm -f "$tempfile"' EXIT
@@ -230,7 +231,32 @@ git_smudge() {
230231
cipher=$(git config --get --local "transcrypt${context_config_group}.cipher")
231232
password=$(load_password "$context_config_group")
232233
openssl_path=$(git config --get --local transcrypt.openssl-path)
233-
tee "$tempfile" | ENC_PASS=$password "$openssl_path" enc -d "-${cipher}" -md MD5 -pass env:ENC_PASS -a 2>/dev/null || cat "$tempfile"
234+
235+
# Write stdin to $tempfile, while skimming the first bytes at the same time
236+
local firstbytes=$(tee "$tempfile" | head -c8 | LC_ALL=C tr -d '\0')
237+
# If the first bytes are "Salted", then the file is encrypted
238+
if [[ $firstbytes == "U2FsdGVk" ]]; then
239+
# Fix for file mistakenly encrypted with double "Salted" prefixes due to #147
240+
# that causes garbage characters at top of decrypted files.
241+
#
242+
# 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
247+
248+
# If the salted prefix is repeated -- and not empty, to avoid mistaken match if
249+
# base64 decoding fails -- remove the first occurrence before decrypting...
250+
if [[ "$first_salt_prefix" && "$first_salt_prefix" == "$maybe_second_salt_prefix" ]]; then
251+
openssl base64 -d <"$tempfile" | tail -c+17 | ENC_PASS=$password "$openssl_path" enc -d "-${cipher}" -md MD5 -pass env:ENC_PASS 2>/dev/null
252+
# ...otherwise decrypt as normal
253+
else
254+
ENC_PASS=$password "$openssl_path" enc -d -a "-${cipher}" -md MD5 -pass env:ENC_PASS <"$tempfile" 2>/dev/null
255+
fi
256+
# If the first bytes are not "Salted", the file is not encrypted so output it unchanged
257+
else
258+
cat "$tempfile"
259+
fi
234260
}
235261

236262
git_textconv() {

0 commit comments

Comments
 (0)