Game Fetching User Info
1. Architecture Overview and Participant Roles
This flow describes how the game client, with the APP's authorization, securely fetches the user's personal information via SUD OP. Depending on the sensitivity of the data the APP is willing to provide, it is divided into basic user info fetching and sensitive user info fetching.
- APP: The application client
- SUD OP: The communication middleware integrated within the client
- Game: The game client
- Game SVR: The game's server
- SUD OP SVR: The SUD server (the core hub for credential circulation and validation)
- APP SVR: The application's server
2. Prerequisites
- Login flow completed: The user has completed the in-game Login flow.
- Key ready (only for sensitive user info fetching): During Login,
SUD OP SVRhas generated a unique session keysessionKeyfor the user within the current game, andGame SVRhas successfully fetched and holds this key on the server side.
3. Basic User Info Fetching (Non-Sensitive Data / No Encryption Flow)
Applicable scenario: The APP only provides the game with public, non-sensitive basic information (user nickname, avatar). Even if such data is intercepted during network transmission or on the client, it will not cause a leak of core assets. Advantage: The chain is extremely short, requiring no server-side participation in complex ticket circulation and encryption/decryption, resulting in extremely fast responses.
3.1 Basic Info Fetching Interaction Sequence Diagram
3.2 Key Step Descriptions
- Initiate request:
GamecallsSUD OPto initiate the request, which is passed through toAPP. - Fetch plaintext data:
APPrecognizes that the current game only needs basic information, and either extracts it directly from the local cache or initiates a normal data pull request to its ownAPP SVR. - Return directly:
APPreturns the plaintextuserinfoback toGamevia the original route, and the flow ends.
4. Sensitive User Info Fetching (High Security Level / Full Encryption Flow)
Applicable scenario: The APP needs to provide the game with sensitive personal asset data (such as phone number, real name, real UID within the APP, etc.). Mechanism: With the help of SUD OP SVR, the encrypted session key (encrypted_session_key) is obtained and decrypted on the APP SVR side (decryption method) to obtain the real sessionKey, which is used to encrypt the user's sensitive information.
4.1 Sensitive Info Fetching Interaction Sequence Diagram
4.2 APP SVR Data Processing Constraints and Algorithm Specification
Per security compliance requirements, when APP SVR responds with sensitive user data to APP, it must strictly follow the algorithm logic below to complete encryption and signing.
1. Algorithm Selection Basis
| Category | Algorithm | Description |
|---|---|---|
| Data encryption | AES-128-CBC | The key must be the 16-byte byte array obtained after Base64-decoding the sessionKey, together with a 16-byte random IV. |
| Data signing | SHA1 | Hash the raw text concatenated with the sessionKey string to ensure the data is not tampered with during transmission. |
| Padding mode | PKCS7Padding | This padding mode must be used for encryption block alignment. |
2. Encryption Mechanism Details (Encryption)
Sensitive data (such as phone number, real name, etc.) must absolutely never be transmitted in plaintext over the network and must be AES-encrypted.
- Step 1: Obtain the key. APP SVR internally decrypts
encrypted_session_keyto obtain thesessionKeyfor this session (this value is usually a 24-character Base64 string). - Step 2: Generate the IV. APP SVR randomly generates a 16-byte initialization vector (IV) byte array. Note: a random IV must be regenerated for each encryption; hardcoding a fixed value is strictly forbidden.
- Step 3: Serialize the sensitive data. Assemble the sensitive fields to be encrypted into a JSON string and convert it to a UTF-8 byte array.
- Step 4: Perform encryption. Base64-decode the
sessionKeystring obtained in Step 1 to get the 16-byte AES key. Using this key and the IV from Step 2, encrypt the JSON byte array from Step 3 with theAES-128-CBC/PKCS7Paddingalgorithm to get the binary ciphertext. - Step 5: Base64 encoding. Base64-encode the binary ciphertext and the binary IV separately to finally obtain the output
encryptedDataandivstrings.
Encryption Mechanism Example Assume the decrypted sessionKey is: tiihtNczf5v6AKRyjwEUhQ== (this is a standard 16-byte Base64 string) The iv randomly generated by APP SVR is: 1a2b3c4d5e6f7g8h (16 bytes when converted to a byte array) The user info JSON to be encrypted is: {"nickname":"Band","avatarUrl":""} (only some fields are shown here; see Section 4.4 for the complete user info structure).
- Base64-decode the
sessionKeyto get the AES keybyte[]. - Base64-encode the
ivto generate theivin the return parameters:MWEyYjNjNGQ1ZTZmN2c4aA==. - Convert the JSON plaintext to
byte[]. - Perform
AES-128-CBCencryption using the above AES key and IV to get the ciphertextbyte[]. - Base64-encode the ciphertext
byte[]to generate the return parameterencryptedData:k3A8n9/...+aBdE=.
3. Signature Mechanism Details (Signature)
To ensure the security of the user data returned by the interface, APP SVR must sign the plaintext data.
- Step 1: Prepare the raw text to be signed. Extract the
rawDatafield to be returned to the client. - Step 2: Concatenate the key. Directly concatenate
rawDatawith the 16-bytesessionKeyto form a new long string.- Concatenation format:
concatenated string = rawData + sessionKey
- Concatenation format:
- Step 3: Compute the digest. Use the SHA1 algorithm to hash the concatenated long string above to get a binary digest.
- Step 4: Hex encoding. Convert the binary digest to a hexadecimal (Hex) string (lowercase letters + digits) to generate the final
signature.
Signature Mechanism Example Assume the decrypted sessionKey is: 5K826NuS40k6289b The rawData string to be returned is: {"nickname":"John","avatarUrl":"https://domain.com/a.png"}
- Raw text to be signed:
{"nickname":"John","avatarUrl":"https://domain.com/a.png"} - String after concatenating the key:
{"nickname":"John","avatarUrl":"https://domain.com/a.png"}5K826NuS40k6289b - Perform SHA1 computation on the above concatenated string to get a binary digest.
- Convert to a Hex string to generate the final
signature:1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d(example value)
4.3 APP SVR Response Parameters (Body)
The interface response Content-Type must be application/json. APP SVR must return the following fields to APP strictly as specified:
| Parameter | Type | Required | Description |
|---|---|---|---|
| userInfo | UserInfo | Yes | User info object, not including sensitive info such as openid |
| rawData | string | Yes | Raw data string not including sensitive info, used to compute the signature |
| encryptedData | string | Yes | The Base64 ciphertext string generated by encrypting the user info JSON with AES-128-CBC. See below for the decrypted field descriptions. |
| iv | string | Yes | The Base64-encoded string of the 16-byte random initialization vector used in AES encryption. |
| signature | string | Yes | The Hex (hexadecimal) string obtained by concatenating the rawData string with the sessionKey and then computing SHA1. |
- UserInfo user info description
| Parameter | Type | Required | Description |
|---|---|---|---|
| nickname | string | Yes | User nickname. |
| avatarUrl | string | Yes | The URL of the user's avatar image. |
4.4 Decrypted encryptedData Structure
In the response, encryptedData is a Base64-encoded ciphertext string, not a directly returned JSON object. APP SVR assembles the user info into JSON and encrypts it according to Section 4.2. Game SVR decrypts it using the corresponding sessionKey and the iv in the response, then decodes the plaintext as UTF-8 and parses it into a JSON object.
The decrypted user info may contain the following fields. The data provided must follow user authorization and the minimization principle:
| Field | Type | Description |
|---|---|---|
| nickname | string | User nickname. |
| avatarUrl | string | The URL of the user's avatar image. |
| gender | number | User gender identifier; the example value is 1. |
| language | string | User language, such as zh_CN. |
| city | string | User's city, such as Shenzhen. |
| province | string | User's province, such as Guangdong. |
| country | string | User's country or region code, such as CN. |
The following is an example of the JSON plaintext before encryption, which is also the data structure after decryption and parsing. Do not return this object directly as the encryptedData field in the response:
{
"nickname": "Band",
"avatarUrl": "",
"gender": 1,
"language": "zh_CN",
"city": "Shenzhen",
"province": "Guangdong",
"country": "CN"
}4.5 Response Example
{
"userInfo": {"nickname":"John","avatarUrl":"https://res.domain.com/a.png"},
"rawData": "{\"nickname\":\"John\",\"avatarUrl\":\"https://res.domain.com/a.png\"}",
"encryptedData": "C6T9Xp7z8L6mQwZkF1vO9/jR4a...[Base64]...",
"iv": "MWEyYjNjNGQ1ZTZmN2c4aA==",
"signature": "1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d"
}5. APP-Side Security Specification and Development Pitfall Guide
As the party providing user data, APP SVR must observe the following security and development specifications when integrating this flow, to ensure that data is not leaked and that downstream can decrypt successfully:
5.1 Absolute Randomness of Encryption Material (Anti-Replay)
The initialization vector (iv) used for AES-128-CBC encryption must be dynamically and randomly generated for each request (16 bytes). Hardcoding a fixed value is strictly forbidden; otherwise, encryption loses randomness and faces serious risks of replay attacks and frequency-analysis cracking.
5.2 Strict Consistency of the Signature Raw String (Anti Signature-Verification Failure)
This is the most common error during joint debugging. When APP SVR computes the SHA1 signature, the raw text passed in must be byte-for-byte identical to the rawData field in the final response message (including spaces, line breaks, double-quote escaping, etc.).
5.3 Secure Custody of the Decryption Private Key
The agreed private key used by APP SVR to decrypt encrypted_session_key is a top-level sensitive asset. It must be securely stored in the application server's key management system (such as KMS, Vault) or a secure configuration center. It must never be hardcoded in the code and must absolutely never be issued to the APP client.
5.4 Exception Blocking and Compliance
- Decryption failure interception: If
APP SVRfinds thatencrypted_session_keyfails to decrypt (such as a corrupted message or an illegal key), it must immediately block the business and should not return any user data; it may throw a system-agreed exception error code. - Minimization principle: When
APP SVRassemblesencryptedData, it should strictly follow the privacy compliance minimization principle, packaging only the sensitive fields explicitly declared as needed by the current game business and authorized by the user, avoiding over-provision of data.
