im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! Token-signing keys: how a key is made, which key signs now, which keys are published, and when the |
| 2 | //! next key is due. |
| 3 | //! |
| 4 | //! The chain (contracts section 2.2, architecture section 8): a key is created at least 24 hours before |
| 5 | //! it signs, so it is published first. A key signs for 90 days. When its successor is created, it is |
| 6 | //! retired at the successor's activation time, and it stays published for 7 more days, so tokens it |
| 7 | //! signed before then still verify. Every instant here is a stored stamp; the comparisons are text. |
| 8 | |
| 9 | use Duration; |
| 10 | |
| 11 | use SigningKey; |
| 12 | |
| 13 | use crateKeyRecord; |
| 14 | use crate; |
| 15 | |
| 16 | const DAY: Duration = from_secs; |
| 17 | |
| 18 | /// How long a key signs before its successor takes over. |
| 19 | pub const ROTATION_PERIOD: Duration = from_secs; |
| 20 | |
| 21 | /// How long before it signs a new key is created and published. |
| 22 | pub const PUBLISH_LEAD: Duration = DAY; |
| 23 | |
| 24 | /// How long a retired key stays published after its retirement. |
| 25 | pub const OVERLAP: Duration = from_secs; |
| 26 | |
| 27 | /// A freshly generated key: its id, its seed (the private key) and its public key. |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | /// Generates a new Ed25519 key with a random seed and a random `kid`. |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | /// The key that signs at `now`: the newest one whose activation has come and that is not yet retired. |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | /// The keys published at `now`: every key not retired, and every key retired less than [`OVERLAP`] ago. |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /// Whether a new key must be created at `now`, and if so when it activates. `None` means the chain is |
| 77 | /// fine: a key is pending, or the current one is not due within the publish lead. |
| 78 | /// |
| 79 | /// With no key at all, the new key activates at once. Otherwise it activates [`PUBLISH_LEAD`] from now, |
| 80 | /// which is the first moment it can be published, and the newest key is retired at that same instant. |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 |