WebAuthn | 注册

WebAuthn 注册涉及客户端(浏览器)、身份验证器(安全设备)和依赖方(RP;TsgcWSAPIServer_WebAuthn Delphi/CBuilder 服务器)。

 

注册选项

 

创建新用户凭据通常需要客户端使用新的 HTTP 请求向 TsgcWSAPIServer_WebAuthn 服务器中配置的注册选项端点发起注册流程。默认情况下,端点为 /sgcWebAuthn/Registration/Options,因此如果您的服务器正在监听域名 https://www.test.com,客户端应向 https://www.test.com/sgcWebAuthn/Registration/Options 发出新请求。

 

客户端发送新请求,将以下 JSON 作为有效负载传递(以 test 作为用户名)

 

{"username":"test","algorithms":[]}

 

服务器读取请求并返回带有新挑战的响应。

 

{
    "rp": {
        "name": "localhost",
        "id": "localhost"
    },
    "user": {
        "id": "36b9d6a84204487382fee62e7e67a80d",
        "name": "test",
        "displayName": "test"
    },
    "challenge": "6c6c468c99f24bf29a85a15b661f75f385654f97309c46bab2909c926e17ccbe",
    "pubKeyCredParams": [
        {
            "type": "public-key",
            "alg": "-7"
        },
        {
            "type": "public-key",
            "alg": "-257"
        }
    ],
    "timeout": 60000,
    "excludeCredentials": [],
    "authenticatorSelection": {
        "residentKey": "preferred",
        "requireResidentKey": false,
        "userVerification": "preferred"
    },
    "attestation": "direct",
    "hints": [],
    "extensions": {
        "credProps": true
    }
}

 

响应返回以下数据:

 

 

 

注册验证

 

客户端现已获取服务器响应,读取响应后,认证器将密码学数据返回给客户端 Web 浏览器。然后客户端向 TsgcWSAPIServer_WebAuthn 服务器上配置的注册验证端点(默认为 /sgcWebAuthn/Registration/Verify)发送新的 HTTP 请求,携带以下数据。

,因此如果您的服务器正在监听域名 https://www.test.com,客户端应向 https://www.test.com/sgcWebAuthn/Registration/Verify 发出新请求。

 

身份验证器将以下内容响应给浏览器中的 JavaScript:

 

 

以下是一个示例:

 

{
    "id": "yeA4BVRlrAfLG-KzqsL_rlI4ffhuKHK8uoEkVoab065UkS82Zqlh9VFQHIYwOuOo",
    "rawId": "yeA4BVRlrAfLG-KzqsL_rlI4ffhuKHK8uoEkVoab065UkS82Zqlh9VFQHIYwOuOo",
    "response": {
        "attestationObject": "o2NmbXRmcGFja2VkZ2F0dFN0....",
        "clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uY3Jl....",
        "transports": [
            "nfc",
            "usb"
        ],
        "publicKeyAlgorithm": -7,
        "publicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj....",
        "authenticatorData": "SZYN5YgOjGh0NBcPZHZgW4_k...."
    },
    "type": "public-key",
    "clientExtensionResults": {
        "credProps": {
            "rk": true
        }
    },
    "authenticatorAttachment": "cross-platform"
}

 

服务器读取来自客户端的 JSON 请求,并对公钥和凭据 ID 进行解码、验证和存储。

 

解码 attestationObject 和 clientDataJSON:

 

 

存储凭证:

 

 

 

 

注册流程

有关注册流程的更多信息,请访问以下链接: