mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
## What changed - Introduce `codex-user-verification` with a provider interface for credential status, creation, deletion, and challenge signing. Include typed errors, shared cancellation guards, and hashed account-user key namespaces. - Add P-256 public-key encoding as unpadded base64url SPKI DER, derive credential IDs from its SHA-256 digest, and redact proof fields in debug output. - Add app-server helpers to validate challenge and display-text bounds and map provider errors to typed RPC errors without exposing provider diagnostics. The platform implementation reports verification as unsupported. App-server requests still return typed unavailability, with the message updated to mention build or account availability. ## Testing Add tests for credential encoding and signature verification, invalid curve points, cancellation across guard clones, stable and distinct account namespaces, and invalid challenge or display values. Update the app-server unavailability test for the revised message. GitOrigin-RevId: fe4a4eb37c68d7fdc547704e76aa257abf3e9c81
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
//! Cancellation and caller-owned identity checks for queued native operations.
|
|
|
|
use crate::UserVerificationCancellationReason;
|
|
use crate::UserVerificationError;
|
|
use std::sync::Arc;
|
|
use std::sync::atomic::AtomicBool;
|
|
use std::sync::atomic::Ordering;
|
|
|
|
/// Invalidates queued work and suppresses late results. Native providers observe cancellation
|
|
/// during authentication and request dismissal of their active OS prompt.
|
|
#[derive(Clone, Default)]
|
|
pub struct UserVerificationRequestGuard {
|
|
cancelled: Arc<AtomicBool>,
|
|
activity_check: Option<Arc<dyn Fn() -> bool + Send + Sync>>,
|
|
}
|
|
|
|
impl UserVerificationRequestGuard {
|
|
/// The callback checks a captured identity; it must be nonblocking and must not prompt.
|
|
pub fn with_activity_check(activity_check: impl Fn() -> bool + Send + Sync + 'static) -> Self {
|
|
Self {
|
|
cancelled: Arc::default(),
|
|
activity_check: Some(Arc::new(activity_check)),
|
|
}
|
|
}
|
|
|
|
pub fn cancel(&self) {
|
|
self.cancelled.store(/*val*/ true, Ordering::Release);
|
|
}
|
|
|
|
pub fn is_active(&self) -> bool {
|
|
if self.activity_check.as_ref().is_some_and(|check| !check()) {
|
|
self.cancel();
|
|
}
|
|
!self.cancelled.load(Ordering::Acquire)
|
|
}
|
|
|
|
pub fn check(&self) -> Result<(), UserVerificationError> {
|
|
if self.is_active() {
|
|
Ok(())
|
|
} else {
|
|
Err(UserVerificationError::Cancelled {
|
|
reason: UserVerificationCancellationReason::Interrupted,
|
|
message: "the verification operation is no longer active".to_string(),
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "guard_tests.rs"]
|
|
mod tests;
|