synqro 0.1.1

Synqro Zero-Trust OTA updater library
Documentation
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# .github/workflows/ci.yml
# Synqro — Continuous Integration
# Runs on every push, pull request, and can be called from release.yml.

name: CI

on:
  push:
    branches: ["**"]
  pull_request:
    branches: ["**"]
  workflow_call: {}   # Allows release.yml to invoke all CI checks as a gate

# Cancel in-progress runs for the same branch/PR to save compute.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  RUST_BACKTRACE: 1
  CARGO_TERM_COLOR: always
  RUSTUP_TOOLCHAIN: "stable"

jobs:

  # ─────────────────────────────────────────────────────────────
  # JOB 1: audit
  # Runs cargo-audit and cargo-deny to check for known
  # vulnerabilities and license / source policy violations.
  # ─────────────────────────────────────────────────────────────
  audit:
    name: Security Audit (cargo-audit + cargo-deny)
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      security-events: write

    steps:
      - name: Checkout source
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUSTUP_TOOLCHAIN }}

      - name: Cache Cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            ~/.cargo/git/db
          key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-registry-${{ runner.os }}-

      - name: Install cargo-audit
        run: cargo install cargo-audit --locked --version =0.20.0

      - name: Install cargo-deny
        run: cargo install cargo-deny --locked --version =0.16.1

      - name: Run cargo-audit
        run: cargo audit --deny warnings --json > audit-report.json

      - name: Diagnostic dump (cargo-audit) on failure
        if: failure()
        run: |
          cargo audit --deny warnings 2>&1 | tail -80 | while IFS= read -r line; do
            echo "::error::AUDIT: ${line}"
          done

      - name: Upload audit report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: audit-report-${{ github.run_id }}
          path: audit-report.json
          retention-days: 90

      - name: Run cargo-deny
        run: cargo deny check

      - name: Diagnostic dump (cargo-deny) on failure
        if: failure()
        run: |
          cargo deny check 2>&1 | tail -80 | while IFS= read -r line; do
            echo "::error::DENY: ${line}"
          done

  # ─────────────────────────────────────────────────────────────
  # JOB 2: lint
  # Enforces code formatting and Clippy lints.
  # ─────────────────────────────────────────────────────────────
  lint:
    name: Lint (rustfmt + clippy)
    runs-on: ubuntu-24.04
    permissions:
      contents: read

    steps:
      - name: Checkout source
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install Rust toolchain with rustfmt and clippy
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUSTUP_TOOLCHAIN }}
          components: rustfmt, clippy

      - name: Cache Cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            ~/.cargo/git/db
          key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-registry-${{ runner.os }}-

      - name: Cache build artifacts
        uses: actions/cache@v4
        with:
          path: target/
          key: cargo-build-${{ runner.os }}-${{ env.RUSTUP_TOOLCHAIN }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-build-${{ runner.os }}-${{ env.RUSTUP_TOOLCHAIN }}-

      - name: Check formatting (rustfmt)
        run: cargo fmt --all -- --check

      - name: Run Clippy
        run: >
          cargo clippy --all-targets --all-features --
          -D warnings
          -D clippy::unwrap_used
          -D clippy::expect_used
          -D clippy::panic
          -D clippy::indexing_slicing
          -D clippy::arithmetic_side_effects
          -D clippy::pedantic
          -A clippy::module_name_repetitions

  # ─────────────────────────────────────────────────────────────
  # JOB 3: test
  # Runs the full test suite on all three major platforms.
  # ─────────────────────────────────────────────────────────────
  test:
    name: Test (${{ matrix.os }})
    needs: [lint]
    runs-on: ${{ matrix.os }}
    permissions:
      contents: read
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04, macos-14, windows-2022]

    steps:
      - name: Checkout source
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUSTUP_TOOLCHAIN }}

      - name: Cache Cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            ~/.cargo/git/db
          key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-registry-${{ runner.os }}-

      - name: Cache build artifacts
        uses: actions/cache@v4
        with:
          path: target/
          key: cargo-build-${{ runner.os }}-${{ env.RUSTUP_TOOLCHAIN }}-test-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-build-${{ runner.os }}-${{ env.RUSTUP_TOOLCHAIN }}-

      - name: Run tests
        env:
          TEST_LOG: synqro=debug
        run: cargo test --locked --all-features -- --nocapture

      - name: Diagnostic dump (cargo test) on failure
        if: failure()
        shell: bash
        run: |
          cargo test --locked --all-features -- --nocapture 2>&1 | tail -100 | while IFS= read -r line; do
            echo "::error::TEST[${{ matrix.os }}]: ${line}"
          done

      - name: Run doc tests
        run: cargo test --locked --doc --all-features

      - name: Diagnostic dump (doc tests) on failure
        if: failure()
        shell: bash
        run: |
          cargo test --locked --doc --all-features 2>&1 | tail -60 | while IFS= read -r line; do
            echo "::error::DOCTEST[${{ matrix.os }}]: ${line}"
          done

  # ─────────────────────────────────────────────────────────────
  # JOB 4: build (reproducible build verification)
  # Builds release binaries twice per target and compares hashes.
  # ─────────────────────────────────────────────────────────────
  build:
    name: Build (${{ matrix.target }}, run ${{ matrix.build_run }})
    needs: [audit, lint]
    runs-on: ${{ matrix.runner }}
    permissions:
      contents: read
    env:
      SOURCE_DATE_EPOCH: "0"
      CARGO_INCREMENTAL: "0"
      RUSTFLAGS: "-C metadata=SYNQRO_REPRO -C link-arg=-Wl,--build-id=none"
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-musl
            runner: ubuntu-24.04
            build_run: 1
          - target: x86_64-unknown-linux-musl
            runner: ubuntu-24.04
            build_run: 2
          - target: aarch64-unknown-linux-musl
            runner: ubuntu-24.04
            build_run: 1
          - target: aarch64-unknown-linux-musl
            runner: ubuntu-24.04
            build_run: 2
          - target: x86_64-apple-darwin
            runner: macos-14
            build_run: 1
          - target: x86_64-apple-darwin
            runner: macos-14
            build_run: 2
          - target: aarch64-apple-darwin
            runner: macos-14
            build_run: 1
          - target: aarch64-apple-darwin
            runner: macos-14
            build_run: 2
          - target: x86_64-pc-windows-msvc
            runner: windows-2022
            build_run: 1
          - target: x86_64-pc-windows-msvc
            runner: windows-2022
            build_run: 2

    steps:
      - name: Checkout source
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install Rust toolchain + target
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUSTUP_TOOLCHAIN }}
          targets: ${{ matrix.target }}

      - name: Install cross-compilation tools (Linux)
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update -qq
          sudo apt-get install -y --no-install-recommends \
            musl-tools \
            gcc-aarch64-linux-gnu

      - name: Cache Cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            ~/.cargo/git/db
          key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-registry-${{ runner.os }}-

      - name: Build release binary
        run: >
          cargo build
          --locked
          --release
          --target ${{ matrix.target }}

      - name: Compute SHA-256 (Linux/macOS)
        if: runner.os != 'Windows'
        run: |
          BIN="target/${{ matrix.target }}/release/synqro"
          HASH=$(sha256sum "${BIN}" | awk '{print $1}')
          echo "BINARY_SHA256=${HASH}" >> "${GITHUB_ENV}"

      - name: Compute SHA-256 (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          $hash = (Get-FileHash -Algorithm SHA256 "target\${{ matrix.target }}\release\synqro.exe").Hash.ToLower()
          "BINARY_SHA256=$hash" | Out-File -FilePath $env:GITHUB_ENV -Append

      - name: Write SHA-256 to file (Linux/macOS)
        if: runner.os != 'Windows'
        run: echo "${{ env.BINARY_SHA256 }}" > sha256-${{ matrix.target }}-run${{ matrix.build_run }}.txt

      - name: Write SHA-256 to file (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          "${{ env.BINARY_SHA256 }}" | Out-File -FilePath "sha256-${{ matrix.target }}-run${{ matrix.build_run }}.txt" -NoNewline

      - name: Upload SHA-256 file
        uses: actions/upload-artifact@v4
        with:
          name: sha256-${{ matrix.target }}-run${{ matrix.build_run }}-${{ github.run_id }}
          path: sha256-${{ matrix.target }}-run${{ matrix.build_run }}.txt

      - name: Upload binary (run 1 only, for release job)
        if: matrix.build_run == 1
        uses: actions/upload-artifact@v4
        with:
          name: binary-${{ matrix.target }}-${{ github.run_id }}
          path: |
            target/${{ matrix.target }}/release/synqro
            target/${{ matrix.target }}/release/synqro.exe
          if-no-files-found: ignore
          retention-days: 7

  # ─────────────────────────────────────────────────────────────
  # JOB 4b: compare-reproducibility
  # Downloads both SHA-256 files per target and verifies they match.
  # ─────────────────────────────────────────────────────────────
  compare-reproducibility:
    name: Verify Reproducible Build (${{ matrix.target }})
    needs: [build]
    runs-on: ubuntu-24.04
    permissions:
      contents: read
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-musl
          - aarch64-unknown-linux-musl
          - x86_64-apple-darwin
          - aarch64-apple-darwin
          - x86_64-pc-windows-msvc

    steps:
      - name: Download SHA-256 from run 1
        uses: actions/download-artifact@v4
        with:
          name: sha256-${{ matrix.target }}-run1-${{ github.run_id }}
          path: hashes/

      - name: Download SHA-256 from run 2
        uses: actions/download-artifact@v4
        with:
          name: sha256-${{ matrix.target }}-run2-${{ github.run_id }}
          path: hashes/

      - name: Compare hashes
        run: |
          HASH1=$(cat "hashes/sha256-${{ matrix.target }}-run1.txt")
          HASH2=$(cat "hashes/sha256-${{ matrix.target }}-run2.txt")
          echo "Run 1 SHA-256: ${HASH1}"
          echo "Run 2 SHA-256: ${HASH2}"
          if [ "${HASH1}" != "${HASH2}" ]; then
            echo "::error::Reproducible build FAILED for ${{ matrix.target }}"
            exit 1
          fi
          echo "Reproducible build PASSED for ${{ matrix.target }}."

  # ─────────────────────────────────────────────────────────────
  # JOB 5: sast-python
  # Runs Bandit static analysis on Python scripts and reporter.
  # ─────────────────────────────────────────────────────────────
  sast-python:
    name: Python SAST (Bandit)
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      security-events: write

    steps:
      - name: Checkout source
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Set up Python 3.12
        uses: actions/setup-python@v5
        with:
          python-version: "3.12.3"

      - name: Install Bandit
        run: pip install bandit==1.7.9

      - name: Run Bandit
        run: |
          bandit \
            -r scripts/ synqro/reporter/ \
            -ll \
            -f json \
            -o bandit-report.json \
            || true

      - name: Upload Bandit report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: bandit-report-${{ github.run_id }}
          path: bandit-report.json
          retention-days: 90

      - name: Fail on HIGH or CRITICAL findings
        run: |
          python3 - <<'PYEOF'
          import json, sys
          with open("bandit-report.json") as f:
              report = json.load(f)
          findings = [
              r for r in report.get("results", [])
              if r.get("issue_severity", "").upper() in ("HIGH", "CRITICAL")
          ]
          if findings:
              print(f"FAIL: {len(findings)} HIGH/CRITICAL finding(s):")
              for r in findings:
                  print(f"  [{r['issue_severity']}] {r['issue_text']} at {r['filename']}:{r['line_number']}")
              sys.exit(1)
          print("PASS: No HIGH or CRITICAL Bandit findings.")
          PYEOF

  # ─────────────────────────────────────────────────────────────
  # JOB 6: sbom
  # Generates a CycloneDX SBOM and signs it with Ed25519.
  # ─────────────────────────────────────────────────────────────
  sbom:
    name: Generate & Sign SBOM (CycloneDX)
    needs: [audit]
    runs-on: ubuntu-24.04
    permissions:
      contents: read

    steps:
      - name: Checkout source
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUSTUP_TOOLCHAIN }}

      - name: Cache Cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            ~/.cargo/git/db
          key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            cargo-registry-${{ runner.os }}-

      - name: Install cargo-cyclonedx
        run: cargo install cargo-cyclonedx --locked --version =0.5.5

      - name: Generate SBOM
        run: cargo cyclonedx --format json --output-file synqro-sbom.cdx.json

      - name: Sign SBOM with Ed25519
        env:
          SYNQRO_SIGNING_KEY: ${{ secrets.SYNQRO_SIGNING_KEY }}
          SYNQRO_SIGNING_KEY_PUB: ${{ secrets.SYNQRO_SIGNING_KEY_PUB }}
        run: |
          mkdir -p /dev/shm/synqro_ci_signing && chmod 700 /dev/shm/synqro_ci_signing
          echo "${SYNQRO_SIGNING_KEY}" | base64 -d > /dev/shm/synqro_ci_signing/key.pem

          openssl pkeyutl \
            -sign \
            -inkey /dev/shm/synqro_ci_signing/key.pem \
            -rawin \
            -in synqro-sbom.cdx.json \
            | base64 --wrap=0 > synqro-sbom.cdx.json.sig

          echo "${SYNQRO_SIGNING_KEY_PUB}" | base64 -d > /dev/shm/synqro_ci_signing/pub.pem
          openssl pkeyutl \
            -verify \
            -pubin \
            -inkey /dev/shm/synqro_ci_signing/pub.pem \
            -rawin \
            -in synqro-sbom.cdx.json \
            -sigfile <(cat synqro-sbom.cdx.json.sig | base64 -d)

          shred -u /dev/shm/synqro_ci_signing/key.pem /dev/shm/synqro_ci_signing/pub.pem
          rmdir /dev/shm/synqro_ci_signing

      - name: Upload SBOM and signature
        uses: actions/upload-artifact@v4
        with:
          name: sbom-${{ github.run_id }}
          path: |
            synqro-sbom.cdx.json
            synqro-sbom.cdx.json.sig
          retention-days: 365