← Back to CoderGeek
Protocol Analysis Android RE Authorized Research

Reversing the UPI Wallet Protocol:
From OTP Login to Transaction History

Platforms: Amazon Pay · MobiKwik · PhonePe · BharatPe · Airtel · FreeCharge · Paytm

This is a write-up of an authorized Android reverse-engineering study of the client communication protocol used by mainstream Indian UPI wallet apps. App names are referenced only to illustrate cross-platform differences; all endpoints, accounts, and sensitive parameters are redacted. The discussion is limited to the interface model, encryption mechanism, and security controls — it contains no reproducible attack code and targets no real account or service.
UPI wallet apps look simple on the surface, but their protocol is a composite system of hard state dependency, multi-layer encryption, and multi-form credentials. Across seven major platforms the underlying model is remarkably consistent — here is the abstraction.

1. Overall Architecture

1.1 Transport

All platforms run over HTTPS (TLS), with some enabling HTTP/2 to reduce handshake overhead. Request bodies are predominantly JSON; a few legacy endpoints (e.g. Amazon Pay) still use the older server-rendered HTML + client-side parsing pattern.

1.2 Session Lifecycle

A UPI wallet session follows a strict linear pipeline with hard state dependencies — each step's output is the next step's input:

Device init / registration
        ↓
Fetch encryption public key (some platforms)
        ↓
Request OTP send (phone number entered)
        ↓
Verify OTP → obtain Auth Token / Cookie / Session
        ↓
Query UPI ID (requires logged-in Token)
        ↓
Query transaction list (requires Token, paginated)
        ↓
Query transaction detail (optional)
        ↓
Token refresh / logout

An OTP request that omits the prerequisite Cookie is rejected outright; a Token that did not pass OTP verification cannot reach the UPI ID or history endpoints. This "progressive unlock" is itself a layer of defense-in-depth.

2. The OTP Login Flow

OTP login is split into a send step and a verify step:

Some platforms (e.g. Paytm) layer a multi-step OAuth2 authorization on top of OTP verification (state token → authorization code → access token), ultimately producing a Bearer Token valid for roughly one month.

2.1 Prerequisite Steps

Before requesting an OTP, most platforms require one or more initialization actions — so a "bare" OTP request is almost impossible to succeed against a modern UPI wallet:

StepDescriptionTypical params
Device registration / configReport device info, receive a device-level initial Token / Sessiondevice ID, OS, model, app version
Fetch encryption public keyPull an RSA public key (~36h validity) for later body encryptionnone; returns key + TTL
Obtain initial Cookie / CSRFInitialize session contextdelivered via Set-Cookie
Initialize Session IDCreate the login sessionphone, device ID, flow type

2.2 Request-OTP Endpoint

Method: POST  ·  Auth state: anonymous

Beyond business fields, the Header layer carries extensive device and crypto metadata:

LocationParameterNotes
HeaderUser-Agentapp version, OS, model
HeaderDevice IDX-Device-ID / x-bsy-did / x-id
HeaderApp versionX-App-Ver / x-bsy-appvn
HeaderEncryption public keye.g. pke
HeaderEncryption key handleAES key wrapped with RSA, e.g. cske
HeaderCSRF tokenanti-CSRF
BodyPhone numberplaintext or symmetrically encrypted
BodyNoncenonceToken / tid; anti-replay

Success-response fields: otpId / nid / sessionId (unique OTP ID, echoed at verify), otpLength (4 or 6), and a platform status flag (success:true / status:"SUCCESS").

Common errors: phone number not found / malformed, rate-limited, device not authorized.

2.3 Verify-OTP Endpoint

Method: POST  ·  Auth state: anonymous

The client submits the 4–6 digit code plus the correlation identifier returned by the send step. On success the server issues an auth credential — and the credential's concrete shape is where platforms diverge most:

Token formDescriptionPlatform
HTTP Cookiestored in Set-Cookie, auto-attachedFreeCharge
Header concatenationhashid + "." + tokenAuthorizationMobiKwik
accessToken in bodyBearer Token, manually injectedPaytm, PhonePe
Multi-field Session Cookiesession-token, at-acbin, …Amazon Pay
Dynamic + static dual Tokendynamic refreshed per request, static long-livedAirtel

Common verify failures: wrong code (attempts decrement), expired (~3–5 min), max attempts exceeded (5 tries → 24h lockout).

3. The Encryption Scheme

UPI wallets generally use a hybrid RSA + AES scheme:

This mirrors the "double-layer" idea of running application-layer encryption inside TLS: even if the transport is observed by a MITM (e.g. a debug proxy), the application-layer ciphertext still protects sensitive fields.

IdentifierPurpose
nonceToken / tidAnti-replay
CSRF tokenAnti-CSRF
Device fingerprintDevice binding & risk control

4. UPI ID Lookup & Transaction History

Once the auth credential is in hand, two core paths open up:

  1. UPI ID (VPA) lookup: Token-gated; returns the registered Virtual Payment Address (e.g. xxxx@bank) and binding status. Some platforms attach this directly in the OTP-verify response.
  2. Transaction history: also Token-gated, paginated, with optional single-transaction detail. These endpoints directly expose a user's financial trail and carry additional device checks and rate limits.

5. Security Controls Summary

Defensive lineMechanism
Transport securityHTTPS / TLS, some HTTP/2
Application-layer cryptoRSA + AES hybrid, ~36h key rotation
Authenticationtwo-step OTP + multi-step OAuth (Paytm)
Session bindingdevice fingerprint, CSRF, Session ID
Risk / rate limitingOTP throttling, 5/24h lockout, anti-replay nonce

6. Methodology Notes

  1. Establish session context first. Always capture from a cold start and record the full prerequisite chain — device registration → public-key fetch → cookie acquisition — or later requests won't replay.
  2. Identify the crypto layer. Locate the client-side RSA public-key cache and AES key-generation logic; they usually concentrate in the network layer or a dedicated crypto class.
  3. Track token lifecycles. Distinguish short-lived from long-lived tokens, and note their different injection points across Header / Cookie / Body.
  4. Watch for risk signals. Rate limiting, attempt lockout, and device-fingerprint checks are implicit constraints outside the protocol proper — they often define the feasibility boundary of any automation.

Need a protocol reversed — the right way?

Authorized protocol analysis, algorithm extraction, and SDK integration. Quote within 24 hours.

Get a Quote