|
1 | 1 | #pragma once
|
2 | 2 |
|
3 |
| -#include <session/config/pro.h> |
4 |
| - |
5 |
| -#include <chrono> |
6 |
| -#include <cstdint> |
7 | 3 | #include <session/config.hpp>
|
8 | 4 | #include <session/config/base.hpp>
|
9 |
| -#include <session/sodium_array.hpp> |
10 |
| -#include <session/types.hpp> |
| 5 | +#include <session/session_protocol.hpp> |
11 | 6 |
|
12 | 7 | namespace session::config {
|
13 | 8 |
|
14 |
| -enum ProProofVersion { ProProofVersion_v0 }; |
15 |
| - |
16 |
| -enum class ProStatus { |
17 |
| - // Pro proof sig was not signed by the Pro backend key |
18 |
| - InvalidProBackendSig = PRO_STATUS_INVALID_PRO_BACKEND_SIG, |
19 |
| - // Pro sig in the envelope was not signed by the Rotating key |
20 |
| - InvalidUserSig = PRO_STATUS_INVALID_USER_SIG, |
21 |
| - Valid = PRO_STATUS_VALID, // Proof is verified; has not expired |
22 |
| - Expired = PRO_STATUS_EXPIRED, // Proof is verified; has expired |
23 |
| -}; |
24 |
| - |
25 |
| -struct ProSignedMessage { |
26 |
| - std::span<const uint8_t> sig; |
27 |
| - std::span<const uint8_t> msg; |
28 |
| -}; |
29 |
| - |
30 |
| -/// keys used currently or in the past (so that we don't reuse): |
31 |
| -/// |
32 |
| -/// @ - version |
33 |
| -/// g - gen_index_hash |
34 |
| -/// r - rotating ed25519 pubkey |
35 |
| -/// e - expiry unix timestamp (in seconds) |
36 |
| -/// s - proof signature, signed by the Session Pro Backend's ed25519 key |
37 |
| -class ProProof { |
38 |
| - public: |
39 |
| - /// Version of the proof set by the Session Pro Backend |
40 |
| - std::uint8_t version; |
41 |
| - |
42 |
| - /// Hash of the generation index set by the Session Pro Backend |
43 |
| - array_uc32 gen_index_hash; |
44 |
| - |
45 |
| - /// The public key that the Session client registers their Session Pro entitlement under. |
46 |
| - /// Session clients must sign messages with this key along side the sending of this proof for |
47 |
| - /// the network to authenticate their usage of the proof |
48 |
| - array_uc32 rotating_pubkey; |
49 |
| - |
50 |
| - /// Unix epoch timestamp to which this proof's entitlement to Session Pro features is valid to |
51 |
| - std::chrono::sys_seconds expiry_unix_ts; |
52 |
| - |
53 |
| - /// Signature over the contents of the proof. It is signed by the Session Pro Backend key which |
54 |
| - /// is the entity responsible for issueing tamper-proof Sesison Pro certificates for Session |
55 |
| - /// clients. |
56 |
| - array_uc64 sig; |
57 |
| - |
58 |
| - /// API: pro/Proof::verify_signature |
59 |
| - /// |
60 |
| - /// Verify that the proof's contents was not tampered with by hashing the proof and checking |
61 |
| - /// that the hash was signed by the secret key of the given Ed25519 public key. |
62 |
| - /// |
63 |
| - /// For Session Pro intents and purposes, we expect proofs to be signed by the Session Pro |
64 |
| - /// Backend public key. This function throws if an incorrectly sized key is passed in. |
65 |
| - /// |
66 |
| - /// Inputs: |
67 |
| - /// - `verify_pubkey` -- 32 byte Ed25519 public key of the corresponding secret key to check if |
68 |
| - /// they are the original signatory of the proof. |
69 |
| - /// |
70 |
| - /// Outputs: |
71 |
| - /// - `bool` - True if the given key was the signatory of the proof, false otherwise |
72 |
| - bool verify_signature(const std::span<const uint8_t>& verify_pubkey) const; |
73 |
| - |
74 |
| - /// API: pro/Proof::verify_message |
75 |
| - /// |
76 |
| - /// Check if the `rotating_pubkey` in the proof was the signatory of the message and signature |
77 |
| - /// passed in. This function throws if an signature is passed in that isn't 64 bytes. |
78 |
| - /// |
79 |
| - /// Inputs: |
80 |
| - /// - `sig` -- Signature to verify with the `rotating_pubkey`. The signature should have |
81 |
| - /// originally been signed over `msg` passed in. |
82 |
| - /// - `msg` -- Message that the signature signed over with. It will be verified using the |
83 |
| - /// embedded `rotating_pubkey`. |
84 |
| - /// |
85 |
| - /// Outputs: |
86 |
| - /// - `bool` - True if the message was signed by the embedded `rotating_pubkey` false otherwise. |
87 |
| - bool verify_message(std::span<const uint8_t> sig, const std::span<const uint8_t> msg) const; |
88 |
| - |
89 |
| - /// API: pro/Proof::is_active |
90 |
| - /// |
91 |
| - /// Check if Pro proof is currently entitled to Pro given the `unix_ts` with respect to the |
92 |
| - /// proof's `expiry_unix_ts` |
93 |
| - /// |
94 |
| - /// Inputs: |
95 |
| - /// - `unix_ts` -- Unix timestamp in seconds to compared against the embedded `expiry_unix_ts` |
96 |
| - /// to determine if the proof has expired or not |
97 |
| - /// |
98 |
| - /// Outputs: |
99 |
| - /// - `bool` - True if proof is active (i.e. has not expired), false otherwise. |
100 |
| - bool is_active(std::chrono::sys_seconds unix_ts) const; |
101 |
| - |
102 |
| - /// API: pro/Proof::status |
103 |
| - /// |
104 |
| - /// Evaluate the status of the pro proof by checking it is signed by the `verify_pubkey`, it has |
105 |
| - /// not expired via `unix_ts` and optionally verify that the `signed_msg` was signed by the |
106 |
| - /// `rotating_pubkey` embedded in the proof. |
107 |
| - /// |
108 |
| - /// Internally this function calls `verify_signature`, `verify_message` and optionally |
109 |
| - /// `is_active` in sequence. This function throws if an invalidly sized public key or signature |
110 |
| - /// are passed in. They must be 32 and 64 bytes respectively. |
111 |
| - /// |
112 |
| - /// Inputs: |
113 |
| - /// - `verify_pubkey` -- 32 byte Ed25519 public key of the corresponding secret key to check if |
114 |
| - /// they are the original signatory of the proof. |
115 |
| - /// - `unix_ts` -- Unix timestamp in seconds to compared against the embedded `expiry_unix_ts` |
116 |
| - /// to determine if the proof has expired or not |
117 |
| - /// - `signed_msg` -- Optionally set the payload to the message with the signature to verify if |
118 |
| - /// the embedded `rotating_pubkey` in the proof signed the given message. |
119 |
| - /// |
120 |
| - /// Outputs: |
121 |
| - /// - `ProStatus` - The derived status given the components of the message. If `signed_msg` is |
122 |
| - /// not set then this function can never return `ProStatus::InvalidUserSig` from the set of |
123 |
| - /// possible enum values. Otherwise this funtion can return all possible values. |
124 |
| - ProStatus status( |
125 |
| - std::span<const uint8_t> verify_pubkey, |
126 |
| - std::chrono::sys_seconds unix_ts, |
127 |
| - const std::optional<ProSignedMessage>& signed_msg); |
128 |
| - |
129 |
| - /// API: pro/Proof::hash |
130 |
| - /// |
131 |
| - /// Create a 32-byte hash from the proof. This hash is the payload that is signed in the proof. |
132 |
| - array_uc32 hash() const; |
133 |
| - |
134 |
| - bool load(const dict& root); |
135 |
| -}; |
136 |
| - |
137 | 9 | /// keys used currently or in the past (so that we don't reuse):
|
138 | 10 | ///
|
139 |
| -/// r - rotating ed25519 privkey |
140 |
| -/// p - proof |
| 11 | +/// p + pro data |
| 12 | +/// | |
| 13 | +/// +-- @ - version |
| 14 | +/// +-- g - gen_index_hash |
| 15 | +/// +-- r - rotating ed25519 pubkey |
| 16 | +/// +-- e - expiry unix timestamp (in seconds) |
| 17 | +/// +-- s - proof signature, signed by the Session Pro Backend's ed25519 key |
| 18 | +/// +-- r - rotating ed25519 privkey |
| 19 | +/// +-- p - proof |
141 | 20 | class ProConfig {
|
142 | 21 | public:
|
143 | 22 | /// Private key for the public key key specified in the proof. This is synced between clients
|
|
0 commit comments