Commit d61fa44
feat(be): sign a session to the II frontend at sign-in (#4268)
Design: #4224. Overview: #4230. This is the caller #4266 and #4264 were
waiting for, so it removes their `#[allow(dead_code)]` annotations.
**`prepare_account_session` / `get_account_session`.** The first creates
a session and signs its delegation to the II frontend's key; the second
witnesses it. A separate pair from `prepare_account_delegation`, not an
option on it: both mint, but one proves a live session and identifies
the account by its principal while the other proves an access method and
names the anchor outright. Merging them would mean one method with two
authorizers and two argument shapes, and would drag the frontend's
internal surface into the public API.
**Everything that can refuse does so before anything is written**,
cheapest first. The account check leads — an account the identity does
not hold is the one failure a caller can provoke, and returning it after
the writes would leave a browser registered for a sign-in that never
happened — so a request that was never going to succeed does not pay for
two P-256 verifications on the way to being told so. Nothing is revealed
by that order: `check_authz_and_record_activity` above is the auth
guard. The browser proof follows, using the verifier from #4264, and
`create_session` takes the `VerifiedBrowserKeys` it produces rather than
two byte strings.
**The session credential is scoped to Internet Identity.** It exists to
mint app delegations, which is an update call on this canister and
nothing else, so it is signed with `targets = [id()]` and can be
presented nowhere else. Leaving that to the II frontend would have left
it to the party holding the session key, who can decline to add it.
`permissions` stays absent for the same reason it is set on app
delegations: minting is an update call, so a read-only session that
could not make one could not sign in to an app at all — read-only
travels on the app delegation instead.
**`get_account_session` tells three failures apart.** No stored session
for that id is `NoSuchSession`; a session that is present with no
signature for the asked-for key and expiration is `NoSuchDelegation`,
because the remedy is to ask with the parameters that were signed rather
than to sign in again; a seed that will not derive is the salt being
unset, which is `InternalCanisterError`. An over-long origin is that
too, rather than a rejected message the caller cannot read as a
response.
**The request carries what the browser is, not a label for it.**
`browser_description` holds the tokens the registry stores (#4242), and
each token a client writes for itself — an unrecognised brand, an
unrecognised system, and the hardware model — is bounded at 64 bytes.
The named variants carry no text, so a description of nothing but those
is within the limit whatever it says. Refused rather than truncated: a
cut-off token would put a value in the record that no parser ever
produced.
**Every later failure traps rather than returning.** On the IC,
returning an error commits state and only a trap rolls the message back,
so once the browser registration is written a failure has to trap or a
caller could be told "no" and still have a browser enrolled.
**`valid_for`** is the lifetime the user chose at consent, clamped by
the canister to between 10 minutes and 30 days. Every ceremony creates,
so it always applies: the replacement's expiry is measured from the
ceremony that made it, and no session is renewed in place.
Tests: `integration/sessions.rs` (18) drives the real ceremony —
creating and verifying a session, a request for another identity
refused, the registry cap dropping the least recently used and ending
its sessions, the key proof's rejections at the endpoint, rotation
keeping the entry, a retired key returning as a new browser, and two
browsers each keeping the description it registered with.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 0c929f8 commit d61fa44
19 files changed
Lines changed: 1695 additions & 35 deletions
File tree
- src
- canister_tests/src
- api/internet_identity
- frontend/src/lib/generated
- internet_identity_interface/src/internet_identity
- internet_identity
- src
- email_inbound
- storage
- tests/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
378 | 442 | | |
379 | 443 | | |
380 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
389 | 409 | | |
390 | 410 | | |
391 | 411 | | |
| |||
718 | 738 | | |
719 | 739 | | |
720 | 740 | | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
721 | 762 | | |
722 | 763 | | |
723 | 764 | | |
| |||
1071 | 1112 | | |
1072 | 1113 | | |
1073 | 1114 | | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
1074 | 1125 | | |
1075 | 1126 | | |
1076 | 1127 | | |
| |||
1327 | 1378 | | |
1328 | 1379 | | |
1329 | 1380 | | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
1330 | 1391 | | |
1331 | 1392 | | |
1332 | 1393 | | |
| |||
Lines changed: 126 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
22 | 48 | | |
23 | 49 | | |
24 | 50 | | |
| |||
696 | 722 | | |
697 | 723 | | |
698 | 724 | | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
699 | 739 | | |
700 | 740 | | |
701 | 741 | | |
| |||
1334 | 1374 | | |
1335 | 1375 | | |
1336 | 1376 | | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
1337 | 1447 | | |
1338 | 1448 | | |
1339 | 1449 | | |
| |||
2103 | 2213 | | |
2104 | 2214 | | |
2105 | 2215 | | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
2106 | 2221 | | |
2107 | 2222 | | |
2108 | 2223 | | |
| |||
2395 | 2510 | | |
2396 | 2511 | | |
2397 | 2512 | | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
2398 | 2524 | | |
2399 | 2525 | | |
2400 | 2526 | | |
| |||
0 commit comments