| 1 | .. -*- coding: utf-8 -*- |
|---|
| 2 | |
|---|
| 3 | .. _share leases: |
|---|
| 4 | |
|---|
| 5 | Share Leases |
|---|
| 6 | ============ |
|---|
| 7 | |
|---|
| 8 | A lease is a marker attached to a share indicating that some client has asked for that share to be retained for some amount of time. |
|---|
| 9 | The intent is to allow clients and servers to collaborate to determine which data should still be retained and which can be discarded to reclaim storage space. |
|---|
| 10 | Zero or more leases may be attached to any particular share. |
|---|
| 11 | |
|---|
| 12 | Renewal Secrets |
|---|
| 13 | --------------- |
|---|
| 14 | |
|---|
| 15 | Each lease is uniquely identified by its **renewal secret**. |
|---|
| 16 | This is a 32 byte string which can be used to extend the validity period of that lease. |
|---|
| 17 | |
|---|
| 18 | To a storage server a renewal secret is an opaque value which is only ever compared to other renewal secrets to determine equality. |
|---|
| 19 | |
|---|
| 20 | Storage clients will typically want to follow a scheme to deterministically derive the renewal secret for a particular share from information the client already holds about that share. |
|---|
| 21 | This allows a client to maintain and renew single long-lived lease without maintaining additional local state. |
|---|
| 22 | |
|---|
| 23 | The scheme in use in Tahoe-LAFS as of 1.16.0 is as follows. |
|---|
| 24 | |
|---|
| 25 | * The **netstring encoding** of a byte string is the concatenation of: |
|---|
| 26 | |
|---|
| 27 | * the ascii encoding of the base 10 representation of the length of the string |
|---|
| 28 | * ``":"`` |
|---|
| 29 | * the string itself |
|---|
| 30 | * ``","`` |
|---|
| 31 | |
|---|
| 32 | * The **sha256d digest** is the **sha256 digest** of the **sha256 digest** of a string. |
|---|
| 33 | * The **sha256d tagged digest** is the **sha256d digest** of the concatenation of the **netstring encoding** of one string with one other unmodified string. |
|---|
| 34 | * The **sha256d tagged pair digest** the **sha256d digest** of the concatenation of the **netstring encodings** of each of three strings. |
|---|
| 35 | * The **bucket renewal tag** is ``"allmydata_bucket_renewal_secret_v1"``. |
|---|
| 36 | * The **file renewal tag** is ``"allmydata_file_renewal_secret_v1"``. |
|---|
| 37 | * The **client renewal tag** is ``"allmydata_client_renewal_secret_v1"``. |
|---|
| 38 | * The **lease secret** is a 32 byte string, typically randomly generated once and then persisted for all future uses. |
|---|
| 39 | * The **client renewal secret** is the **sha256d tagged digest** of (**lease secret**, **client renewal tag**). |
|---|
| 40 | * The **storage index** is constructed using a capability-type-specific scheme. |
|---|
| 41 | See ``storage_index_hash`` and ``ssk_storage_index_hash`` calls in ``src/allmydata/uri.py``. |
|---|
| 42 | * The **file renewal secret** is the **sha256d tagged pair digest** of (**file renewal tag**, **client renewal secret**, **storage index**). |
|---|
| 43 | * The **base32 encoding** is ``base64.b32encode`` lowercased and with trailing ``=`` stripped. |
|---|
| 44 | * The **peer id** is the **base32 encoding** of the SHA1 digest of the server's x509 certificate. |
|---|
| 45 | * The **renewal secret** is the **sha256d tagged pair digest** of (**bucket renewal tag**, **file renewal secret**, **peer id**). |
|---|
| 46 | |
|---|
| 47 | A reference implementation is available. |
|---|
| 48 | |
|---|
| 49 | .. literalinclude:: derive_renewal_secret.py |
|---|
| 50 | :language: python |
|---|
| 51 | :linenos: |
|---|
| 52 | |
|---|
| 53 | Cancel Secrets |
|---|
| 54 | -------------- |
|---|
| 55 | |
|---|
| 56 | Lease cancellation is unimplemented. |
|---|
| 57 | Nevertheless, |
|---|
| 58 | a cancel secret is sent by storage clients to storage servers and stored in lease records. |
|---|
| 59 | |
|---|
| 60 | The scheme for deriving **cancel secret** in use in Tahoe-LAFS as of 1.16.0 is similar to that used to derive the **renewal secret**. |
|---|
| 61 | |
|---|
| 62 | The differences are: |
|---|
| 63 | |
|---|
| 64 | * Use of **client renewal tag** is replaced by use of **client cancel tag**. |
|---|
| 65 | * Use of **file renewal secret** is replaced by use of **file cancel tag**. |
|---|
| 66 | * Use of **bucket renewal tag** is replaced by use of **bucket cancel tag**. |
|---|
| 67 | * **client cancel tag** is ``"allmydata_client_cancel_secret_v1"``. |
|---|
| 68 | * **file cancel tag** is ``"allmydata_file_cancel_secret_v1"``. |
|---|
| 69 | * **bucket cancel tag** is ``"allmydata_bucket_cancel_secret_v1"``. |
|---|