Skip to main content

StepUpManager

Struct StepUpManager 

Source
pub struct StepUpManager { /* private fields */ }
Expand description

独立签名域的 step-up challenge/proof 管理器。

Implementations§

Source§

impl StepUpManager

Source

pub fn new( secret: impl AsRef<[u8]>, issuer: impl Into<String>, audience: impl Into<String>, ) -> Result<Self, BaseError>

使用 HS256 和安全默认短时限创建管理器。

secret 必须至少 32 字节,且应与 access/refresh token 使用不同密钥。

Source

pub fn new_with_keyring<I, K, S>( active_kid: impl Into<String>, active_secret: impl AsRef<[u8]>, retiring_keys: I, issuer: impl Into<String>, audience: impl Into<String>, ) -> Result<Self, BaseError>
where I: IntoIterator<Item = (K, S)>, K: Into<String>, S: AsRef<[u8]>,

使用 active/retiring HS256 keyring 创建可无感轮换的管理器。

新 challenge/proof 始终使用 active key 并写入 kid;校验只接受 active 与 显式 retiring keys。删除 retiring key 后,由该 key 签发且仍在 TTL 内的 Token 会立即失效。

Source

pub fn with_ttls( self, challenge_ttl: Duration, proof_ttl: Duration, ) -> Result<Self, BaseError>

覆盖 challenge/proof 时限;分别硬限制为 5/10 分钟。

Source

pub fn issue_challenge( &self, subject: impl Into<String>, action: &ActionRef, resource: &str, ) -> Result<StepUpChallenge, BaseError>

为已认证主体和确定的 Action/资源签发 challenge。

Source

pub async fn complete_challenge<V>( &self, context: &ActionContext, verifier: &V, credentials: &LoginInput, challenge: &str, ) -> Result<StepUpProof, BaseError>

重新校验凭据并把 challenge 升级为 proof。

CredentialVerifier 返回的 subject 必须与 challenge 完全一致;先解析 challenge, 再调用业务 verifier,避免用无效 Token 触发昂贵的密码哈希。

§限流(实现方必须)

本方法是凭据猜测的在线入口,实现方必须为完成 challenge 的端点配置速率 限制与失败计数,本管理器自身不做限流。接线要点:

  • 在调用方(重认证 Action 或 CredentialVerifier 实现内)按 subject + 客户端标识(如来源 IP、设备指纹)计数连续失败;
  • 超过阈值后按指数退避或直接锁定,并返回 Unauthorized,不得泄露锁定原因;
  • 计数与锁定状态应经 ctx.tools() 中的共享存储(如 Redis)实现, 多实例部署下才有一致的限流视图;
  • CredentialVerifier 返回的失败与 challenge 解析失败都应计入失败次数。
Source

pub fn verify_proof( &self, proof: &str, subject: &str, action: &ActionRef, resource: &str, ) -> Result<StepUpVerification, BaseError>

校验 proof 与当前主体、Action 和资源是否完全一致。

成功与失败都会发出审计事件(均含 subject/action/resource_hash,不记录 proof Token 原文)。成功事件含 proof_id;失败事件按可解码性分两类: 签名可解码、因绑定维度不匹配被拒时,额外记录签名背书的 claimed_proof_id/claimed_resource_hash(重放取证的关键字段); 伪造或过期的 Token 无法解码,没有可信 proof_id,失败事件不含 claimed_* 字段。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more