Sub topic 11
Setting up an authenticator app and a passkey on your exchange
This chapter walks through enrolling both factors on a centralized exchange account and checking that each one works. It assumes you can log in to an exchange, know what a password and two-factor authentication are, and can install apps and change account settings. Earlier chapters explained how TOTP and WebAuthn work. Here the focus is the enrollment flow, the choices you make during it, and the mistakes that cause lockouts or leave a weak path open.
Plan the order before you start
Enroll in an order that never leaves you with fewer working factors than you started with.
- Log in on a trusted computer and check the device clock.
- Enroll the authenticator app and confirm it with a live code.
- Enroll a passkey or security key and test a full sign-in with it.
- Save recovery material (covered in the next chapter).
- Only then remove or downgrade weaker factors such as SMS.
Enrolling an authenticator app
What the exchange does
When you choose "Enable authenticator app" in the security settings, the exchange generates a random secret and shows it to you once, as a QR code and as a text key. The secret is stored as pending. It becomes active only when you submit a valid code, which proves your app holds the same secret.
The QR code is an otpauth URI:
otpauth://totp/Example%20Exchange:alice%40example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=Example%20Exchange&algorithm=SHA1&digits=6&period=30The URI contains the base32 secret, the issuer, and the algorithm, digit count and period. Anyone who sees the QR code or text key can generate your codes, so treat that screen like a password.
This sketch shows how a server could produce the secret and URI. It uses Python's secrets module, which draws from the operating system's cryptographic random source:
import base64
import secrets
from urllib.parse import quote
def new_enrollment(issuer, account):
# 20 random bytes = 160 bits, the size RFC 4226 recommends for HMAC-SHA1
secret = base64.b32encode(secrets.token_bytes(20)).decode().rstrip("=")
label = quote(f"{issuer}:{account}", safe=":")
uri = (
f"otpauth://totp/{label}?secret={secret}"
f"&issuer={quote(issuer)}&algorithm=SHA1&digits=6&period=30"
)
return secret, uri
if __name__ == "__main__":
secret, uri = new_enrollment("Example Exchange", "[email protected]")
print(secret)
print(uri)What you do
- Open the app (any standards-based TOTP app works) and add an account by scanning the QR code.
- Check that the issuer and account label match your exchange and email. If you manage several exchange accounts, the label is the only way to tell the entries apart.
- Enter the current six-digit code on the exchange to confirm.
- If you cannot scan, type the text key into the app manually. Keep the algorithm at SHA-1, six digits and 30 seconds unless the exchange states otherwise.
Verifying a code on the server
The exchange accepts the code for the current step and one step either side to allow for clock drift:
def verify_totp(secret_b32, submitted, window=1, step=30):
now = time.time()
return any(
hmac.compare_digest(totp(secret_b32, step=step, at=now + drift * step), submitted)
for drift in range(-window, window + 1)
)This uses the totp function from the chapter on TOTP internals. A real server must also reject a code it has already accepted, otherwise someone who watches you type a code can replay it within the window.
Common enrollment errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Code is rejected every time | Phone clock is off by more than about 30 seconds | Turn on automatic network time, then retry with a fresh code |
| Code works once, then fails | You submitted the same code twice, or the app entry is for another account | Wait for the next code. Check the label |
| QR will not scan | Screen glare, or the page expired | Reload the setup page. Use the text key |
| Codes stop after a phone reset | Secret was never backed up | Use recovery material (next chapter) |
Reloading the setup page usually generates a new secret. If you scanned the old QR code, the entry in your app no longer matches. Delete it and scan the new one.
Enrolling a passkey
What happens in the browser
When you choose "Add passkey" or "Add security key", the exchange's page calls the browser's WebAuthn API with a random challenge. The browser asks your authenticator to create a new key pair for this site. The private key stays on the authenticator and the exchange stores the public key.
// Registration: the server supplies a random challenge and the user id.
const credential = await navigator.credentials.create({
publicKey: {
challenge: challengeBytes,
rp: { id: "exchange.example", name: "Example Exchange" },
user: { id: userIdBytes, name: "[email protected]", displayName: "Alice" },
pubKeyCredParams: [
{ type: "public-key", alg: -7 }, // ES256
{ type: "public-key", alg: -257 } // RS256
],
authenticatorSelection: { residentKey: "preferred", userVerification: "required" },
attestation: "none",
timeout: 60000
}
});
// Sign-in: the server supplies a fresh challenge for each attempt.
const assertion = await navigator.credentials.get({
publicKey: {
challenge: newChallengeBytes,
rpId: "exchange.example",
userVerification: "required"
}
});Four parameters shape what you see during enrollment:
rp.idties the credential to the exchange's domain. The browser refuses to use it on any other site.residentKey: "preferred"asks the authenticator to store a discoverable credential, so you can sign in without typing a username first.userVerification: "required"makes the authenticator check your fingerprint, face or PIN before it signs.attestation: "none"means the exchange does not ask which device model you have, which protects your privacy.
The server must then verify the response. It checks that the challenge matches the one it issued, that the origin is its own, and that the signature is valid. Only then does it store the public key.
Choosing where the passkey lives
| Choice | What it means | When to pick it |
|---|---|---|
| Phone or computer passkey manager | A synced passkey, available on your other devices through your account | Convenience, and you trust your platform account's recovery |
| Password manager passkey | Synced through the manager's vault | You already protect the vault with a strong secret and its own second factor |
| Hardware security key | A device-bound passkey on a physical key | Largest balance, or you do not want the key in any cloud |
Many people enroll two: a synced passkey for daily use and a hardware key kept in a safe place. Give each passkey a recognizable name at enrollment, such as "YubiKey in safe" or "Laptop". The exchange's list of credentials is how you later spot and remove one you no longer control.
Test before you rely on it
- Open a private browser window and go to the exchange's real address, typed or from a bookmark.
- Sign in with the passkey, and confirm that it asks for fingerprint, face or PIN.
- Confirm that you reach the account without being sent to a different factor.
- If you enrolled a security key, repeat the test with that key.
Interaction with the factors you already have
Enrolling a new factor does not by itself disable old ones. Look for these settings:
- Whether the exchange still accepts SMS or email codes as a fallback at login or for withdrawals. A fallback is only as strong as its weakest option.
- Whether withdrawals require the passkey or app code, or only the login factor.
- Whether adding or removing a factor triggers a withdrawal hold. Many exchanges apply a delay of 24 hours or more after a security change.
Expect a hold and plan around it. Enrolling right before you need to withdraw funds is a bad idea.
Exercise
You scanned the exchange's QR code into your authenticator app, but the exchange rejects every six-digit code. Your phone shows the right time zone. Name two possible causes besides a typo, and say how you would check each.
Show answer
First, the phone's clock may be off by more than the accepted window (typically 30 seconds each side). Check by turning on automatic network time and retrying with a fresh code. Second, you may have scanned an outdated QR code, because reloading the setup page generated a new secret. Check by deleting the app entry, reloading the setup page and scanning the new QR code. A third cause is an entry for a different account with a similar label.
Exercise
Why should you test a new passkey in a private window while still logged in elsewhere, and what two things should the test confirm?
Show answer
A working session lets you fix or remove a broken passkey without going through account recovery. The test should confirm that the passkey completes sign-in on the exchange's real domain with a fingerprint, face or PIN prompt, and that you did not need a weaker fallback factor to get in.