Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
ci: SonarQube scan for Windows, Linux and macOS
AnoF-Cybere330e1f7aa95
diff --git a/.github/scripts/sonar-compile-windows.ps1 b/.github/scripts/sonar-compile-windows.ps1new file mode 100644index 0000000..36253ca--- /dev/null+++ b/.github/scripts/sonar-compile-windows.ps1@@ -0,0 +1,31 @@+# Compiles every Windows C file (compile only, no link) so the SonarQube Build Wrapper can record the compiler+# calls. Same build as the CodeQL Windows job. Run from the repository root:+# build-wrapper-win-x86-64.exe --out-dir bw-output pwsh -NoProfile -File .github\scripts\sonar-compile-windows.ps1+$ErrorActionPreference = "Stop"++$vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `+ -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `+ -property installationPath+$vcvars = Join-Path $vsPath "VC\Auxiliary\Build\vcvars64.bat"+$common = "/nologo /c /W4 /wd4100 /wd4189 /wd4267 /wd4244 /wd4996 /D_CRT_SECURE_NO_WARNINGS /D_WINSOCK_DEPRECATED_NO_WARNINGS /GS /guard:cf"++# every .c file of a folder is listed, so a new source file is picked up without touching this script+function Compile($dir, $extra) {+ $files = (Get-ChildItem $dir -Filter *.c -File | ForEach-Object { Join-Path $dir $_.Name }) -join " "+ if (-not $files) { throw "no C files found in $dir" }+ cmd /c "`"$vcvars`" && cl.exe $common $extra $files"+ if ($LASTEXITCODE -ne 0) { throw "compile failed in $dir" }+}++# Core DLL+Compile "Windows\src" "/DPROXYBRIDGE_EXPORTS /I`"C:\WinDivert-2.2.2-A\include`""+# Engine service (runs as LocalSystem)+Compile "Windows\src\service" "/D_CRT_SECURE_NO_WARNINGS /DUNICODE /D_UNICODE"+# CLI+Compile "Windows\cli" "/D_WIN32_WINNT=0x0601 /DUNICODE /D_UNICODE"+# Native C GUI: built from its own folder so the subfolder includes resolve+Push-Location Windows\gui+$guiFiles = (Get-ChildItem . -Filter *.c -File -Recurse | ForEach-Object { Resolve-Path -Relative $_.FullName }) -join " "+cmd /c "`"$vcvars`" && cl.exe $common /utf-8 /DUNICODE /D_UNICODE $guiFiles"+if ($LASTEXITCODE -ne 0) { throw "compile failed in Windows\gui" }+Pop-Locationdiff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.ymlnew file mode 100644index 0000000..d313e8a--- /dev/null+++ b/.github/workflows/sonarqube.yml@@ -0,0 +1,176 @@+name: SonarQube++# SonarQube Cloud keeps one result per project, and the C analyzer needs the compiler and headers of the platform the+# code is built for (MSVC and the Windows SDK, or gcc and the Linux headers). So every platform is its own project,+# analysed on its own runner, and each has its own quality gate:+#+# Windows InterceptSuite_ProxyBridge_Windows MSVC, recorded by the Build Wrapper Windows/sonar-project.properties+# Linux InterceptSuite_ProxyBridge_Linux gcc/clang, recorded by the Build Wrapper Linux/sonar-project.properties+# macOS InterceptSuite_ProxyBridge_macOS Swift is read from the sources, no build MacOS/sonar-project.properties+#+# Needs the SONAR_TOKEN secret and the three projects created in SonarQube Cloud (import this repository as a monorepo).+# In every project, Administration > Analysis Method must be "With GitHub Actions" (automatic analysis rejects CI scans).++on:+ push:+ branches: [ "master" ]+ pull_request:+ types: [ opened, synchronize, reopened ]++permissions:+ contents: read++concurrency:+ group: sonarqube-${{ github.ref }}+ cancel-in-progress: true++jobs:+ windows:+ name: Analyze (Windows)+ runs-on: windows-latest+ timeout-minutes: 45+ # Pull requests from forks do not get repository secrets: skip them instead of failing.+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ steps:+ - name: Checkout+ uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1+ with:+ fetch-depth: 0 # shallow clones lower the relevancy of the analysis++ - name: Cache SonarQube packages+ uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0+ with:+ path: ~\.sonar\cache+ key: ${{ runner.os }}-sonar+ restore-keys: ${{ runner.os }}-sonar++ # same download, with the same checksum, as the Build Windows and CodeQL workflows+ - name: Download WinDivert+ run: |+ $url = "https://github.com/basil00/WinDivert/releases/download/v2.2.2/WinDivert-2.2.2-A.zip"+ $expectedHash = "63CB41763BB4B20F600B6DE04E991A9C2BE73279E317D4D82F237B150C5F3F15"+ Invoke-WebRequest -Uri $url -OutFile "WinDivert.zip" -UseBasicParsing+ $actualHash = (Get-FileHash "WinDivert.zip" -Algorithm SHA256).Hash+ if ($actualHash -ne $expectedHash) {+ Write-Error "WinDivert.zip SHA256 mismatch! Expected: $expectedHash Got: $actualHash"+ exit 1+ }+ Expand-Archive -Path "WinDivert.zip" -DestinationPath "C:\"+ shell: pwsh++ - name: Install Build Wrapper+ id: build-wrapper+ uses: SonarSource/sonarqube-scan-action/install-build-wrapper@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0++ # The wrapper records every compiler call of the compile-only build of the engine, service, CLI and GUI.+ - name: Build Windows code under the Build Wrapper+ env:+ BUILD_WRAPPER: ${{ steps.build-wrapper.outputs.build-wrapper-binary }}+ run: |+ & $env:BUILD_WRAPPER --out-dir bw-output pwsh -NoProfile -File .github\scripts\sonar-compile-windows.ps1+ if ($LASTEXITCODE -ne 0) { throw "build under the Build Wrapper failed" }+ shell: pwsh++ - name: SonarQube Scan+ uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0+ env:+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}+ with:+ projectBaseDir: Windows+ args: >+ -Dsonar.cfamily.compile-commands=${{ github.workspace }}/bw-output/compile_commands.json++ linux:+ name: Analyze (Linux)+ runs-on: ubuntu-latest+ timeout-minutes: 45+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ steps:+ - name: Checkout+ uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1+ with:+ fetch-depth: 0++ - name: Cache SonarQube packages+ uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0+ with:+ path: ~/.sonar/cache+ key: ${{ runner.os }}-sonar+ restore-keys: ${{ runner.os }}-sonar++ # same packages as the Build Linux and CodeQL workflows+ - name: Install build dependencies+ run: |+ sudo apt-get update+ sudo apt-get install -y \+ build-essential \+ gcc \+ make \+ clang \+ curl \+ linux-tools-common \+ linux-tools-generic \+ libbpf-dev \+ libelf-dev \+ zlib1g-dev \+ libgtk-3-dev \+ pkg-config+ shell: bash++ - name: Locate bpftool+ run: |+ shopt -s nullglob+ candidates=(/usr/lib/linux-tools/*/bpftool)+ [ ${#candidates[@]} -gt 0 ] || { echo "bpftool binary not found"; ls /usr/lib/linux-tools 2>&1 || true; exit 1; }+ echo "BPFTOOL=${candidates[0]}" >> "$GITHUB_ENV"+ shell: bash++ - name: Install Build Wrapper+ id: build-wrapper+ uses: SonarSource/sonarqube-scan-action/install-build-wrapper@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0++ # The wrapper records every compiler call of the Linux build (library, CLI and GTK GUI). LTO and the binary+ # audit are off (they only matter for the shipped binaries); the system libbpf is used.+ - name: Build Linux code under the Build Wrapper+ env:+ BUILD_WRAPPER: ${{ steps.build-wrapper.outputs.build-wrapper-binary }}+ run: |+ chmod +x Linux/build.sh+ "$BUILD_WRAPPER" --out-dir bw-output bash -c 'cd Linux && LTO=0 AUDIT=0 STATIC_LIBBPF=0 ./build.sh'+ shell: bash++ - name: SonarQube Scan+ uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0+ env:+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}+ with:+ projectBaseDir: Linux+ args: >+ -Dsonar.cfamily.compile-commands=${{ github.workspace }}/bw-output/compile_commands.json++ macos:+ # Swift is analysed from the sources and needs no build, so an ordinary Linux runner is enough (macOS runners cost+ # far more). The job is named after the platform it covers.+ name: Analyze (macOS)+ runs-on: ubuntu-latest+ timeout-minutes: 30+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository+ steps:+ - name: Checkout+ uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1+ with:+ fetch-depth: 0++ - name: Cache SonarQube packages+ uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0+ with:+ path: ~/.sonar/cache+ key: ${{ runner.os }}-sonar+ restore-keys: ${{ runner.os }}-sonar++ - name: SonarQube Scan+ uses: SonarSource/sonarqube-scan-action@d209202bc7d53ff1cc128f7f907dac145c9d6ae9 # v8.3.0+ env:+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}+ with:+ projectBaseDir: MacOSdiff --git a/Linux/sonar-project.properties b/Linux/sonar-project.propertiesnew file mode 100644index 0000000..9bb9942--- /dev/null+++ b/Linux/sonar-project.properties@@ -0,0 +1,12 @@+sonar.projectKey=InterceptSuite_ProxyBridge_Linux+sonar.organization=interceptsuite+sonar.projectName=ProxyBridge (Linux)+sonar.sourceEncoding=UTF-8++# Everything under Linux/ is analysed; the unit-test and benchmark programs in the tests folders are test code.+sonar.sources=.+sonar.tests=.+sonar.exclusions=**/tests/**, **/out/**, **/build/**, **/obj/**, **/third_party/**+sonar.test.inclusions=**/tests/**++# C is analysed from the gcc/clang compiler calls recorded by the Build Wrapper (.github/workflows/sonarqube.yml).diff --git a/MacOS/sonar-project.properties b/MacOS/sonar-project.propertiesnew file mode 100644index 0000000..e8f826a--- /dev/null+++ b/MacOS/sonar-project.properties@@ -0,0 +1,10 @@+sonar.projectKey=InterceptSuite_ProxyBridge_macOS+sonar.organization=interceptsuite+sonar.projectName=ProxyBridge (macOS)+sonar.sourceEncoding=UTF-8++# Swift is analysed from the sources, no build is needed. The logic tests and the test tool are test code.+sonar.sources=.+sonar.tests=.+sonar.exclusions=**/tests/**, **/.build/**, **/build/**, **/DerivedData/**, **/*.xcodeproj/**+sonar.test.inclusions=**/tests/**diff --git a/Windows/sonar-project.properties b/Windows/sonar-project.propertiesnew file mode 100644index 0000000..e85c965--- /dev/null+++ b/Windows/sonar-project.properties@@ -0,0 +1,10 @@+sonar.projectKey=InterceptSuite_ProxyBridge_Windows+sonar.organization=interceptsuite+sonar.projectName=ProxyBridge (Windows)+sonar.sourceEncoding=UTF-8++# Product code: the engine and service, the CLI and the native GUI. The test programs are reported as test code.+sonar.sources=src,cli,gui+sonar.tests=tests++# C is analysed from the MSVC compiler calls recorded by the Build Wrapper (.github/workflows/sonarqube.yml).