pub struct StepUpManager { /* private fields */ }Expand description
独立签名域的 step-up challenge/proof 管理器。
Implementations§
Source§impl StepUpManager
impl StepUpManager
Sourcepub fn new(
secret: impl AsRef<[u8]>,
issuer: impl Into<String>,
audience: impl Into<String>,
) -> Result<Self, BaseError>
pub fn new( secret: impl AsRef<[u8]>, issuer: impl Into<String>, audience: impl Into<String>, ) -> Result<Self, BaseError>
使用 HS256 和安全默认短时限创建管理器。
secret 必须至少 32 字节,且应与 access/refresh token 使用不同密钥。
Sourcepub 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>
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>
使用 active/retiring HS256 keyring 创建可无感轮换的管理器。
新 challenge/proof 始终使用 active key 并写入 kid;校验只接受 active 与
显式 retiring keys。删除 retiring key 后,由该 key 签发且仍在 TTL 内的 Token
会立即失效。
Sourcepub fn with_ttls(
self,
challenge_ttl: Duration,
proof_ttl: Duration,
) -> Result<Self, BaseError>
pub fn with_ttls( self, challenge_ttl: Duration, proof_ttl: Duration, ) -> Result<Self, BaseError>
覆盖 challenge/proof 时限;分别硬限制为 5/10 分钟。
Sourcepub fn issue_challenge(
&self,
subject: impl Into<String>,
action: &ActionRef,
resource: &str,
) -> Result<StepUpChallenge, BaseError>
pub fn issue_challenge( &self, subject: impl Into<String>, action: &ActionRef, resource: &str, ) -> Result<StepUpChallenge, BaseError>
为已认证主体和确定的 Action/资源签发 challenge。
Sourcepub async fn complete_challenge<V>(
&self,
context: &ActionContext,
verifier: &V,
credentials: &LoginInput,
challenge: &str,
) -> Result<StepUpProof, BaseError>where
V: CredentialVerifier,
pub async fn complete_challenge<V>(
&self,
context: &ActionContext,
verifier: &V,
credentials: &LoginInput,
challenge: &str,
) -> Result<StepUpProof, BaseError>where
V: CredentialVerifier,
重新校验凭据并把 challenge 升级为 proof。
CredentialVerifier 返回的 subject 必须与 challenge 完全一致;先解析 challenge,
再调用业务 verifier,避免用无效 Token 触发昂贵的密码哈希。
§限流(实现方必须)
本方法是凭据猜测的在线入口,实现方必须为完成 challenge 的端点配置速率 限制与失败计数,本管理器自身不做限流。接线要点:
- 在调用方(重认证 Action 或
CredentialVerifier实现内)按subject + 客户端标识(如来源 IP、设备指纹)计数连续失败; - 超过阈值后按指数退避或直接锁定,并返回
Unauthorized,不得泄露锁定原因; - 计数与锁定状态应经
ctx.tools()中的共享存储(如 Redis)实现, 多实例部署下才有一致的限流视图; CredentialVerifier返回的失败与 challenge 解析失败都应计入失败次数。
Sourcepub fn verify_proof(
&self,
proof: &str,
subject: &str,
action: &ActionRef,
resource: &str,
) -> Result<StepUpVerification, BaseError>
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§
impl Freeze for StepUpManager
impl RefUnwindSafe for StepUpManager
impl Send for StepUpManager
impl Sync for StepUpManager
impl Unpin for StepUpManager
impl UnsafeUnpin for StepUpManager
impl UnwindSafe for StepUpManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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