Add all the user request handling
parent: tbd commit: e3bda14
1 | use Error; |
2 | use ; |
3 | use |
4 | , |
5 | , |
6 | , | Sha256
7 | , |
8 | RsaPrivateKey, RsaPublicKey, |
9 | ; |
10 | use ; |
11 | use Debug; |
12 | |
13 | use crate:: |
14 | , | UserTokenMetadata
15 | , | HandshakeMessage
16 | , |
17 | ; |
18 | |
19 | use |
20 | , DiscoveryMessage, | AuthenticationMessage
21 | , UserMessage, | RepositoryMessage
22 | ; |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | Handshake, |
33 | Repository, |
34 | Authentication, |
35 | Discovery, |
36 | User, |
37 | |
38 | |
39 | /// An authenticated message, where the instance is authenticating |
40 | /// a request it is making for itself. |
41 | |
42 | |
43 | message: T, |
44 | pub instance: Instance, |
45 | signature: , |
46 | |
47 | |
48 | |
49 | |
50 | T: PartialEq + Serialize, |
51 | |
52 | |
53 | self.message == other.message |
54 | && self.instance == other.instance |
55 | && self.signature == other.signature |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | T: Hash + Serialize, |
64 | |
65 | |
66 | self.message.hash; |
67 | self.instance.hash; |
68 | self.signature.hash; |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | T: Clone + Serialize, |
75 | |
76 | |
77 | Self |
78 | message: self.message.clone, |
79 | instance: self.instance.clone, |
80 | signature: self.signature.clone, |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | T: Debug + Serialize, |
88 | |
89 | |
90 | f.debug_struct |
91 | .field |
92 | .field |
93 | .field |
94 | .finish |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | let mut rng = thread_rng; |
101 | |
102 | let private_key = from_pkcs1_pem?; |
103 | let signing_key = new; |
104 | |
105 | let message_json = to_vec?; |
106 | |
107 | let signature = signing_key.sign_with_rng; |
108 | |
109 | Ok |
110 | message, |
111 | instance, |
112 | signature: signature.to_vec, |
113 | |
114 | |
115 | |
116 | pub async |
117 | &self.message |
118 | |
119 | |
120 | pub async |
121 | let public_key = public_key .await?; |
122 | let public_key = from_pkcs1_pem .unwrap; |
123 | |
124 | let verifying_key: = new; |
125 | |
126 | let message_json = to_vec .unwrap; |
127 | |
128 | verifying_key |
129 | .verify |
130 | &message_json, |
131 | & try_from .unwrap, |
132 | |
133 | .unwrap; |
134 | |
135 | Ok |
136 | |
137 | |
138 | |
139 | /// An authenticated message. |
140 | /// |
141 | /// Includes the message, with a digest generated with |
142 | /// our private key. |
143 | |
144 | |
145 | #[serde(flatten)] |
146 | message: T, |
147 | pub(crate) user: User, |
148 | |
149 | |
150 | |
151 | |
152 | T: Clone + Serialize, |
153 | |
154 | |
155 | Self |
156 | message: self.message.clone, |
157 | user: self.user.clone, |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | T: Debug + Serialize, |
165 | |
166 | |
167 | f.debug_struct |
168 | .field |
169 | .field |
170 | .finish |
171 | |
172 | |
173 | |
174 | |
175 | pub async |
176 | &self.message |
177 | |
178 | |
179 | pub async |
180 | &self.user |
181 | |
182 | |
183 | |
184 | /// An unvalidated authenticated message. |
185 | /// |
186 | /// Includes the message, with a digest generated with |
187 | /// our private key. |
188 | |
189 | |
190 | #[serde(flatten)] |
191 | message: T, |
192 | token: String, |
193 | digest: , |
194 | |
195 | |
196 | |
197 | |
198 | T: Clone + Serialize, |
199 | |
200 | |
201 | Self |
202 | message: self.message.clone, |
203 | token: self.token.clone, |
204 | digest: self.digest.clone, |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | T: Debug + Serialize, |
212 | |
213 | |
214 | f.debug_struct |
215 | .field |
216 | .field |
217 | .field |
218 | .finish |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | let mut rng = thread_rng; |
225 | |
226 | let private_key = from_pkcs1_pem?; |
227 | let signing_key = new; |
228 | |
229 | let message_json = to_vec?; |
230 | |
231 | let signature = signing_key.sign_with_rng; |
232 | |
233 | Ok |
234 | message, |
235 | token, |
236 | digest: signature.to_vec, |
237 | |
238 | |
239 | |
240 | pub async |
241 | &self.message |
242 | |
243 | |
244 | pub async |
245 | let instance = |
246 | let mut validation = new; |
247 | validation.insecure_disable_signature_validation; |
248 | |
249 | info!; |
250 | |
251 | let value: = |
252 | decode .unwrap; |
253 | |
254 | value.claims.generated_for.clone |
255 | ; |
256 | |
257 | let public_key_raw = public_key .await?; |
258 | let public_key = from_pkcs1_pem .unwrap; |
259 | |
260 | let verifying_key: = new; |
261 | |
262 | let message_json = to_vec .unwrap; |
263 | |
264 | verifying_key |
265 | .verify |
266 | &message_json, |
267 | & try_from .unwrap, |
268 | |
269 | .unwrap; |
270 | |
271 | let verification_key = from_rsa_pem .unwrap; |
272 | |
273 | let data: = decode |
274 | &self.token, |
275 | &verification_key, |
276 | & new, |
277 | |
278 | .unwrap; |
279 | |
280 | assert_eq!; |
281 | |
282 | Ok |
283 | message: self.message, |
284 | user: data.claims.user, |
285 | |
286 | |
287 | |
288 | |
289 | async |
290 | let key = get |
291 | .await? |
292 | .text |
293 | .await?; |
294 | |
295 | Ok |
296 | |
297 |