Skip to content

Implement browser PKCE authentication prototype - #60

Open
sultandevin wants to merge 3 commits into
mainfrom
feat/browser-auth
Open

sultandevin wants to merge 3 commits into
mainfrom
feat/browser-auth

Conversation

@sultandevin

@sultandevin sultandevin commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

auth login
├── CLI opens the browser and receives the loopback callback
└── auth validates state and the ID token, then saves the session
    ├── auth status reads local session metadata
    └── auth logout removes the local keyring entry
└── web login (--method web, or auto without SIMASTER_CLIENT_ID)
    ├── direct service_login, then CAS fallback with the lt token
    └── CAPTCHA loop: up to five challenges, fresh token per retry
        ├── image challenges classified with the ddddocr model
        │   (downloaded once into the cache, SHA-256 pinned)
        └── audio challenges, model misses, and rejected
            answers escalate to the terminal prompt

The Rust feature interface is reusable by future SDK and MCP callers.

This also retires the documented non-goal on programmatic CAPTCHA solving for
the user's own login; a standalone CAPTCHA-solving service remains a non-goal
(AGENTS.md, docs/AUTH.md, and the OpenAPI evidence for
captchasound_verification updated accordingly).

Closes #59. Refs #35 and #36.

Evidence

  • Before: auth login, status, and logout returned "not implemented."
  • After: the CLI login flow completed against mocked discovery, token, and JWKS endpoints with a signed ID token. The test checked the PKCE form, rejected invalid state and tokens, and confirmed local status and logout.
  • Web login plus reuse covered by mocked direct and CAS flows; a rejected CAPTCHA retries with the fresh simasterUGM token from the re-presented page and escalates to the human answer; a session-lost redirect fails the login.
  • OCR: the ddddocr common.onnx (MIT, from upstream sml2h3/ddddocr, sha256 33b5cd351ee94e73a6bf8fa18c415ed8b819b3ffd342e267c30d8ad8334e34e8) is downloaded once on the first image challenge into the platform cache directory, verified against that checksum, and reused offline. A cold run fetched, cached, and classified a rendered four-digit fixture as 1234 in 5.9 s. No model bytes are committed. The classic common_old.onnx quantizes a DynamicQuantizeLSTM that the pure-Rust tract backend cannot run, so upstream's current f32 graph is used.
  • MSRV bumped 1.85 → 1.92 (Cargo.toml, CI msrv job, README badge, CONTRIBUTING, PR template, dependabot note); cargo +1.92.0 check --all-features verified locally because the ddddocr/tract dependency tree declares 1.88–1.91.
  • Live test against SIMASTER (own account, web method): direct password login established a session, auth status reported the account, and session reuse reached the dashboard after clearing the cookie jar. No CAPTCHA was presented on this account, so the challenge loop stays covered by mocks.
  • The CAPTCHA classifier was checked against 10 real challenge images served by the portal: 10/10 returned six digits, and two were read by eye from a rendered preview and matched the classifier's output exactly.
  • Live testing found and fixed a TLS defect: sso.ugm.ac.id completes a handshake only with TLS 1.2 + CBC suites (TLS 1.3 and AES-GCM are both dropped mid-handshake), and rustls implements no CBC suites, so the CAS fallback could never connect and surfaced as a network error. The web login client now uses the platform TLS stack (OpenSSL gets 200 from CAS; verified); UGM ID PKCE keeps rustls. CAS re-rendering its sign-in form now reports rejected credentials (exit 3) instead of asking for a browser.
  • I also ran the built CLI to check login help and the missing-client exit code.
  • Local checks: cargo test --locked --all-features, format, Clippy, and cargo deny check (NCSA added for libfuzzer-sys, pulled by image's avif feature under ddddocr defaults).

Merge Danger

Door: Two-way.

Blast radius: Authentication, local credential storage, a new platform-TLS (OpenSSL) build dependency for the web client, and a new first-use download (~54 MiB) from upstream GitHub into the user cache directory. Not a one-way door: the feature reverts cleanly and commits no large binary. The download is SHA-256 pinned, is skipped entirely unless a CAPTCHA appears, and a failure falls back to the human prompt. The prototype requires an OS keyring. Authenticated UGM verification still requires a DTI-registered public client.

Add the web feature: direct service login, CAS fallback with the lt token,
and keyring-stored web sessions reused by auth status and removed by auth
logout. The CLI adapter moves into the binary and keeps feature modules in
the library.

CAPTCHA challenges follow the prior-art client loop: up to five challenges,
each fetched with an _= cache buster, answered, and retried with a fresh
simasterUGM token from the re-presented page. Image challenges are classified
with the ddddocr model, downloaded once into the cache directory and verified
against a pinned SHA-256; audio challenges, model misses, and rejected answers
escalate to the human at the terminal, and session-lost redirects fail the
login. Programmatic solving for the user's own login retires the documented
non-goal; standalone solving for others stays out of scope.

Raises the MSRV to 1.92, which the ddddocr and tract dependency tree needs.
Live testing against SIMASTER found that sso.ugm.ac.id completes a handshake
only with TLS 1.2 and CBC cipher suites: TLS 1.3 and AES-GCM are both dropped
mid-handshake. rustls implements no CBC suites, so the CAS fallback could
never connect and surfaced as a network error.

Switch only the web client to native TLS. Also report CAS re-rendering its
sign-in form as a rejected-credentials error instead of asking for a browser.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature-sliced Rust library for CLI, SDK, and MCP

1 participant