跳过内容

iOS 设置和后端验证

GitHub

在 iOS 上,这个插件使用 Apple App Attest 来自 DeviceCheck 框架

需求

需求
  • iOS 14+
  • 建议使用物理设备进行真实验证流程
  • 已启用 App Attest 功能的 Xcode 目标
  1. 前往
  2. 签名和功能 点击.
  3. + 功能 添加功能 并且添加 App Attest.

在企业产品/价格页面中,App Attest Info.plist 不需要自定义 iOS 权限

Client 流程

客户端流程
import { AppAttest } from '@capgo/capacitor-app-attest';
const { keyId } = await AppAttest.prepare();
const attestation = await AppAttest.createAttestation({
keyId,
challenge: 'backend-registration-challenge',
});
const assertion = await AppAttest.createAssertion({
keyId,
payload: 'backend-request-payload',
});

发送 attestation.token 并且 assertion.token 将其发送到您的后端。不要在应用中验证它们。

iOS 后端工作流程

客户端流程

注册(createAttestation)createAttestation)

标题:注册(createAttestation)
  1. 后端创建一次性 challenge.
  2. App调用 createAttestation({ keyId, challenge }).
  3. 后端验证App Attest attestation:
    • 证书链有效且锚定到Apple App Attest
    • app身份与您的app(bundleId,团队)
    • clientDataHash 匹配 SHA256(challenge)
  4. 设备商店密钥状态(keyId,公钥,和验证器元数据)
  1. 后端创建一次性 payload (或 canonical 请求 hash 输入).
  2. App 调用 createAssertion({ keyId, payload }).
  3. 后端验证声明签名与之前存储的密钥材料.
  4. 强制重放保护和 nonce TTL 检查.
sequenceDiagram
participant App as iOS App
participant Plugin as AppAttest plugin
participant Apple as Apple App Attest
participant BE as Backend
BE->>App: one-time challenge
App->>Plugin: prepare()
Plugin->>Apple: generateKey()
Apple-->>Plugin: keyId
App->>Plugin: createAttestation(keyId, challenge)
Plugin->>Apple: attestKey(keyId, SHA256(challenge))
Apple-->>Plugin: attestation token
Plugin-->>App: token + platform + format + keyId
App->>BE: token + challenge + keyId
BE->>BE: verify Apple attestation rules
BE->>App: one-time payload
App->>Plugin: createAssertion(keyId, payload)
Plugin->>Apple: generateAssertion(keyId, SHA256(payload))
Apple-->>Plugin: assertion token
Plugin-->>App: token + platform + format + keyId
App->>BE: token + payload + keyId
BE->>BE: verify signature + replay policy

注册:

{
"platform": "ios",
"format": "apple-app-attest",
"keyId": "string",
"challenge": "string",
"token": "string"
}

断言:

{
"platform": "ios",
"format": "apple-app-attest",
"keyId": "string",
"payload": "string",
"token": "string"
}

继续从 iOS 设置和后端验证

标题:继续从 iOS 设置和后端验证

如果您正在使用 iOS 设置和后端验证 来规划安全性和合规性,连接它与 使用 @capgo/capacitor-app-attest 为 native 能力在使用 @capgo/capacitor-app-attest 加密 为加密实现细节 合规性 合规性 Capgo 安全扫描器 Capgo 安全扫描器 Capgo 安全 for the product workflow in Capgo Security.