Commit Graph
2520 Commits
Author SHA1 Message Date
Max Lv 98915c7828 Build as C11 and remove input-sized VLAs from key parsing
crypto_parse_key sized a stack array from strlen() of the key given on
the command line or in the config file, so a long enough key string
overflowed the stack before any validation ran. Only the first key_len
bytes were ever used, and base64_decode already stops at the size it is
given, so a fixed MAX_KEY_LENGTH buffer is enough. crypto_parse_psk
needs one byte of slack to tell an over-long key from an exact-size one.

The two "here is a valid key instead" error paths were identical; they
are now one helper, which also drops the last input-sized VLA.

Switch the standard from gnu99 to C11 via CMAKE_C_STANDARD rather than a
hand-written -std flag, so CMake picks the right spelling per compiler.
2026-08-19 18:24:33 +08:00
Max Lv 46791234c0 Add Shadowsocks 2022 (SIP022) ciphers
shadowsocks-rust has supported the 2022 edition for years while libev was
stuck on the 2017 AEAD construction, the largest functional gap between
the two implementations. This adds the three SIP022 methods:

  2022-blake3-aes-128-gcm
  2022-blake3-aes-256-gcm
  2022-blake3-chacha20-poly1305

TCP uses BLAKE3 derive_key for session subkeys, standalone header chunks
carrying a type byte and timestamp, request padding, and a response header
echoing the request salt. Replay protection uses an exact-match salt pool
with 60s retention rather than the bloom filter, which SIP022 forbids
because false positives are unacceptable there.

UDP is session-based: an AES-ECB separate header for the AES methods and a
merged XChaCha20-Poly1305 construction for ChaCha, with a per-session
sliding window replay filter. Servers must route by client session ID,
which is only known after decryption, so the crypto layer owns the
server-side session table and hands the session back to udprelay for the
reply path.

The 2022 code lives in aead2022.c and aead2022_udp.c so aead.c keeps its
current size, with aead_internal.h carrying what they share. BLAKE3 is
vendored (portable backend only) as its own build target.

Keys are base64 pre-shared keys of exactly the cipher's key size; per
SIP022 a password is never stretched into a key.

Verified interoperable in both directions against shadowsocks-rust 1.24.0
for all three ciphers over TCP and UDP, including an 8MB transfer checked
by digest, plus unit tests for header framing, partial delivery, tamper
detection, and UDP replay rejection.
2026-08-19 18:15:35 +08:00
Max Lv ab6e49381f Accept the standard base64 alphabet when decoding keys
The decode table only mapped the URL-safe alphabet, so '+' and '/' were
rejected as invalid characters. Keys are commonly generated with
`openssl rand -base64`, which emits standard base64, and shadowsocks-rust
accepts either form; a key containing '+' or '/' was refused outright
while the same key worked elsewhere.

Map both alphabets. The affected table entries previously decoded as
"invalid", so no input that used to decode changes meaning.
2026-08-19 18:15:24 +08:00
Max Lv 93b12ec7af Fix mbedTLS headers and libraries being drawn from different installs
find_library's search order puts CMAKE_PREFIX_PATH ahead of HINTS, so on
a Homebrew machine with both mbedtls (4.x) and the keg-only mbedtls@3,
the headers resolved to mbedtls@3 while the libraries resolved to 4.x.

That is not a link error but memory corruption at runtime:
mbedtls_cipher_context_t grew between the two versions, so every context
allocated with ss_malloc(sizeof(cipher_evp_t)) from the 3.x headers was
overrun by 4.x's mbedtls_cipher_init. It corrupted the heap in every
binary that sets up a cipher, and made the unit tests segfault inside an
unrelated malloc.

Pick a prefix that provides both the headers and libmbedcrypto and pin
every component to it, then verify at configure time that the header
version string matches what the linked library reports, so a mismatch
fails the build instead of corrupting memory.
2026-08-19 18:15:16 +08:00
Max LvandClaude Fable 5 dd2704c857 Fix bugs found by clang-tidy triage; ratchet warning budget to zero (#3047)
Real bugs fixed:
- manager.c: kill_server/stop_server checked fscanf() != EOF, so malformed
  pid file content left pid uninitialized and passed it to kill(). Parse
  with fgets + ss_parse_int and require pid > 0.
- utils.c: get_default_conf() crashed on strlen(NULL) when HOME is unset
  (e.g. daemons started by init) and left a dangling static pointer after
  free(), a latent use-after-free on repeated calls. Use a static buffer
  and fall back to the system config when HOME is missing.
- local.c: in UDP_ONLY mode, start_ss_local_server() passed uninitialized
  listen_ctx.fd to the library callback. Initialize it to -1.

Improvements:
- Replace rand()/srand(time(NULL)) upstream-server selection in ss-local,
  ss-redir and ss-tunnel with libsodium randombytes_uniform(): unbiased,
  unpredictable, and no seeding required (cert-msc30/msc32).
- Mark FATAL() noreturn so both the compiler and analyzers understand
  control flow (removes a family of analyzer false positives).
- Drop two dead stores (manager.c restore_sigchld, udprelay.c src_addr_len).

All remaining findings were verified as false positives and carry NOLINT
comments with rationale (uthash macro internals, symmetric back-pointer
cleanup, analyzer-invisible postconditions). clang-tidy-18 on Linux now
reports zero warnings, so MAX_WARNINGS drops from 29 to 0.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 13:02:58 +08:00
Max LvandClaude Fable 5 ba7b9ad4cc Add code quality tooling: clang-tidy, sanitizers, coverage (#3046)
- Export compile_commands.json for tooling
- .clang-tidy: clang-analyzer + bugprone + cert checks scoped to src/,
  with stylistic/false-positive-prone checks disabled
- ENABLE_SANITIZERS CMake option (ASan + UBSan)
- ENABLE_COVERAGE CMake option with an lcov/genhtml 'coverage' target
- CI: asan job (ctest + stress test under ASan/UBSan), clang-tidy job
  (warning-count ratchet, baseline 29 with pinned clang-tidy-18),
  coverage job (lcov summary + HTML report artifact)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 12:24:57 +08:00
Max Lv 5559eec939 Harden security-sensitive input handling (#3045)
* harden security-sensitive input handling

* enable ctest failure checks in ci

* add valgrind leak smoke tests

* split tests into separate workflow
2026-07-15 11:10:24 +08:00
notsure2 fc8750f329 Fix mishandling of incoming socket buffer. It must be set on the listening socket not the accepted socket. 2026-06-17 17:19:00 +08:00
dependabot[bot] 244af7d35c Bump actions/checkout from 4 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-17 16:47:35 +08:00
Max Lv 19e681fd8c Merge pull request #2986 from xwjdsh/master
[ss-manager] Fall back to /tmp if workdir is /
2026-06-17 11:26:53 +08:00
Max Lv 6f73c823a9 Merge pull request #3034 from vndroid/patch1
Fix CMake Warning
2026-06-17 11:26:48 +08:00
Max Lv 7ae92ee2cd Merge pull request #3038 from hillwoodroc/master
Fix build with gcc13
2026-06-17 11:26:43 +08:00
Max Lv acf55e495f Merge pull request #3025 from shadowsocks/fix/cares-static-lib-name
Fix static c-ares detection for c-ares >= 1.27
2026-06-17 11:26:39 +08:00
Max Lv 9292a30225 Merge pull request #3017 from ayuusweetfish/mbedtls3-aesgcm
Fix failed assertion with Mbed TLS 3
2026-06-17 11:26:35 +08:00
Max Lv 7b507caf9e Merge pull request #3039 from TurboTheTurtle/fix-udp-json-bounds-checks
Fix truncated UDP and JSON bounds checks
2026-06-17 11:26:32 +08:00
Andy Ye 835f653df8 Fix truncated UDP and JSON bounds checks 2026-05-12 00:50:59 -07:00
Hillwood Yang 59a6aca759 Fix build with gcc13 2026-05-05 14:39:10 +08:00
Pain 95b8a2ca7a Fix CMake Warning 2026-04-16 07:39:14 -07:00
Pain fb3d4a5fb2 Fix CMake Deprecation Warning 2026-04-16 07:35:27 -07:00
Max LvandClaude Opus 4.6 8ad3036f29 Update snap packaging for v3.3.6 with CMake and core22
Migrate from autotools to cmake plugin, upgrade base from core18 to
core22, point source to local git repo instead of stale v3.3.5 tarball,
update PCRE3 to PCRE2, and update runtime library packages for Ubuntu
22.04.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 18:56:17 +08:00
Max LvandClaude Opus 4.6 5c47b80f4e Update README with CMake build instructions and ss-setup/ss-nat docs
Modernize build instructions to focus on CMake (the sole build system),
remove outdated autotools/backports references, and add documentation
for the ss-setup interactive TUI tool and the ss-nat transparent proxy
helper script with practical usage examples.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 08:59:58 +08:00
Max LvandClaude Opus 4.6 716269d020 CI: enable static build to catch static-linking issues
WITH_STATIC defaults to ON in CMakeLists.txt but CI was explicitly
disabling it. Remove -DWITH_STATIC=OFF so the static targets are
also built and linked, catching issues like the c-ares static
library rename (#3024).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 16:13:44 +08:00
Max LvandClaude Opus 4.6 7ac8694aae Fix static c-ares detection for newer Debian/Ubuntu releases
c-ares >= 1.27 renamed the static library from libcares.a to
libcares_static.a. Search for both names so the static build works
on older distros (libcares.a) and newer ones (libcares_static.a).

Fixes #3024

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 15:43:42 +08:00
Max LvandClaude Opus 4.6 c5e8788013 Bump version to 3.3.6
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
v3.3.6
2026-02-09 09:15:12 +08:00
Max Lv 2981f65e20 Merge pull request #3023 from shadowsocks/fix/aead-decrypt-chunk-compaction
Fix unbounded buffer growth in aead_decrypt chunk reassembly
2026-02-09 09:12:12 +08:00
Max LvandClaude Opus 4.6 ff44361f5d Fix unbounded buffer growth in aead_decrypt chunk reassembly
The idx-tracking optimization in aead_decrypt skipped memmove when
partial AEAD chunks spanned multiple calls, but never compacted the
dead space before idx. This caused the chunk buffer to grow
proportionally to total data transferred (~10 MB growth per 10 MB
transferred), tripping the stress test memory leak threshold.

Compact residual data to the front when appending new ciphertext,
keeping the buffer bounded to the size of the residual plus new data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 09:04:58 +08:00
Max LvandClaude Opus 4.6 31731baa44 Reduce memory copies in crypto encrypt/decrypt paths
Add bswap_data() to swap buffer pointers instead of copying, replace
brealloc+memcpy with pointer swaps in aead and stream codecs, add
in-place fast paths for non-Salsa20 stream ciphers, and use index
tracking instead of memmove in aead_decrypt chunked reassembly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 08:53:28 +08:00
Max LvandClaude Opus 4.6 6423c8e496 Add Debian package build test and statically link bundled submodules
Add tests/test_deb_build.sh with four phases:
1. Build .deb packages via dpkg-buildpackage
2. Verify all three packages contain expected files (binaries, man
   pages, shared library, headers, pkg-config)
3. Install packages and resolve dependencies
4. Smoke-test installed binaries, ldconfig, and headers

Add a Linux-only CI step in build.yml to run the test.

Statically link the bundled submodule libraries (libcork, libipset,
libbloom) into all targets instead of building them as shared libs.
These are vendored code built from git submodules, not system
libraries, so static linking is correct and eliminates
dpkg-shlibdeps warnings about missing .so files.

Pass -DWITH_STATIC=OFF in debian/rules since debian build-depends
only provide shared library dev packages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 11:32:13 +08:00
mesher2024 d52d4015d1 Update configure parameter in debian/rules 2026-02-08 09:59:34 +08:00
mesher2024 bb104036d2 Remove configure parameters in debian/rules 2026-02-08 09:59:34 +08:00
mesher2024 2d8af6e56c Update build-depends in debian/control
Replace libpcre3-dev with libpcre2-dev.
2026-02-08 09:59:34 +08:00
mesher2024 d8c3004c97 Update .gitignore
Add obj-* in .gitignore
2026-02-08 09:59:34 +08:00
Max Lv 44939a774a Merge pull request #3020 from shadowsocks/test/ss-redir-qemu-e2e
Add end-to-end test for ss-redir transparent proxy via QEMU
2026-02-08 09:55:41 +08:00
Max LvandClaude Opus 4.6 14b5544634 Add end-to-end test for ss-redir transparent proxy via QEMU
Boot a minimal Alpine Linux guest in QEMU with iptables, ss-redir, and
ss-nat to verify the full transparent proxy chain: iptables REDIRECT →
ss-redir → ss-server (host) → internet. The host-built ss-redir binary
and its shared library dependencies are copied into the Alpine rootfs,
avoiding static linking issues. Uses QEMU user-mode networking with KVM
acceleration when available. Linux-only CI step with 8-minute timeout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 19:01:32 +08:00
Max LvandClaude Opus 4.6 5c2d0e43fa Add ss-setup TUI tool with unit tests and CI integration
Interactive whiptail/dialog TUI for server/client config generation,
systemd service management, SIP003 plugin installation, and ss:// URI
output. Includes 131 bash unit tests covering all utility functions
(validation, JSON generation, URI encoding, config round-trip parsing).
Tests run in CTest and as a dedicated GitHub Actions step.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 18:30:20 +08:00
Max LvandClaude Opus 4.6 7bb250739e Modernize build: switch to CMake, add unit tests, fix man pages
* Modernize build: switch to CMake, add unit tests, fix man pages

Remove autotools (configure.ac, Makefile.am, m4/, autogen.sh) and make
CMake the sole build system. Enhance CMake with proper Find modules for
MbedTLS, libsodium, PCRE, and c-ares with version/feature detection.
Add support for connmarktos, nftables, stack protector, and MinGW.

Add 10 unit test suites (CTest) covering base64, buffer, cache, crypto,
jconf, json, netutils, ppbloom, rule, and utils modules. Add a Python
stress test measuring bandwidth per cipher with memory leak detection.

Fix man page typos ("Resovle" -> "Resolve"), document missing TCP buffer
options, fix ss-manager duplicate --executable entry, add example section
to ss-tunnel, and document --workdir and --nftables-sets options.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Migrate from PCRE to PCRE2

Replace legacy PCRE (libpcre3) with PCRE2 (libpcre2-8). PCRE1 has been
end-of-life since 2021.

- src/rule.h: use pcre2_code and pcre2_match_data types
- src/rule.c: pcre_compile -> pcre2_compile, pcre_exec -> pcre2_match,
  pcre_free -> pcre2_code_free, with proper error message retrieval
- cmake/FindPCRE.cmake -> cmake/FindPCRE2.cmake: find libpcre2-8 via
  pkg-config, pcre2-config, or manual search
- Update all CMakeLists.txt, config.h.cmake, configure.cmake, README.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update Dockerfiles: use CMake build and pcre2-dev

The alpine Dockerfile still used autotools (autogen.sh/configure) which
were removed. Switch to cmake build and replace pcre-dev with pcre2-dev.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Docker build: disable tests and remove git dep

The tests/ directory is excluded by .dockerignore, so pass
-DBUILD_TESTING=OFF to cmake. Submodules are already checked out
by actions/checkout, no need for git inside the container.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Docker build: disable static libs (not available in alpine)

Alpine's mbedtls-dev only provides shared libraries. Disable static
build since Docker only needs shared binaries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Rewrite GitHub Actions: build and test directly on runner

Replace Docker-based CI with direct cmake build on ubuntu-latest and
macos-latest. Install dependencies via apt/brew, build with cmake,
run unit tests with ctest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix CI: use mbedtls@3 on macOS, disable static build

- macOS: brew's mbedtls is now v4 (incompatible), use mbedtls@3
- Disable static build since CI runners lack static lib packages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix test build on Linux: add stdint.h and link libm

- test_ppbloom.c: add missing #include <stdint.h> for uint8_t
- test_json: link against libm for pow() used in json.c

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix test_ppbloom link: add libm for bloom's log()

On Linux, libbloom uses log() which requires explicit -lm linkage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Linux build: link libm for test_buffer and test_crypto, fix warnings

Both test_buffer and test_crypto link libbloom.so which uses log() from
libm. Also fix unused variable warnings in test_json.c that would fail
with -Werror.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix Linux build: link libm for test_jconf (json.c uses pow)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* CI: add unit test and stress test steps to GitHub Actions

Split the Test step into separate "Unit tests" (ctest) and "Stress test"
(stress_test.py with 10MB transfer across all AEAD ciphers) steps for
better visibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 17:06:47 +08:00
Ayu 60ad4ca4b5 Fix failed assertion with Mbed TLS 3 2026-01-18 16:59:48 +08:00
David Korczynski b2a0c545d8 json: fix signed integer overflows
Signed integer overflows can happen in three distinct places. This
fixes it so an error happens when an overflow is observed.

Signed-off-by: David Korczynski <david@adalogics.com>
2025-12-29 17:44:06 +08:00
Lu jicongandZxl hhyccc 9afa3cacf9 Fix in 'mbedtls 3.6.0 ver' compilation failure issue
Fix mbedtls 3.6 compatibility

Co-authored-by: Zxl hhyccc <zxlhhy@gmail.com>
Signed-off-by: Lu jicong <jiconglu58@gmail.com>
2025-01-20 11:11:47 +08:00
Wen Sun c9e3eebbe2 [ss-manager] Fall back to /tmp if workdir is / 2023-11-23 20:49:09 +09:00
GVerso d83ace0f0d Translation of README.md into Brazilian Portuguese. (#2946)
README.md translated to Brazilian Portuguese
2022-11-30 11:08:01 +08:00
Bill Zhong 288cba784e fix snap link and badge 2022-11-30 11:06:54 +08:00
Michael 3bcf258de1 Fix "missing configuration file" error during custom build using autotools 2022-11-23 09:39:54 +08:00
rickyrick2002 7f7f68afe4 replace fixed mbedtls version with variable $MBEDTLS_VER 2022-10-25 11:59:31 +08:00
rickyrick2002 a3b1dc7f37 update MbedTLS dependency link and add Debian / Ubuntu apt pkg-config 2022-10-25 11:59:31 +08:00
nishans08 d3e73c6ce6 fixes grammatical errors in README.md
221: You should jump this section and install them from distribution repository instead. -> You should jump to this section and install them from the distribution repository instead.

FIX #7
2022-07-28 10:24:48 +08:00
vndroid 5fdb6624e3 Update
- Fix path error
2022-06-28 16:22:11 +08:00
vndroid c13c464604 Update
- Solve the problem of not being able to enter the container
- Execute strip after compilation
- Support multi-threaded compilation
2022-06-28 15:32:11 +08:00
DDoSolitary 05e70d4317 fix c-ares link dep 2022-06-26 06:22:56 +08:00
Maxim Galaganov 549b9bedb9 Fix rpm build for fedora 36 2022-06-26 06:21:38 +08:00