Coverage / crates/flow-core/src/alert.rs 100.0%
55 of 55 lines run, 6 of 11 functions · run #227 on main · run missed
| 1 | //! Sealed alerts (oxygenhub-android#16): what a phone is told about a job, | |
| 2 | //! encrypted to a key the phone made, so the push service that carries it | |
| 3 | //! (Firebase Cloud Messaging) sees only ciphertext. | |
| 4 | //! | |
| 5 | //! The phone keeps an X25519 secret and gives the hub its public key. For | |
| 6 | //! each alert the hub makes a fresh X25519 key, agrees a secret with the | |
| 7 | //! phone's key, derives a ChaCha20-Poly1305 key with HKDF-SHA256 (salted | |
| 8 | //! with both public keys) and encrypts once under it with a zero nonce: | |
| 9 | //! the key is never used twice. A sealed alert is the fresh public key (32 | |
| 10 | //! bytes) followed by the ciphertext and its tag. | |
| 11 | | |
| 12 | use MontgomeryPoint; | |
| 13 | use ; | |
| 14 | use hkdf; | |
| 15 | use ; | |
| 16 | ||
| 17 | /// What HKDF binds the key to, so a key for anything else never fits. | |
| 18 | const INFO: & = b"oxygenhub alert v1"; | |
| 19 | ||
| 20 | /// A new X25519 secret, for a phone to keep. | |
| 21 | 5× | |
| 22 | 5× | |
| 23 | 5× | |
| 24 | 5× | |
| 25 | 5× | |
| 26 | ||
| 27 | /// The public key of `secret`, for the hub. | |
| 28 | 8× | |
| 29 | 8× | |
| 30 | 8× | |
| 31 | ||
| 32 | 6× | |
| 33 | | |
| 34 | 6× | |
| 35 | 1× | |
| 36 | 5× | |
| 37 | 5× | |
| 38 | 5× | |
| 39 | 5× | |
| 40 | 5× | |
| 41 | 5× | |
| 42 | 5× | |
| 43 | 5× | |
| 44 | 5× | |
| 45 | 6× | |
| 46 | ||
| 47 | /// Seal `message` to the phone whose public key is `recipient`; `None` | |
| 48 | /// when that key is unusable. | |
| 49 | 3× | |
| 50 | 3× | |
| 51 | 3× | |
| 52 | 3× | |
| 53 | 3× | |
| 54 | 2× | |
| 55 | 2× | |
| 56 | 2× | |
| 57 | 2× | |
| 58 | 2× | |
| 59 | 3× | |
| 60 | ||
| 61 | /// Open an alert sealed to the phone whose secret is `secret`; `None` when | |
| 62 | /// it was not sealed to it or was changed on the way. | |
| 63 | 4× | |
| 64 | 4× | |
| 65 | 1× | |
| 66 | 3× | |
| 67 | 3× | |
| 68 | 3× | |
| 69 | 3× | |
| 70 | 3× | |
| 71 | 3× | |
| 72 | 1× | |
| 73 | 4× | |
| 74 | ||
| 75 | | |
| 76 | | |
| 77 | | |
| 78 | | |
| 79 | | |
| 80 | 1× | |
| 81 | 1× | |
| 82 | 1× | |
| 83 | 1× | |
| 84 | | |
| 85 | 1× | |
| 86 | 1× | |
| 87 | 1× | |
| 88 | 1× | |
| 89 | 1× | |
| 90 | 1× | |
| 91 | | |
| 92 | 1× | |
| 93 | 1× | |
| 94 | |