Skip to main content

hyprstream_core/services/oauth/
wit_bootstrap.rs

1//! Browser WIT bootstrap endpoint — DISABLED for v16 (frozen A).
2//!
3//! `POST /oauth/wit` formerly minted a HYBRID `wit+jwt` (a SERVICE credential
4//! type) for a USER subject, bound to a caller-SUBMITTED (untrusted) Ed25519
5//! public key, with no RFC 9068 `client_id`, no authoritative interactive /
6//! non-interactive session classification, and no authoritative Primary
7//! signer-suite enrollment.
8//!
9//! Frozen A requires a hybrid credential to be an `at+jwt` (never a service
10//! `wit+jwt`) and a user credential to carry a non-empty `client_id` + an active
11//! session; §5/T1 forbids a self-asserted wire key as the confirmation. The
12//! `AuthenticatedUser` request extension exposes only identity/token/exp, so
13//! this route cannot authoritatively recover any of those and cannot mint a
14//! v16-conformant credential. It is therefore **disabled fail-closed** — a
15//! browser access token is issued through the typed OAuth issuance profiles
16//! that carry those authorities. (Git history holds the removed mint; it is not
17//! retained here as unreachable code.)
18
19use std::sync::Arc;
20
21use axum::{
22    extract::State,
23    http::{header, StatusCode},
24    response::{IntoResponse, Response},
25    Extension, Json,
26};
27use serde::Deserialize;
28
29use super::state::OAuthState;
30use crate::server::middleware::AuthenticatedUser;
31
32#[derive(Deserialize)]
33pub struct WitRequest {
34    /// Base64url-encoded Ed25519 public key — retained for wire compatibility of
35    /// the disabled route; no longer trusted, decoded, or used.
36    pub pubkey: String,
37}
38
39/// POST /oauth/wit — DISABLED fail-closed for v16 (see the module docs). Returns
40/// `501 Not Implemented` for every request, before any credential is minted.
41pub async fn issue_browser_wit(
42    State(state): State<Arc<OAuthState>>,
43    Extension(user): Extension<AuthenticatedUser>,
44    Json(body): Json<WitRequest>,
45) -> Response {
46    let _ = (&state, &user, &body);
47    (
48        StatusCode::NOT_IMPLEMENTED,
49        [
50            (header::CACHE_CONTROL, "no-store"),
51            (header::PRAGMA, "no-cache"),
52        ],
53        Json(serde_json::json!({
54            "error": "unsupported_grant_type",
55            "error_description": "browser WIT bootstrap is disabled: a v16 credential cannot be \
56                minted from an untrusted submitted key without an OAuth client_id, an active \
57                session, and authoritative signer-suite enrollment; use the OAuth token flow",
58        })),
59    )
60        .into_response()
61}
62
63#[cfg(test)]
64#[allow(clippy::unwrap_used, clippy::expect_used)]
65mod tests {
66    use super::*;
67    use crate::config::OAuthConfig;
68    use axum::extract::Extension;
69    use hyprstream_rpc::rpc_client::RpcClientImpl;
70    use hyprstream_rpc::signer::LocalSigner;
71    use hyprstream_rpc::transport::lazy_uds::LazyUdsTransport;
72    use hyprstream_rpc_std::discovery_client::DiscoveryClient;
73    use hyprstream_rpc_std::policy_client::PolicyClient;
74
75    fn test_state() -> Arc<OAuthState> {
76        let key = ed25519_dalek::SigningKey::from_bytes(&[0x73; 32]);
77        let dummy = std::path::PathBuf::from("/dev/null/wit-freeze-test.sock");
78        let make_client = || {
79            Arc::new(
80                RpcClientImpl::new(
81                    LocalSigner::new(key.clone()),
82                    LazyUdsTransport::new(dummy.clone()),
83                    Some(key.verifying_key()),
84                )
85                .with_response_verify_policy(hyprstream_rpc::crypto::CryptoPolicy::Classical),
86            )
87        };
88        Arc::new(
89            OAuthState::new(
90                &OAuthConfig::default(),
91                PolicyClient::new(make_client()),
92                DiscoveryClient::new(make_client()),
93                key.verifying_key().to_bytes(),
94            )
95            .with_ca_jwt_key(key),
96        )
97    }
98
99    fn request() -> WitRequest {
100        WitRequest {
101            pubkey: String::new(),
102        }
103    }
104
105    /// The browser WIT bootstrap route is DISABLED fail-closed for v16: it
106    /// returns `501 Not Implemented` with an `unsupported_grant_type` body and
107    /// never mints a credential.
108    #[tokio::test]
109    async fn browser_wit_route_is_disabled_fail_closed() {
110        let response = issue_browser_wit(
111            State(test_state()),
112            Extension(AuthenticatedUser {
113                user: "alice".to_owned(),
114                verified_tenant: Some("tenant-a.example".to_owned()),
115                token: None,
116                exp: None,
117            }),
118            Json(request()),
119        )
120        .await;
121
122        assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED);
123        let body = axum::body::to_bytes(response.into_body(), usize::MAX)
124            .await
125            .unwrap();
126        let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
127        assert_eq!(json["error"].as_str(), Some("unsupported_grant_type"));
128    }
129
130    /// The refusal is unconditional — even a path-form subject (which the old
131    /// mint rejected only later) is refused before any signing.
132    #[tokio::test]
133    async fn browser_wit_route_disabled_for_path_form_subject() {
134        let response = issue_browser_wit(
135            State(test_state()),
136            Extension(AuthenticatedUser {
137                user: "did:web:accounts.example:users:alice".to_owned(),
138                verified_tenant: Some("tenant-a.example".to_owned()),
139                token: None,
140                exp: None,
141            }),
142            Json(request()),
143        )
144        .await;
145
146        assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED);
147    }
148}