Explorar o código

Add upstream contribution drafts; generalize sandbox patch

- work/contrib/: ready-to-paste drafts for uunicorn/wine (modern-toolchain
  build fixes), uunicorn/synaWudfBioUsb-sandbox (argv dispatch + match exit
  status) and rstar000/synaTudor (progress + capture-ioctl forensics), plus
  submission mechanics in work/contrib/README.md
- uunicorn-sandbox-argv-dispatch.patch: detect a returned identify record by
  its non-zero type/size header instead of matching our specific payload, so
  the patch is generic for upstream
Johannes Zellner hai 1 mes
pai
achega
8b23cb756d

+ 68 - 0
work/contrib/01-uunicorn-wine-modern-toolchain.md

@@ -0,0 +1,68 @@
+# Draft: uunicorn/wine — modern-toolchain build fixes
+
+**Where:** https://github.com/uunicorn/wine (branch `hacking/validiy-sensor`)
+**Type:** PR against the branch (or issue with the patch attached)
+**Attach:** `work/patches/uunicorn-wine-modern-toolchain.patch` (vs commit `7a69a82`)
+
+---
+
+## Title
+
+Build fixes for modern toolchains (GCC 14+, GnuTLS 3.8, OpenSSL 3) + working configure recipe
+
+## Body
+
+Hi! I built this fork on a current distro (Arch, x86_64) instead of the
+Docker image and had to fix a handful of toolchain-drift errors. With the
+attached patch + the recipe below, the full build completes and the winusb
+stub works end-to-end — I used it to enroll and verify fingerprints against
+a real Synaptics **06cb:0081** (Lenovo YOGA 720-13IKB) via
+synaWudfBioUsb-sandbox. 
+
+**Environment:** gcc 16.2.1, gnutls 3.8.13, openssl 3.6.5,
+x86_64-w64-mingw32-gcc 16.2.0 (PE side), base commit `7a69a82`.
+
+### Fixes in the patch
+
+1. **`dlls/bcrypt/gnutls.c`** — pointer depth with
+   `gnutls_privkey_export_ecc_raw`. GCC 14+ promotes
+   `-Wincompatible-pointer-types` to an error:
+   `gnutls.c:1034:65: error: passing argument 2 of 'pgnutls_privkey_export_ecc_raw' from incompatible pointer type`
+   → pass `curve` (not `&curve`).
+
+2. **`dlls/bcrypt/secrets.c`**
+   - `ECDSA_SIG_get0` takes `const BIGNUM **` with OpenSSL 3:
+     `secrets.c:242:26: error: passing argument 2 of 'pECDSA_SIG_get0' from incompatible pointer type`
+   - `get_gnutls_ecc_key_params` (defined in gnutls.c) needs a declaration —
+     `implicit-function-declaration` is a hard error since GCC 14.
+
+3. **`dlls/crypt32/crypt32_private.h`** — `HINSTANCE hInstance` needs
+   `extern`; `-fno-common` is default since GCC 10 (hits as
+   "multiple definition of `hInstance`").
+
+### Additional build-level accommodations
+
+- C23 `bool` is now a keyword, which collides with old code using `bool` as a
+  struct/union member name (`dlls/msi/cond.y`, `programs/winhlp32/macro.h`).
+  Neutralized with `-Dbool=winbool_field` in CFLAGS; alternatively disable
+  those modules (`--disable-msi --disable-winhlp32`).
+- `-fcommon` keeps the old global-tentative-definition behavior (the
+  crypt32 fix above is the surgical version of the same issue).
+
+### Recipe that works
+
+```sh
+./configure --enable-win64 --with-gnutls --without-x --disable-tests \
+  --without-freetype --without-fontconfig --without-capi --without-dbus \
+  --without-oss --without-alsa --without-cups --without-sane --without-v4l \
+  --without-pcap --without-ldap --without-xml --without-xslt --without-mscms \
+  --disable-wmic --disable-winedbg --disable-winhlp32 \
+  CFLAGS='-g -O2 -Wno-error -fcommon -Dbool=winbool_field'
+make -j$(nproc) && make install
+```
+
+(The `--disable-wmic/--disable-winedbg/--disable-winhlp32` flags can be
+dropped once the `bool` workaround is in place; they just avoid unrelated
+legacy tool breakage. `mingw-w64-gcc` is required for the PE side.)
+
+Happy to split this up or adjust naming/style for the branch — let me know!

+ 53 - 0
work/contrib/02-uunicorn-sandbox-argv-dispatch.md

@@ -0,0 +1,53 @@
+# Draft: uunicorn/synaWudfBioUsb-sandbox — argv dispatch + match exit status
+
+**Where:** https://github.com/uunicorn/synaWudfBioUsb-sandbox
+**Type:** PR
+**Attach:** `work/patches/uunicorn-sandbox-argv-dispatch.patch` (applies to `hello.cc` HEAD)
+
+---
+
+## Title
+
+Enable the documented `nop|identify|enroll` dispatch and return a match exit status
+
+## Body
+
+Two small improvements to `hello.cc`:
+
+**1. The README documents `./run.sh [ nop | identify | enroll ]`, but the
+dispatch in `main()` is `#if 0`'d and the flow is hardcoded to `enroll()` +
+`identify()`.** As a result `nop` and `identify` currently perform a full
+re-enrollment (10 finger captures) before identifying. The patch enables the
+existing dispatch so:
+
+- `identify` → `setMode(2)` + `identify()` only — a true verify-only run
+- `enroll`  → `enroll()` + (existing 10s pause) + `identify()`, as before
+- `nop`     → nothing extra
+- any other/no argument → usage + exit 3
+
+**2. Return a match status.** `identify()` / `identifyFeatureSet()` now return
+an int and `main()` exits `0` when the sensor returns an identify record and
+`1` on no-match, so the binary can be used from scripts/PAM wrappers.
+
+How match/no-match look (verified against a real 06cb:0081 via the
+`0x442004` IdentifyFeatureSet ioctl):
+
+- **match**: the stored record comes back with a non-zero type/size header
+  (e.g. starts `03 00 00 00 1c 00 00 00 …`)
+- **no match**: the structure is zeroed (only a WinBio error dword further in),
+  i.e. first bytes are `00 00 00 00 …`
+
+The patch detects a record via a non-zero header (first 8 bytes) rather than
+any payload-specific match, so it works for any enrolled identity.
+
+**Testing caveat:** I could not compile it here (the project needs the WDK
+`winbio_*.h` / WDF headers as per the README). I validated the behavior by
+binary-patching the prebuilt `a.exe` instead (NOP out `call enroll`,
+`Sleep(10000)` → `Sleep(0)`) and running verify-only against real hardware —
+that flow works. The source patch is mechanical, but please compile-test
+before merging.
+
+**Why it matters:** verify-only runs are what you want for authentication
+use-cases (e.g. a PAM module for sudo/login) — re-enrolling on every check
+makes the "identify" mode unusable for that. With this patch, `a.exe identify`
+is directly scriptable.

+ 62 - 0
work/contrib/03-rstar000-synaTudor-progress.md

@@ -0,0 +1,62 @@
+# Draft: rstar000/synaTudor — 06cb:0081 progress + capture-ioctl crash forensics
+
+**Where:** https://github.com/rstar000/synaTudor (upstream: Popax21/synaTudor — feel free to forward)
+**Type:** issue (progress report + question; patch set attached)
+**Attach:** `work/patches/synaTudor-work.patch` (vs commit `994c6ba`)
+
+---
+
+## Title
+
+06cb:0081 (Lenovo YOGA 720-13IKB): init, command loop and datastore work — capture ioctl crashes on a NULL dispatch-map entry
+
+## Body
+
+I picked up this project for a **06cb:0081** (Validity-family "Tudor" sensor,
+Lenovo YOGA 720-13IKB, WBDI driver 5.5.2731.1050) and got substantially
+further than the previous state, but I'm now stuck in the driver's capture
+path on something I suspect the host must populate. Sharing in case it helps
+anyone else — and happy to hear ideas.
+
+**What works now** (patch set attached, 12 files):
+
+- Driver init: `Attach` → `Reset` → `QueryStatus` (status `0x5` =
+  NOT_CALIBRATED until calibration is triggered)
+- Command loop + datastore round-trip (`tudor_cli` reaches its prompt)
+- USB protocol, TLS handshake, firmware handshake all functional
+
+Main fixes: accurate `WINBIO_SENSOR_INTERFACE_V1` table layout (15 slots:
+Attach, Detach, ClearContext, QueryStatus, Reset, SetMode, SetIndicatorStatus,
+GetIndicatorStatus, StartCapture, FinishCapture, ExportSensorData, Cancel,
+PushDataToEngine, ControlUnit, ResetOwnership — no PipelineInit/Activate),
+whole-table restore from pristine RVAs, well-formed empty CalibrationData
+PROPVARIANT, re-acquire across USB re-enumeration, correct
+`tudor_devctrl_wudf1` completion semantics, ~30 output-pointer fixes in the
+WUDF methods, AssignContext/RetrieveContext, live factory objects.
+
+**The blocker** — capture ioctl `0x44202c` crashes at driver offset
+`0x34314` (call chain `0x36b00 → 0x36cd9 → 0x34360 → 0x3414c`) dereferencing
+a NULL at `[ctx+0x1c0]`.
+
+Forensics:
+
+- `[ctx+0x1a0..0x1e8]` looks like an MSVC container layout
+  (`{data-ptr, …, count=2, 0x30}`); `[ctx+0x1c0]` is element 4/notional index
+  and the driver indexes into it for the capture entry, then dereferences the
+  element's vtable (`+0x38`).
+- The three writers of that field I could identify (`0x199d2`, `0x1cc61`,
+  `0x6ea49`) never execute under my host.
+- Host vtables match the official UMDF 1.1x `wudfddi.h` interfaces, and the
+  driver only implements `IPnpCallbackHardware` + `IPnpCallback`.
+
+**Hypothesis:** this is a dispatch/handler map built during device-interface
+setup (`CreateDeviceInterface` / `AssignDeviceInterfaceState` / io-queue
+creation), and my host's no-op interface handling leaves the capture entry
+NULL. Guidance on what the UMDF host does at interface activation that fills
+this map would be very welcome.
+
+**Workaround, for context:** the same sensor fully works under
+uunicorn/rstar000's Wine-sandbox approach (vendor Windows driver + a hacked
+Wine 4.8 with a fake libusb-backed winusb): full enroll + verify, currently
+wired into PAM for sudo. A native solution would still be much better (no
+Wine), so I'd love to see this unlocked.

+ 41 - 0
work/contrib/README.md

@@ -0,0 +1,41 @@
+# Upstream contribution drafts
+
+Ready-to-paste GitHub drafts for giving something back to the projects this
+setup builds on. Each `.md` file contains the **title** and **body**; the
+patch to attach lives in `../patches/`.
+
+| Draft | Target | Patch to attach |
+|---|---|---|
+| `01-uunicorn-wine-modern-toolchain.md` | [uunicorn/wine](https://github.com/uunicorn/wine) branch `hacking/validiy-sensor` | `../patches/uunicorn-wine-modern-toolchain.patch` |
+| `02-uunicorn-sandbox-argv-dispatch.md` | [uunicorn/synaWudfBioUsb-sandbox](https://github.com/uunicorn/synaWudfBioUsb-sandbox) | `../patches/uunicorn-sandbox-argv-dispatch.patch` |
+| `03-rstar000-synaTudor-progress.md` | [rstar000/synaTudor](https://github.com/rstar000/synaTudor) (upstream: [Popax21/synaTudor](https://github.com/Popax21/synaTudor)) | `../patches/synaTudor-work.patch` |
+
+## How to submit
+
+**PRs (01, 02)** — GitHub's web UI can't attach arbitrary `.patch` files to a
+PR; the clean way is:
+
+1. Fork the target repo; clone your fork.
+2. Apply the patch and commit(s):
+   ```sh
+   git checkout -b fix/modern-toolchain   # or: feature/argv-dispatch
+   git apply /home/nebulon/projects/fingerprint/work/patches/<patch>
+   git add -A && git commit -m "<short message>"
+   git push -u origin fix/modern-toolchain
+   ```
+   (For `01-uunicorn-wine`, open the PR against the `hacking/validiy-sensor`
+   branch of uunicorn/wine.)
+3. Paste the draft title/body into the PR form. The patch text is also handy
+   as a fallback for an issue ("patch attached below" + paste the diff).
+
+**Issue (03)** — create the issue in rstar000/synaTudor and drag & drop
+`../patches/synaTudor-work.patch` into the description box (GitHub issues
+accept file attachments).
+
+## Notes
+
+- None of the drafts are submitted yet; review/edit the wording first.
+- `02` is honest about not being compile-tested (WDK headers needed); `01`
+  and `03` were exercised on real 06cb:0081 hardware, respectively via a full
+  verify run (03: the native route remains blocked by the dispatch-map NULL).
+- Our own repo notes the same content in `README.md` → "Contributing back".

+ 19 - 21
work/patches/uunicorn-sandbox-argv-dispatch.patch

@@ -1,5 +1,5 @@
 diff --git a/hello.cc b/hello.cc
-index b1a095c..3222033 100644
+index b1a095c..4ac10d0 100644
 --- a/hello.cc
 +++ b/hello.cc
 @@ -1489,7 +1489,7 @@ operator << (std::basic_ostream<wchar_t> &os, WINBIO_REGISTERED_FORMAT r)
@@ -11,20 +11,18 @@ index b1a095c..3222033 100644
  identifyFeatureSet()
  {
      //char ibuf[0x2000] = { 0 };
-@@ -1507,9 +1507,19 @@ identifyFeatureSet()
+@@ -1507,9 +1507,17 @@ identifyFeatureSet()
      for(LONG_PTR i=0;i<req.informationSize;i++)
          printf("%02x", obuf[i]);
      printf("\n");
 +
-+    /* verify-only flow: did the enrolled record come back? */
-+    for(LONG_PTR i=0;i+7<=req.informationSize;i++) {
-+        if(memcmp(obuf+i, "Unicorn", 7) == 0) {
-+            printf("MATCH: enrolled record found\n");
-+            return 0;
-+        }
-+    }
-+    printf("NO MATCH\n");
-+    return 1;
++    /* A sensor match returns the stored identify record; a no-match result is
++       a zeroed structure (only a WinBio error dword further in is set).
++       Detect a record by its non-zero type/size header. */
++    int matched = req.informationSize >= 8 && (obuf[0] | obuf[1] | obuf[2] | obuf[3] |
++                                               obuf[4] | obuf[5] | obuf[6] | obuf[7]);
++    printf(matched ? "MATCH: identify record found\n" : "NO MATCH\n");
++    return matched ? 0 : 1;
  }
  
 -void
@@ -32,7 +30,7 @@ index b1a095c..3222033 100644
  identify()
  {
      char ibuf[1024*10];
-@@ -1595,7 +1605,7 @@ identify()
+@@ -1595,7 +1603,7 @@ identify()
              printf("sz=%lld\n", (PUCHAR)(hdr+1) - data->CaptureData.Data);
          }
      }
@@ -41,7 +39,7 @@ index b1a095c..3222033 100644
  }
  
  void
-@@ -1646,7 +1656,7 @@ reset()
+@@ -1646,7 +1654,7 @@ reset()
      printf("\r\n");
  }
  
@@ -50,7 +48,7 @@ index b1a095c..3222033 100644
  enroll()
  {
      Sleep(500);
-@@ -1749,6 +1759,8 @@ enroll()
+@@ -1749,6 +1757,8 @@ enroll()
      Sleep(1000);
  
      commitEnrollment();
@@ -59,7 +57,7 @@ index b1a095c..3222033 100644
  }
  
  void
-@@ -2398,9 +2410,10 @@ struct breakpoint breakpoints[] = {
+@@ -2398,9 +2408,10 @@ struct breakpoint breakpoints[] = {
      { "00000001800D8C34", (unsigned char *)0x00000001800D8C34, handle_export_out },
  };
  
@@ -71,7 +69,7 @@ index b1a095c..3222033 100644
  }
  
  void
-@@ -2414,10 +2427,9 @@ int
+@@ -2414,10 +2425,9 @@ int
  main(int argc, char *argv[])
  {
      char *br = getenv("SANDBOX_BREAKPOINTS");
@@ -83,7 +81,7 @@ index b1a095c..3222033 100644
      if(argc != 2) {
          usage();
          return 3;
-@@ -2436,7 +2448,6 @@ main(int argc, char *argv[])
+@@ -2436,7 +2446,6 @@ main(int argc, char *argv[])
          usage();
          return 3;
      }
@@ -91,7 +89,7 @@ index b1a095c..3222033 100644
  
      HMODULE pDll = LoadLibrary("synawudfbiousb.dll");
      if(!pDll) {
-@@ -2542,16 +2553,26 @@ main(int argc, char *argv[])
+@@ -2542,16 +2551,26 @@ main(int argc, char *argv[])
  
      setMode(2); // WINBIO_SENSOR_ADVANCED_MODE
  
@@ -106,13 +104,13 @@ index b1a095c..3222033 100644
 +
 +    if(what == enroll) {
 +        enroll();
- 
--    identify();
++
 +        printf("======================================================\r\n");
 +        printf("Sleeping 10 secons....\r\n");
 +        printf("======================================================\r\n");
 +        Sleep(10000);
-+
+ 
+-    identify();
 +        status = identify();
 +    }
 +    else if(what == identify) {