]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/proposed/accounting-overview.txt
8ae01f22918c2dbf30b4d852ae59e438908c48c2
[tahoe-lafs/tahoe-lafs.git] / docs / proposed / accounting-overview.txt
1
2 = Accounting =
3
4 "Accounting" is the arena of the Tahoe system that concerns measuring,
5 controlling, and enabling the ability to upload and download files, and to
6 create new directories. In contrast with the capability-based access control
7 model, which dictates how specific files and directories may or may not be
8 manipulated, Accounting is concerned with resource consumption: how much disk
9 space a given person/account/entity can use.
10
11 Tahoe releases up to and including 1.4.1 have a nearly-unbounded resource
12 usage model. Anybody who can talk to the Introducer gets to talk to all the
13 Storage Servers, and anyone who can talk to a Storage Server gets to use as
14 much disk space as they want (up to the reserved_space= limit imposed by the
15 server, which affects all users equally). Not only is the per-user space
16 usage unlimited, it is also unmeasured: the owner of the Storage Server has
17 no way to find out how much space Alice or Bob is using.
18
19 The goals of the Accounting system are thus:
20
21  * allow the owner of a storage server to control who gets to use disk space,
22    with separate limits per user
23  * allow both the server owner and the user to measure how much space the user
24    is consuming, in an efficient manner
25  * provide grid-wide aggregation tools, so a set of cooperating server
26    operators can easily measure how much a given user is consuming across all
27    servers. This information should also be available to the user in question.
28
29 For the purposes of this document, the terms "Account" and "User" are mostly
30 interchangeable. The fundamental unit of Accounting is the "Account", in that
31 usage and quota enforcement is performed separately for each account. These
32 accounts might correspond to individual human users, or they might be shared
33 among a group, or a user might have an arbitrary number of accounts.
34
35 Accounting interacts with Garbage Collection. To protect their shares from
36 GC, clients maintain limited-duration leases on those shares: when the last
37 lease expires, the share is deleted. Each lease has a "label", which
38 indicates the account or user which wants to keep the share alive. A given
39 account's "usage" (their per-server aggregate usage) is simply the sum of the
40 sizes of all shares on which they hold a lease. The storage server may limit
41 the user to a fixed "quota" (an upper bound on their usage). To keep a file
42 alive, the user must be willing to use up some of their quota.
43
44 Note that a popular file might have leases from multiple users, in which case
45 one user might take a chance and decline to add their own lease, saving some
46 of their quota and hoping that the other leases continue to keep the file
47 alive despite their personal unwillingness to contribute to the effort. One
48 could imagine a "pro-rated quotas" scheme, in which a 10MB file with 5
49 leaseholders would deduct 2MB from each leaseholder's quota. We have decided
50 to not implement pro-rated quotas, because such a scheme would make usage
51 values hard to predict: a given account might suddenly go over quota solely
52 because of a third party's actions.
53
54 == Authority Flow ==
55
56 The authority to consume space on the storage server originates, of course,
57 with the storage server operator. These operators start with complete control
58 over their space, and delegate portions of it to others: either directly to
59 clients who want to upload files, or to intermediaries who can then delegate
60 attenuated authority onwards. The operators have various reasons for wanting
61 to share their space: monetary consideration, expectations of in-kind
62 exchange, or simple generosity. But the final authority always rests with the
63 operator.
64
65 The server operator grants limited authority over their space by configuring
66 their server to accept requests that demonstrate knowledge of certain
67 secrets. They then share those secrets with the client who intends to use
68 this space, or with an intermediary who will generate still more secrets and
69 share those with the client. Eventually, an upload or create-directory
70 operation will be performed that needs this authority. Part of the operation
71 will involve proving knowledge of the secret to the storage server, and the
72 server will require this proof before accepting the uploaded share or adding
73 a new lease.
74
75 The authority is expressed as a string, containing cryptographically-signed
76 messages and keys. The string also contains "restrictions", which are
77 annotations that explain the limits imposed upon this authority, either by
78 the original grantor (the storage server operator) or by one of the
79 intermediaries. Authority can be reduced but not increased. Any holder of a
80 given authority can delegate some or all of it to another party.
81
82 The authority string may be short enough to include as an argument to a CLI
83 command (--with-authority ABCDE), or it may be long enough that it must be
84 stashed in a file and referenced in some other fashion (--with-authority-file
85 ~/.my_authority). There are CLI tools to create brand new authority strings,
86 to derive attenuated authorities from an existing one, and to explain the
87 contents of an authority string. These authority strings can be shared with
88 others just like filecaps and dircaps: knowledge of the authority string is
89 both necessary and complete to wield the authority it represents.
90
91 Web-API requests will include the authority necessary to complete the
92 operation. When used by a CLI tool, the authority is likely to come from
93 ~/.tahoe/private/authority (i.e. it is ambient to the user who has access to
94 that node, just like aliases provide similar access to a specific "root
95 directory"). When used by the browser-oriented WUI, the authority will [TODO]
96 somehow be retained on each page in a way that minimizes the risk of CSRF
97 attacks and allows safe sharing (cut-and-paste of a URL without sharing the
98 storage authority too). The client node receiving the web-API request will
99 extract the authority string from the request and use it to build the storage
100 server messages that it sends to fulfill that request.
101
102 == Definition Of Authority ==
103
104 The term "authority" is used here in the object-capability sense: it refers
105 to the ability of some principal to cause some action to occur, whether
106 because they can do it themselves, or because they can convince some other
107 principal to do it for them. In Tahoe terms, "storage authority" is the
108 ability to do one of the following actions:
109
110  * upload a new share, thus consuming storage space
111  * adding a new lease to a share, thus preventing space from being reclaimed
112  * modify an existing mutable share, potentially increasing the space consumed
113
114 The Accounting effort may involve other kinds of authority that get limited
115 in a similar manner as storage authority, like the ability to download a
116 share or query whether a given share is present: anything that may consume
117 CPU time, disk bandwidth, or other limited resources. The authority to renew
118 or cancel a lease may be controlled in a similar fashion.
119
120 Storage authority, as granted from a server operator to a client, is not
121 simply a binary "use space or not" grant. Instead, it is parameterized by a
122 number of "restrictions". The most important of these restrictions (with
123 respect to the goals of Accounting) is the "Account Label".
124
125 === Account Labels ===
126
127 A Tahoe "Account" is defined by a variable-length sequence of small integers.
128 (they are not required to be small, the actual limit is 2**64, but neither
129 are they required to be unguessable). For the purposes of discussion, these
130 lists will be expressed as period-joined strings: the two-element list (1,4)
131 will be displayed here as "1.4".
132
133 These accounts are arranged in a hierarchy: the account identifier 1.4 is
134 considered to be a "parent" of 1.4.2 . There is no relationship between the
135 values used by unrelated accounts: 1.4 is unrelated to 2.4, despite both
136 coincidentally using a "4" in the second element.
137
138 Each lease has a label, which contains the Account identifier. The storage
139 server maintains an aggregate size count for each label prefix: when asked
140 about account 1.4, it will report the amount of space used by shares labeled
141 1.4, 1.4.2, 1.4.7, 1.4.7.8, etc (but *not* 1 or 1.5).
142
143 The "Account Label" restriction allows a client to apply any label it wants,
144 as long as that label begins with a specific prefix. If account 1 is
145 associated with Alice, then Alice will receive a storage authority string
146 that contains a "must start with 1" restriction, enabling her to to use
147 storage space but obligating her to lease her shares with a label that can be
148 traced back to her. She can delegate part of her authority to others (perhaps
149 with other non-label restrictions, such as a space restriction or time limit)
150 with or without an additional label restriction. For example, she might
151 delegate some of her authority to her friend Amy, with a 1.4 label
152 restriction. Amy could then create labels with 1.4 or 1.4.7, but she could
153 not create labels with the same 1 identifier that Alice can do, nor could she
154 create labels with 1.5 (which Alice might have given to her other friend
155 Annette). The storage server operator can ask about the usage of 1 to find
156 out how much Alice is responsible for (which includes the space that she has
157 delegated to Amy and Annette), and none of the A-users can avoid being
158 counted in this total. But Alice can ask the storage server about the usage
159 of 1.4 to find out how much Amy has taken advantage of her gift. Likewise,
160 Alice has control over any lease with a label that begins with 1, so she can
161 cancel Amy's leases and free the space they were consuming. If this seems
162 surprising, consider that the storage server operator considered Alice to be
163 responsible for that space anyways: with great responsibility (for space
164 consumed) comes great power (to stop consuming that space).
165
166 === Server Space Restriction ===
167
168 The storage server's basic control over how space usage (apart from the
169 binary use-it-or-not authority granted by handing out an authority string at
170 all) is implemented by keeping track of the space used by any given account
171 identifier. If account 1.4 sends a request to allocate a 1MB share, but that
172 1MB would bring the 1.4 usage over its quota, the request will be denied.
173
174 For this to be useful, the storage server must give each usage-limited
175 principal a separate account, and it needs to configure a size limit at the
176 same time as the authority string is minted. For a friendnet, the CLI "add
177 account" tool can do both at once:
178
179  tahoe server add-account --quota 5GB Alice
180  --> Please give the following authority string to "Alice", who should
181      provide it to the "tahoe add-authority" command
182      (authority string..)
183
184 This command will allocate an account identifier, add Alice to the "pet name
185 table" to associate it with the new account, and establish the 5GB sizelimit.
186 Both the sizelimit and the petname can be changed later.
187
188 Note that this restriction is independent for each server: some additional
189 mechanism must be used to provide a grid-wide restriction.
190
191 Also note that this restriction is not expressed in the authority string. It
192 is purely local to the storage server.
193
194 === Attenuated Server Space Restriction ===
195
196 TODO (or not)
197
198 The server-side space restriction described above can only be applied by the
199 storage server, and cannot be attenuated by other delegates. Alice might be
200 allowed to use 5GB on this server, but she cannot use that restriction to
201 delegate, say, just 1GB to Amy.
202
203 Instead, Alice's sub-delegation should include a "server_size" restriction
204 key, which contains a size limit. The storage server will only honor a
205 request that uses this authority string if it does not cause the aggregate
206 usage of this authority string's account prefix to rise above the given size
207 limit.
208
209 Note that this will not enforce the desired restriction if the size limits
210 are not consistent across multiple delegated authorities for the same label.
211 For example, if Amy ends up with two delagations, A1 (which gives her a size
212 limit of 1GB) and A2 (which gives her 5GB), then she can consume 5GB despite
213 the limit in A1.
214
215 === Other Restrictions ===
216
217 Many storage authority restrictions are meant for internal use by tahoe tools
218 as they delegate short-lived subauthorities to each other, and are not likely
219 to be set by end users.
220
221  * "SI": a storage index string. The authority can only be used to upload
222    shares of a single file.
223  * "serverid": a server identifier. The authority can only be used when
224    talking to a specific server
225  * "UEB_hash": a binary hash. The authority can only be used to upload shares
226    of a single file, identified by its share's contents. (note: this
227    restricton would require the server to parse the share and validate the
228    hash)
229  * "before": a timestamp. The authority is only valid until a specific time.
230    Requires synchronized clocks or a better definition of "timestamp".
231  * "delegate_to_furl": a string, used to acquire a FURL for an object that
232    contains the attenuated authority. When it comes time to actually use the
233    authority string to do something, this is the first step.
234  * "delegate_to_key": an ECDSA pubkey, used to grant attenuated authority to
235    a separate private key.
236
237 == User Experience ==
238
239 The process starts with Bob the storage server operator, who has just created
240 a new Storage Server:
241
242  tahoe create-node
243  --> creates ~/.tahoe
244  # edit ~/.tahoe/tahoe.cfg, add introducer.furl, configure storage, etc
245
246 Now Bob decides that he wants to let his friend Alice use 5GB of space on his
247 new server.
248
249  tahoe server add-account --quota=5GB Alice
250  --> Please give the following authority string to "Alice", who should
251      provide it to the "tahoe add-authority" command
252      (authority string XYZ..)
253
254 Bob copies the new authority string into an email message and sends it to
255 Alice. Meanwhile, Alice has created her own client, and attached it to the
256 same Introducer as Bob. When she gets the email, she pastes the authority
257 string into her local client:
258
259  tahoe client add-authority (authority string XYZ..)
260  --> new authority added: account (1)
261
262 Now all CLI commands that Alice runs with her node will take advantage of
263 Bob's space grant. Once Alice's node connects to Bob's, any upload which
264 needs to send a share to Bob's server will search her list of authorities to
265 find one that allows her to use Bob's server.
266
267 When Alice uses her WUI, upload will be disabled until and unless she pastes
268 one or more authority strings into a special "storage authority" box. TODO:
269 Once pasted, we'll use some trick to keep the authority around in a
270 convenient-yet-safe fashion.
271
272 When Alice uses her javascript-based web drive, the javascript program will
273 be launched with some trick to hand it the storage authorities, perhaps via a
274 fragment identifier (http://server/path#fragment).
275
276 If Alice decides that she wants Amy to have some space, she takes the
277 authority string that Bob gave her and uses it to create one for Amy:
278
279  tahoe authority dump (authority string XYZ..)
280  --> explanation of what is in XYZ
281  tahoe authority delegate --account 4,1 --space 2GB (authority string XYZ..)
282  --> (new authority string ABC..)
283
284 Alice sends the ABC string to Amy, who uses "tahoe client add-authority" to
285 start using it.
286
287 Later, Bob would like to find out how much space Alice is using. He brings up
288 his node's Storage Server Web Status page. In addition to the overall usage
289 numbers, the page will have a collapsible-treeview table with lines like:
290
291  AccountID  Usage  TotalUsage Petname
292  (1)        1.5GB  2.5GB      Alice
293  +(1,4)     1.0GB  1.0GB      ?
294
295 This indicates that Alice, as a whole, is using 2.5GB. It also indicates that
296 Alice has delegated some space to a (1,4) account, and that delegation has
297 used 1.0GB. Alice has used 1.5GB on her own, but is responsible for the full
298 2.5GB. If Alice tells Bob that the subaccount is for Amy, then Bob can assign
299 a pet name for (1,4) with "tahoe server add-pet-name 1,4 Amy". Note that Bob
300 is not aware of the 2GB limit that Alice has imposed upon Amy: the size
301 restriction may have appeared on all the requests that have showed up thus
302 far, but Bob has no way of being sure that a less-restrictive delgation
303 hasn't been created, so his UI does not attempt to remember or present the
304 restrictions it has seen before.
305
306 === Friendnet ===
307
308 A "friendnet" is a set of nodes, each of which is both a storage server and a
309 client, each operated by a separate person, all of which have granted storage
310 rights to the others.
311
312 The simplest way to get a friendnet started is to simply grant storage
313 authority to everybody. "tahoe server enable-ambient-storage-authority" will
314 configure the storage server to give space to anyone who asks. This behaves
315 just like a 1.3.0 server, without accounting of any sort.
316
317 The next step is to restrict server use to just the participants. "tahoe
318 server disable-ambient-storage-authority" will undo the previous step, then
319 there are two basic approaches:
320
321  * "full mesh": each node grants authority directory to all the others.
322    First, agree upon a userid number for each participant (the value doesn't
323    matter, as long as it is unique). Each user should then use "tahoe server
324    add-account" for all the accounts (including themselves, if they want some
325    of their shares to land on their own machine), including a quota if they
326    wish to restrict individuals:
327
328     tahoe server add-account --account 1 --quota 5GB Alice
329     --> authority string for Alice
330     tahoe server add-account --account 2 --quota 5GB Bob
331     --> authority string for Bob
332     tahoe server add-account --account 3 --quota 5GB Carol
333     --> authority string for Carol
334
335   Then email Alice's string to Alice, Bob's string to Bob, etc. Once all
336   users have used "tahoe client add-authority" on everything, each server
337   will accept N distinct authorities, and each client will hold N distinct
338   authorities.
339
340  * "account manager": the group designates somebody to be the "AM", or
341    "account manager". The AM generates a keypair and publishes the public key
342    to all the participants, who create a local authority which delgates full
343    storage rights to the corresponding private key. The AM then delegates
344    account-restricted authority to each user, sending them their personal
345    authority string:
346
347     AM:
348      tahoe authority create-authority --write-private-to=private.txt
349      --> public.txt
350      # email public.txt to all members
351     AM:
352      tahoe authority delegate --from-file=private.txt --account 1 --quota 5GB
353      --> alice_authority.txt # email this to Alice
354      tahoe authority delegate --from-file=private.txt --account 2 --quota 5GB
355      --> bob_authority.txt # email this to Bob
356      tahoe authority delegate --from-file=private.txt --account 3 --quota 5GB
357      --> carol_authority.txt # email this to Carol
358      ...
359     Alice:
360      # receives alice_authority.txt
361      tahoe client add-authority --from-file=alice_authority.txt
362      # receives public.txt
363      tahoe server add-authorization --from-file=public.txt
364     Bob:
365      # receives bob_authority.txt
366      tahoe client add-authority --from-file=bob_authority.txt
367      # receives public.txt
368      tahoe server add-authorization --from-file=public.txt
369     Carol:
370      # receives carol_authority.txt
371      tahoe client add-authority --from-file=carol_authority.txt
372      # receives public.txt
373      tahoe server add-authorization --from-file=public.txt
374
375    If the members want to see names next to their local usage totals, they
376    can set local petnames for the accounts:
377
378      tahoe server set-petname 1 Alice
379      tahoe server set-petname 2 Bob
380      tahoe server set-petname 3 Carol
381
382    Alternatively, the AM could provide a usage aggregator, which will collect
383    usage values from all the storage servers and show the totals in a single
384    place, and add the petnames to that display instead.
385
386    The AM gets more authority than anyone else (they can spoof everybody),
387    but each server has just a single authorization instead of N, and each
388    client has a single authority instead of N. When a new member joins the
389    group, the amount of work that must be done is significantly less, and
390    only two parties are involved instead of all N:
391
392     AM:
393      tahoe authority delegate --from-file=private.txt --account 4 --quota 5GB
394      --> dave_authority.txt # email this to Dave
395     Dave:
396      # receives dave_authority.txt
397      tahoe client add-authority --from-file=dave_authority.txt
398      # receives public.txt
399      tahoe server add-authorization --from-file=public.txt
400
401    Another approach is to let everybody be the AM: instead of keeping the
402    private.txt file secret, give it to all members of the group (but not to
403    outsiders). This lets current members bring new members into the group
404    without depending upon anybody else doing work. It also renders any notion
405    of enforced quotas meaningless, so it is only appropriate for actual
406    friends who are voluntarily refraining from spoofing each other.
407
408 === Commercial Grid ===
409
410 A "commercial grid", like the one that allmydata.com manages as a for-profit
411 service, is characterized by a large number of independent clients (who do
412 not know each other), and by all of the storage servers being managed by a
413 single entity. In this case, we use an Account Manager like above, to
414 collapse the potential N*M explosion of authorities into something smaller.
415 We also create a dummy "parent" account, and give all the real clients
416 subaccounts under it, to give the operations personnel a convenient "total
417 space used" number. Each time a new customer joins, the AM is directed to
418 create a new authority for them, and the resulting string is provided to the
419 customer's client node.
420
421  AM:
422   tahoe authority create-authority --account 1 \
423    --write-private-to=AM-private.txt --write-public-to=AM-public.txt
424
425 Each time a new storage server is brought up:
426
427  SERVER:
428   tahoe server add-authorization --from-file=AM-public.txt
429
430 Each time a new client joins:
431
432  AM:
433   N = next_account++
434   tahoe authority delegate --from-file=AM-private.txt --account 1,N
435   --> new_client_authority.txt # give this to new client
436
437 == Programmatic Interfaces ==
438
439 The storage authority can be passed as a string in a single serialized form,
440 which is cut-and-pasteable and printable. It uses minimal punctuation, to
441 make it possible to include it as a URL query argument or HTTP header field
442 without requiring character-escaping.
443
444 Before passing it over HTTP, however, note that revealing the authority
445 string to someone is equivalent to irrevocably delegating all that authority
446 to them. While this is appropriate when transferring authority from, say, a
447 receptive storage server to your local agent, it is not appropriate when
448 using a foreign tahoe node, or when asking a Helper to upload a specific
449 file. Attenuations (see below) should be used to limit the delegated
450 authority in these cases.
451
452 In the programmatic web-API, any operation that consumes storage will accept
453 a storage-authority= query argument, the value of which will be the printable
454 form of an authority string. This includes all PUT operations, POST t=upload
455 and t=mkdir, and anything which creates a new file, creates a directory
456 (perhaps an intermediate one), or modifies a mutable file.
457
458 Alternatively, the authority string can also be passed through an HTTP
459 header. A single "X-Tahoe-Storage-Authority:" header can be used with the
460 printable authority string. If the string is too large to fit in a single
461 header, the application can provide a series of numbered
462 "X-Tahoe-Storage-Authority-1:", "X-Tahoe-Storage-Authority-2:", etc, headers,
463 and these will be sorted in alphabetical order (please use 08/09/10/11 rather
464 than 8/9/10/11), stripped of leading and trailing whitespace, and
465 concatenated. The HTTP header form can accomodate larger authority strings,
466 since these strings can grow too large to pass as a query argument
467 (especially when several delegations or attenuations are involved). However,
468 depending upon the HTTP client library being used, passing extra HTTP headers
469 may be more complicated than simply modifying the URL, and may be impossible
470 in some cases (such as javascript running in a web browser).
471
472 TODO: we may add a stored-token form of authority-passing to handle
473 environments in which query-args won't work and headers are not available.
474 This approach would use a special PUT which takes the authority string as the
475 HTTP body, and remembers it on the server side in associated with a
476 brief-but-unguessable token. Later operations would then use the authority by
477 passing a --storage-authority-token=XYZ query argument. These authorities
478 would expire after some period.
479
480 == Quota Management, Aggregation, Reporting ==
481
482 The storage server will maintain enough information to efficiently compute
483 usage totals for each account referenced in all of their leases, as well as
484 all their parent accounts. This information is used for several purposes:
485
486  * enforce server-space restrictions, by selectively rejecting storage
487    requests which would cause the account-usage-total to rise above the limit
488    specified in the enabling authorization string
489  * report individual account usage to the account-holder (if a client can
490    consume space under account A, they are also allowed to query usage for
491    account A or a subaccount).
492  * report individual account usage to the storage-server operator, possibly
493    associated with a pet name
494  * report usage for all accounts to the storage-server operator, possibly
495    associated with a pet name, in the form of a large table
496  * report usage for all accounts to an external aggregator
497
498 The external aggregator would take usage information from all the storage
499 servers in a single grid and sum them together, providing a grid-wide usage
500 number for each account. This could be used by e.g. clients in a commercial
501 grid to report overall-space-used to the end user.
502
503 There will be web-API URLs available for all of these reports.
504
505 TODO: storage servers might also have a mechanism to apply space-usage limits
506 to specific account ids directly, rather than requiring that these be
507 expressed only through authority-string limitation fields. This would let a
508 storage server operator revoke their space-allocation after delivering the
509 authority string.
510
511 == Low-Level Formats ==
512
513 This section describes the low-level formats used by the Accounting process,
514 beginning with the storage-authority data structure and working upwards. This
515 section is organized to follow the storage authority, starting from the point
516 of grant. The discussion will thus begin at the storage server (where the
517 authority is first created), work back to the client (which receives the
518 authority as a web-API argument), then follow the authority back to the
519 servers as it is used to enable specific storage operations. It will then
520 detail the accounting tables that the storage server is obligated to
521 maintain, and describe the interfaces through which these tables are accessed
522 by other parties.
523
524 === Storage Authority ===
525
526 ==== Terminology ====
527
528 Storage Authority is represented as a chain of certificates and a private
529 key. Each certificate authorizes and restricts a specific private key. The
530 initial certificate in the chain derives its authority by being placed in the
531 storage server's tahoe.cfg file (i.e. by being authorized by the storage
532 server operator). All subsequent certificates are signed by the authorized
533 private key that was identified in the previous certificate: they derive
534 their authority by delegation. Each certificate has restrictions which limit
535 the authority being delegated.
536
537  authority: ([cert[0], cert[1], cert[2] ...], privatekey)
538
539 The "restrictions dictionary" is a table which establishes an upper bound on
540 how this authority (or any attenuations thereof) may be used. It is
541 effectively a set of key-value pairs.
542
543 A "signing key" is an EC-DSA192 private key string, as supplied to the
544 pycryptopp SigningKey() constructor, and is 12 bytes long. A "verifying key"
545 is an EC-DSA192 public key string, as produced by pycryptopp, and is 24 bytes
546 long. A "key identifier" is a string which securely identifies a specific
547 signing/verifying keypair: for long RSA keys it would be a secure hash of the
548 public key, but since ECDSA192 keys are so short, we simply use the full
549 verifying key verbatim. A "key hint" is a variable-length prefix of the key
550 identifier, perhaps zero bytes long, used to help a recipient reduce the
551 number of verifying keys that it must search to find one that matches a
552 signed message.
553
554 ==== Authority Chains ====
555
556 The authority chain consists of a list of certificates, each of which has a
557 serialized restrictions dictionary. Each dictionary will have a
558 "delegate-to-key" field, which delegates authority to a private key,
559 referenced with a key identifier. In addition, the non-initial certs are
560 signed, so they each contain a signature and a key hint:
561
562  cert[0]: serialized(restrictions_dictionary)
563  cert[1]: serialized(restrictions_dictionary), signature, keyhint
564  cert[2]: serialized(restrictions_dictionary), signature, keyhint
565
566 In this example, suppose cert[0] contains a delegate-to-key field that
567 identifies a keypair sign_A/verify_A. In this case, cert[1] will have a
568 signature that was made with sign_A, and the keyhint in cert[1] will
569 reference verify_A.
570
571  cert[0].restrictions[delegate-to-key] = A_keyid
572
573  cert[1].signature = SIGN(sign_A, serialized(cert[0].restrictions))
574  cert[1].keyhint = verify_A
575  cert[1].restrictions[delegate-to-key] = B_keyid
576
577  cert[2].signature = SIGN(sign_B, serialized(cert[1].restrictions))
578  cert[2].keyhint = verify_B
579  cert[2].restrictions[delete-to-key] = C_keyid
580
581 In this example, the full storage authority consists of the cert[0,1,2] chain
582 and the sign_C private key: anyone who is in possession of both will be able
583 to exert this authority. To wield the authority, a client will present the
584 cert[0,1,2] chain and an action message signed by sign_C; the server will
585 validate the chain and the signature before performing the requested action.
586 The only circumstances that might prompt the client to share the sign_C
587 private key with another party (including the server) would be if it wanted
588 to irrevocably share its full authority with that party.
589
590 ==== Restriction Dictionaries ====
591
592 Within a restriction dictionary, the following keys are defined. Their full
593 meanings are defined later.
594
595  'accountid': an arbitrary-length sequence of integers >=0, restricting the
596               accounts which can be manipulated or used in leases
597  'SI': a storage index (binary string), controlling which file may be
598        manipulated
599  'serverid': binary string, limiting which server will accept requests
600  'UEB-hash': binary string, limiting the content of the file being manipulated
601  'before': timestamp (seconds since epoch), limits the lifetime of this
602            authority
603  'server-size': integer >0, maximum aggregate storage (in bytes) per account
604  'delegate-to-key': binary string (DSA pubkey identifier)
605  'furl-to': printable FURL string
606
607 ==== Authority Serialization ====
608
609 There is only one form of serialization: a somewhat-compact URL-safe
610 cut-and-pasteable printable form. We are interested in minimizing the size of
611 the resulting authority, so rather than using a general-purpose (perhaps
612 JSON-based) serialization scheme, we use one that is specialized for this
613 task.
614
615 This URL-safe form will use minimal punctuation to avoid quoting issues when
616 used in a URL query argument. It would be nice to avoid word-breaking
617 characters that make cut-and-paste troublesome, however this is more
618 difficult because most non-alphanumeric characters are word-breaking in at
619 least one application.
620
621 The serialized storage authority as a whole contains a single version
622 identifier and magic number at the beginning. None of the internal components
623 contain redundant version numbers: they are implied by the container. If
624 components are serialized independently for other reasons, they may contain
625 version identifers in that form.
626
627 Signing keys (i.e. private keys) are URL-safe-serialized using Zooko's base62
628 alphabet, which offers almost the same density as standard base64 but without
629 any non-URL-safe or word-breaking characters. Since we used fixed-format keys
630 (EC-DSA, 192bit, with SHA256), the private keys are fixed-length (96 bits or
631 12 bytes), so there is no length indicator: all URL-safe-serialized signing
632 keys are 17 base62 characters long. The 192-bit verifying keys (i.e. public
633 keys) use the same approach: the URL-safe form is 33 characters long.
634
635 An account-id sequence (a variable-length sequence of non-negative numbers)
636 is serialized by representing each number in decimal ASCII, then joining the
637 pieces with commas. The string is terminated by the first non-[0-9,]
638 character encountered, which will either be the key-identifier letter of the
639 next field, or the dictionary-terminating character at the end.
640
641 Any single integral decimal number (such as the "before" timestamp field, or
642 the "server-size" field) is serialized as a variable-length sequence of ASCII
643 decimal digits, terminated by any non-digit.
644
645 The restrictions dictionary is serialized as a concatenated series of
646 key-identifier-letter / value string pairs, ending with the marker "E.". The
647 URL-safe form uses a single printable letter to indicate the which key is
648 being serialized. Each type of value string is serialized differently:
649
650  "A": accountid: variable-length sequence of comma-joned numbers
651  "I": storage index: fixed-length 26-character *base32*-encoded storage index
652  "P": server id (peer id): fixed-length 32-character *base32* encoded serverid
653       (matching the printable Tub.tubID string that Foolscap provides)
654  "U": UEB hash: fixed-length 43-character base62 encoded UEB hash
655  "B": before: variable-length sequence of decimal digits, seconds-since-epoch.
656  "S": server-size: variable-length sequence of decimal digits, max size in bytes
657  "D": delegate-to-key: ECDSA public key, 33 base62 characters.
658  "F": furl-to: variable-length FURL string, wrapped in a netstring:
659       "%d:%s," % (len(FURL), FURL). Note that this is rarely pasted.
660  "E.": end-of-dictionary marker
661
662 The ECDSA signature is serialized as a variable number of base62 characters,
663 terminated by a period. We expect the signature to be about 384 bits (48
664 bytes) long, or 65 base62 characters. A missing signature (such as for the
665 initial cert) is represented as a single period.
666
667 The key hint is serialized with a base62-encoded serialized hint string (a
668 byte-quantized prefix of the serialized public key), terminated by a period.
669 An empty hint would thus be serialized as a single period. For the current
670 design, we expect the key hint to be empty.
671
672 The full storage authority string consists of a certificate chain and a
673 delegate private key. Given the single-certificate serialization scheme
674 described above, the full authority is serialized as follows:
675
676  * version prefix: depends upon the application, but for storage-authority
677                    chains this will be "sa0-", for Storage-Authority Version 0.
678  * serialized certificates, concatenated together
679  * serialized private key (to which the last certificate delegates authority)
680
681 Note that this serialization form does not have an explicit terminator, so
682 the environment must provide a length indicator or some other way to identify
683 the end of the authority string. The benefit of this approach is that the
684 full string will begin and end with alphanumeric characters, making
685 cut-and-paste easier (increasing the size of the mouse target: anywhere
686 within the final component will work).
687
688 Also note that the period is a reserved delimiter: it cannot appear in the
689 serialized restrictions dictionary. The parser can remove the version prefix,
690 split the rest on periods, and expect to see 3*k+1 fields, consisting of k
691 (restriction-dictionary,signature,keyhint) 3-tuples and a single private key
692 at the end.
693
694 Some examples:
695
696  (example A)
697  cert[0] delegates account 1,4 to (pubkey ZlFA / privkey 1f2S):
698
699   sa0-A1,4D2lFA6LboL2xx0ldQH2K1TdSrwuqMMiME3E...1f2SI9UJPXvb7vdJ1
700
701  (example B)
702  cert[0] delegates account 1,4 to ZlFA/1f2S
703  cert[1] subdelegates 5GB and subaccount 1,4,7 to pubkey 0BPo/06rt:
704
705   sa0-A1,4D2lFA6LboL2xx0ldQH2K1TdSrwuqMMiME3E...A1,4,7S5000000000D0BPoGxJ3M4KWrmdpLnknhJABrWip5e9kPE,7cyhQvv5axdeihmOzIHjs85TcUIYiWHdsxNz50GTerEOR5ucj2TITPXxyaCUli1oF...06rtcPQotR3q4f2cT
706
707
708
709
710
711
712
713 == Problems ==
714
715 Problems which have thus far been identified with this approach:
716
717  * allowing arbitrary subaccount generation will permit a DoS attack, in
718    which an authorized uploader consumes lots of DB space by creating an
719    unbounded number of randomly-generated subaccount identifiers. OTOH, they
720    can already attach an unbounded number of leases to any file they like,
721    consuming a lot of space.
722