Client Handshake Flow Specification

Overview

This document defines the handshake flow implementation specification for ATH protocol clients (agents).

Client Responsibilities

  1. Manage its own DID identity and public/private key pairs
  2. Store and manage user authorization credentials
  3. Initiate handshake requests and complete mutual identity verification
  4. Negotiate access permissions and obtain access tokens
  5. Maintain encrypted communication sessions with the server

Complete Handshake Flow (Client Perspective)

Prerequisite: Obtain User Pre-Authorization

Before initiating a handshake, the client must first obtain a pre-authorization credential from the user:
  1. Request authorization from the user, specifying the scope of resources to be accessed
  2. The user signs an authorization credential containing the authorization scope, validity period, and other information
  3. The client securely stores the user authorization credential

Step 1: Initiate Handshake Request

The client sends a handshake request message to the server:
{
  "type": "handshake_request",
  "client_did": "did:ath:client_xxxxxx",
  "client_pubkey": "-----BEGIN PUBLIC KEY-----...",
  "versions": ["0.1", "0.2"],
  "capabilities": ["ES256", "EdDSA", "TLS1.3"],
  "nonce": "random_string_a",
  "timestamp": 1234567890
}

Step 2: Process Server Handshake Response

After receiving the server response, the client:
  1. Verifies the validity of the server DID and public key
  2. Verifies the server’s signature of nonce A is correct
  3. Negotiates and determines the protocol version and encryption algorithm
  4. Saves the server public key and metadata

Step 3: Send Identity Proof

The client signs nonce B generated by the server using its own private key and sends an identity proof message:
{
  "type": "identity_proof",
  "signature": "signature_of_nonce_b",
  "credentials": [/* optional identity credentials */],
  "timestamp": 1234567892
}

Step 4: Process Identity Verification Result

The client receives the identity verification result:
  1. Checks whether identity verification passed
  2. Reads the list of supported scopes and configuration information from the server
  3. If verification fails, terminates the handshake flow

Step 5: Send Permission Request

The client sends a permission request to the server, attaching the user pre-authorization credential:
{
  "type": "scope_request",
  "scopes": ["user:read", "data:write"],
  "ttl": 1800,
  "user_authorization": {
    "credential": "jwt_token_signed_by_user",
    "signature": "signature_by_client"
  },
  "context": "For generating user monthly reports",
  "timestamp": 1234567894
}

Steps 6-7: Wait for User Authorization Confirmation

The client waits for the server to complete the user authorization confirmation flow. This process involves direct interaction between the server and the user; the client does not need to participate.

Step 8: Process Permission Approval Result

The client receives the permission approval result:
  1. Checks whether the granted permission scope meets its requirements
  2. Records access restrictions and validity period
  3. If permissions are denied, terminates the handshake flow

Step 9: Complete Handshake, Establish Session

The client and server complete key negotiation:
  1. Generates key exchange parameters and sends them to the server
  2. Receives the server’s key exchange parameters and generates a shared session key
  3. Verifies the validity of the access token issued by the server
  4. Encrypts all subsequent business requests using the session key

Error Handling

Error CodeDescriptionHandling
401Identity verification failedCheck identity configuration and re-initiate handshake
403Permission deniedPrompt the user to re-authorize and adjust the permission scope
408Handshake timeoutRetry the handshake flow, up to 3 retries

Security Requirements

  • User authorization credentials must be stored encrypted to prevent leakage
  • Private keys must be stored securely and must not be transmitted in plaintext
  • Session keys must be rotated periodically, with a validity period not exceeding 24 hours