-
Notifications
You must be signed in to change notification settings - Fork 3
382 lines (319 loc) · 12.5 KB
/
test.yml
File metadata and controls
382 lines (319 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
# Fast compile-only check: ensures no compiler warnings slip through.
# The main build uses -Wall but not -Werror, so warnings don't fail the
# build for end users on different compiler versions. This CI job adds
# -Werror to catch regressions like the dc-table overflow in v3.5.3.
build-werror:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev
- name: Build with -Werror
run: make clean && make -j$(nproc) EXTRA_CFLAGS="-Werror"
# Native ARM64 build: catches platform-specific issues (e.g., x86-only
# headers) that pass on x86 and Alpine/musl but fail on glibc aarch64.
build-werror-arm64:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev
- name: Build with -Werror (ARM64 native)
run: make clean && make -j$(nproc) EXTRA_CFLAGS="-Werror"
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build and Run Tests
env:
TELEPROXY_SECRET: ${{ secrets.TELEPROXY_SECRET }}
run: |
if [ -z "$TELEPROXY_SECRET" ]; then
export TELEPROXY_SECRET=$(head -c 16 /dev/urandom | xxd -ps)
echo "Generated random TELEPROXY_SECRET for testing"
fi
make test
- name: Run TLS E2E Tests
env:
TELEPROXY_SECRET: ${{ secrets.TELEPROXY_SECRET }}
run: |
if [ -z "$TELEPROXY_SECRET" ]; then
export TELEPROXY_SECRET=$(head -c 16 /dev/urandom | xxd -ps)
fi
make test-tls
- name: Run Multi-Secret Tests
run: make test-multi-secret
- name: Run Secret Limit Tests
run: make test-secret-limit
- name: Run DRS Delays Tests
run: make test-drs-delays
- name: Run CDN DC Tests
run: make test-cdn-dc
- name: Run IPv6 Direct Mode Tests
run: make test-ipv6-direct
test-dc-lookup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev
- name: Build and run DC lookup tests
run: make test-dc-lookup
test-arm64:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build and smoke test (ARM64)
run: |
export TELEPROXY_SECRET=$(head -c 16 /dev/urandom | xxd -ps)
echo "Generated TELEPROXY_SECRET for ARM64 testing"
make test
- name: Run TLS E2E Tests (ARM64)
run: |
export TELEPROXY_SECRET=$(head -c 16 /dev/urandom | xxd -ps)
make test-tls
test-native-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev git curl vim-common python3 python3-pip python3-venv netcat-openbsd libunwind-dev
python3 -m venv .venv
source .venv/bin/activate
pip install requests telethon
- name: Build Teleproxy
run: |
make clean && make -j$(nproc)
- name: Verify version string
run: |
EXPECTED_VERSION=$(git describe --tags --match 'v*' --abbrev=0 | sed 's/^v//')
echo "Expected version: $EXPECTED_VERSION"
ACTUAL_OUTPUT=$(objs/bin/teleproxy 2>&1 || true)
echo "$ACTUAL_OUTPUT" | grep -q "teleproxy-${EXPECTED_VERSION}" || {
echo "ERROR: version mismatch — expected teleproxy-${EXPECTED_VERSION}"
exit 1
}
echo "Version check passed"
- name: Setup and Run Proxy
run: |
echo "Checking connectivity to Telegram DC (149.154.175.50:443)..."
nc -zv 149.154.175.50 443 || echo "Failed to connect to Telegram DC 149.154.175.50:443"
mkdir -p teleproxy-run
cp objs/bin/teleproxy teleproxy-run/
cd teleproxy-run
# Download config/secret (ME relay mode)
curl --connect-timeout 10 --max-time 30 --retry 3 -fsSL https://core.telegram.org/getProxySecret -o proxy-secret
curl --connect-timeout 10 --max-time 30 --retry 3 -fsSL https://core.telegram.org/getProxyConfig -o proxy-multi.conf
SECRET=$(head -c 16 /dev/urandom | xxd -ps)
echo "Using secret: $SECRET"
# ME relay mode proxy
./teleproxy -u nobody -p 8888 -H 8443 -S $SECRET --http-stats --aes-pwd proxy-secret proxy-multi.conf -M 1 &
echo "TELEPROXY_SECRET=$SECRET" >> $GITHUB_ENV
sleep 5
- name: Run Python Tests
run: |
source .venv/bin/activate
export TELEPROXY_HOST=localhost
export TELEPROXY_PORT=8443
python3 tests/test_proxy.py
- name: Run TLS E2E Tests (ME Relay)
run: |
source .venv/bin/activate
cd teleproxy-run
./teleproxy -p 9888 -H 9443 -S $TELEPROXY_SECRET \
--http-stats --aes-pwd proxy-secret proxy-multi.conf -D ya.ru -M 0 &
TLS_PID=$!
cd ..
for i in $(seq 1 30); do
curl -sf http://localhost:9888/stats >/dev/null 2>&1 && break
sleep 2
done
TELEPROXY_HOST=localhost TELEPROXY_PORT=9443 TELEPROXY_STATS_PORT=9888 \
TELEPROXY_SECRET=$TELEPROXY_SECRET TLS_BACKEND_HOST=ya.ru TLS_BACKEND_PORT=443 \
python3 tests/test_tls_e2e.py
TELEPROXY_HOST=localhost TELEPROXY_PORT=9443 \
TELEPROXY_SECRET=$TELEPROXY_SECRET TLS_BACKEND_HOST=ya.ru \
python3 tests/test_tls_fingerprint.py
kill $TLS_PID 2>/dev/null || true
test-direct-e2e:
runs-on: ubuntu-latest
# Only run when secrets are available (skip on fork PRs)
if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev git curl vim-common python3 python3-pip python3-venv netcat-openbsd
python3 -m venv .venv
source .venv/bin/activate
pip install requests telethon TelethonFakeTLS
- name: Build Teleproxy
run: |
make clean && make -j$(nproc)
- name: Start Direct-Mode Proxies
run: |
echo "Checking connectivity to Telegram DCs..."
nc -zv 149.154.167.51 443 || echo "WARNING: Cannot reach production DC 2"
nc -zv 149.154.167.40 443 || echo "WARNING: Cannot reach test DC 2"
mkdir -p teleproxy-run
cp objs/bin/teleproxy teleproxy-run/
cd teleproxy-run
SECRET=$(head -c 16 /dev/urandom | xxd -ps)
echo "Using secret: $SECRET"
echo "TELEPROXY_SECRET=$SECRET" >> $GITHUB_ENV
# Obfuscated2 direct-mode proxy (no proxy-secret/proxy-multi.conf needed)
./teleproxy -u nobody -p 8888 -H 8443 -S $SECRET \
--http-stats --direct -M 0 2>obfs2.log &
echo "Started obfs2 direct-mode proxy on port 8443"
# Fake-TLS direct-mode proxy
./teleproxy -u nobody -p 9888 -H 9443 -S $SECRET \
--http-stats --direct -D ya.ru -M 0 2>faketls.log &
echo "Started fake-TLS direct-mode proxy on port 9443"
# Wait for both proxies to be ready
for port in 8888 9888; do
for i in $(seq 1 30); do
curl -sf http://localhost:$port/stats >/dev/null 2>&1 && break
sleep 2
done
curl -sf http://localhost:$port/stats >/dev/null 2>&1 || {
echo "ERROR: Proxy on stats port $port not ready after 60s"
exit 1
}
done
echo "Both proxies are ready"
- name: Run Direct Mode E2E Tests
env:
TG_TEST_SESSION: ${{ secrets.TG_TEST_SESSION }}
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
run: |
source .venv/bin/activate
DIRECT_HOST=localhost \
DIRECT_OBFS2_PORT=8443 \
DIRECT_TLS_PORT=9443 \
TELEPROXY_SECRET=$TELEPROXY_SECRET \
EE_DOMAIN=ya.ru \
python3 tests/test_direct_e2e.py
- name: Proxy logs (debug)
if: always()
run: |
echo "=== Obfs2 proxy log ==="
cat teleproxy-run/obfs2.log 2>/dev/null || echo "(no log)"
echo ""
echo "=== Fake-TLS proxy log ==="
cat teleproxy-run/faketls.log 2>/dev/null || echo "(no log)"
test-asan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev git curl vim-common python3 python3-pip python3-venv
- name: Build with AddressSanitizer
run: |
make clean && make -j$(nproc) \
EXTRA_CFLAGS="-fsanitize=address -fno-omit-frame-pointer" \
EXTRA_LDFLAGS="-fsanitize=address"
- name: Setup and Run Proxy
run: |
mkdir -p teleproxy-run
cp objs/bin/teleproxy teleproxy-run/
cd teleproxy-run
curl --connect-timeout 10 --max-time 30 --retry 3 -fsSL https://core.telegram.org/getProxySecret -o proxy-secret
curl --connect-timeout 10 --max-time 30 --retry 3 -fsSL https://core.telegram.org/getProxyConfig -o proxy-multi.conf
SECRET=$(head -c 16 /dev/urandom | xxd -ps)
echo "Using secret: $SECRET"
echo "TELEPROXY_SECRET=$SECRET" >> $GITHUB_ENV
ASAN_OPTIONS=detect_leaks=0 \
./teleproxy -u nobody -p 8888 -H 8443 -S $SECRET \
--http-stats --aes-pwd proxy-secret proxy-multi.conf -M 1 \
2>asan.log &
echo $! > proxy.pid
sleep 5
- name: Run Tests
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install requests
TELEPROXY_HOST=localhost TELEPROXY_PORT=8443 python3 tests/test_proxy.py
- name: Check for ASan Errors
if: always()
run: |
PID=$(cat teleproxy-run/proxy.pid 2>/dev/null || true)
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
echo "Proxy still running (PID $PID) — no ASan crash during test"
kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null || true
else
echo "WARNING: Proxy exited early — possible ASan error"
fi
if [ -f teleproxy-run/asan.log ] && grep -q "AddressSanitizer" teleproxy-run/asan.log; then
echo "::error::AddressSanitizer errors detected"
cat teleproxy-run/asan.log
exit 1
fi
echo "No ASan errors detected"
- name: Verify ASan catches known heap overflow
run: |
# Re-introduce the CONN_INFO heap overflow fixed in a7e832e to
# prove ASan catches real bugs in the proxy, not just toy programs.
#
# The bug: CONN_INFO(LC)->window_clamp writes at offset ~512 into
# an 80-byte listening_connection_info (allocated via malloc).
#
# Key: use -M 0 (no fork) so the bug triggers in the main process
# whose stderr we capture. With -M 1, the bug only fires in the
# child worker, but $! captures the parent PID.
sed -i 's/LISTEN_CONN_INFO(LC)->window_clamp/CONN_INFO(LC)->window_clamp/' src/mtproto/mtproto-proxy.c
make -j$(nproc) \
EXTRA_CFLAGS="-fsanitize=address -fno-omit-frame-pointer" \
EXTRA_LDFLAGS="-fsanitize=address"
cp objs/bin/teleproxy teleproxy-run/
cd teleproxy-run
ASAN_OPTIONS=detect_leaks=0 \
./teleproxy -u nobody -p 7888 -H 7443 -S $TELEPROXY_SECRET \
--http-stats --aes-pwd proxy-secret proxy-multi.conf -M 0 \
>asan-bug.log 2>&1 &
BUG_PID=$!
sleep 5
kill "$BUG_PID" 2>/dev/null || true
wait "$BUG_PID" 2>/dev/null || true
if grep -q "heap-buffer-overflow" asan-bug.log; then
echo "ASan correctly detected the known heap-buffer-overflow"
else
echo "::error::ASan did NOT detect the known heap overflow"
echo "--- asan-bug.log ---"
cat asan-bug.log
exit 1
fi
- name: Restore source tree
if: always()
run: git checkout -- src/mtproto/mtproto-proxy.c