跳过内容

iOS 设置和后端验证

GitHub

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

  • iOS 14+
  • 建议使用物理设备进行真实验证流程
  • 已启用 App Attest 能力的 Xcode 目标
  1. 在 Xcode 中打开您的 iOS 应用程序目标。
  2. 前往 签名和能力.
  3. 点击 + 能力 并且添加 App Attest.

在企业产品/价格页面中,角色:短的UI标签或导航项。 Info.plist 在App Attest中,不需要自定义iOS权限。

客户端流程

客户端流程
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. 应用程序调用 createAttestation({ keyId, challenge }).
  3. 后端验证App Attest attestation:
    • 证书链有效并且锚定到Apple App Attest
    • 应用程序身份与您的应用程序(bundleId,团队)
    • clientDataHash 匹配 SHA256(challenge)
  4. 设备商店设备密钥状态(keyId,公钥,和验证器元数据)

请求保护(createAssertion)

保护请求(创建断言)
  1. 后端创建一次性 payload (或规范请求哈希输入).
  2. 应用程序调用 createAssertion({ keyId, payload }).
  3. 后端验证断言签名与之前存储的密钥材料.
  4. 强制重放保护和非一次性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 为本地能力在使用 @capgo/capacitor-app-attest, 加密 为实现细节在加密, 合规性 为合规性中的实现细节 Capgo 安全扫描器 为Capgo 安全扫描器中的产品工作流程 Capgo 安全 为Capgo 安全中的产品工作流程