Automatically populate the target instance field from the request using MessageTarget trait
parent: tbd commit: 37da513
1 | use ; |
2 | |
3 | use Error; |
4 | use Future; |
5 | use |
6 | , |
7 | , | Instance
8 | , | User
9 | ; |
10 | use ; |
11 | use |
12 | , | DecodeRsaPublicKey
13 | , |
14 | , | Sha256
15 | , | Verifier
16 | RsaPublicKey, |
17 | ; |
18 | use ; |
19 | |
20 | use crate ConnectionState; |
21 | |
22 | ; |
23 | |
24 | |
25 | type Target = ; |
26 | |
27 | |
28 | &self.0 |
29 | |
30 | |
31 | |
32 | ; |
33 | |
34 | |
35 | |
36 | |
37 | Missing, |
38 | // #[error("{0}")] |
39 | // InstanceAuthentication(#[from] Error), |
40 | |
41 | InvalidToken, |
42 | |
43 | Other, |
44 | |
45 | |
46 | ; |
47 | |
48 | |
49 | |
50 | &self.0 |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | async ; |
57 | |
58 | |
59 | |
60 | |
61 | async |
62 | network_message: &NetworkMessage, |
63 | state: &ConnectionState, |
64 | |
65 | let message: AuthenticatedPayload = |
66 | map_err?; | from_slice .
67 | |
68 | let = message |
69 | .source |
70 | .iter |
71 | .filter_map |
72 | if let User = auth |
73 | Some |
74 | else |
75 | None |
76 | |
77 | |
78 | .next |
79 | .ok_or_else?; |
80 | |
81 | let authenticated_instance = |
82 | ?; | from_message .await
83 | |
84 | let public_key_raw = state.public_key .await?; |
85 | let verification_key = from_rsa_pem .unwrap; |
86 | |
87 | let data: = decode |
88 | auth_token.as_ref, |
89 | &verification_key, |
90 | & new, |
91 | |
92 | .unwrap; |
93 | |
94 | if data.claims.user != *auth_user |
95 | || data.claims.generated_for != *authenticated_instance.inner |
96 | |
97 | Err |
98 | else |
99 | Ok |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | async |
107 | network_message: &NetworkMessage, |
108 | state: &ConnectionState, |
109 | |
110 | let message: AuthenticatedPayload = |
111 | map_err?; | from_slice .
112 | |
113 | info!; |
114 | |
115 | let = message |
116 | .source |
117 | .iter |
118 | .filter_map |
119 | if let Instance |
120 | instance, |
121 | signature, |
122 | = auth |
123 | |
124 | Some |
125 | else |
126 | None |
127 | |
128 | |
129 | .next |
130 | // TODO: Instance authentication error |
131 | .ok_or_else?; |
132 | |
133 | info!; |
134 | |
135 | info!; |
136 | |
137 | let public_key = from_pkcs1_pem .unwrap; |
138 | |
139 | let verifying_key: = new; |
140 | |
141 | verifying_key.verify |
142 | &message.payload, |
143 | & try_from .unwrap, |
144 | ?; |
145 | |
146 | Ok |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | T: , |
154 | S: Send + Sync + 'static, |
155 | |
156 | async |
157 | Ok |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | async ; |
164 | |
165 | |
166 | |
167 | |
168 | T: FnOnce(T1) -> F + Clone + Send + 'static, |
169 | F: + Send, |
170 | T1: + Send, |
171 | S: Send + Sync, |
172 | E: Error + Send + Sync + 'static, |
173 | |
174 | async |
175 | let value = T1 from_message .await?; |
176 | self .await.map_err |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | T: FnOnce(T1, T2) -> F + Clone + Send + 'static, |
184 | F: + Send, |
185 | T1: + Send, |
186 | T2: + Send, |
187 | S: Send + Sync, |
188 | E: Error + Send + Sync + 'static, |
189 | |
190 | async |
191 | let value = T1 from_message .await?; |
192 | let value_2 = T2 from_message .await?; |
193 | self .await.map_err |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | |
200 | T: FnOnce(T1, T2, T3) -> F + Clone + Send + 'static, |
201 | F: + Send, |
202 | T1: + Send, |
203 | T2: + Send, |
204 | T3: + Send, |
205 | S: Send + Sync, |
206 | E: Error + Send + Sync + 'static, |
207 | |
208 | async |
209 | let value = T1 from_message .await?; |
210 | let value_2 = T2 from_message .await?; |
211 | let value_3 = T3 from_message .await?; |
212 | |
213 | self |
214 | .await |
215 | .map_err |
216 | |
217 | |
218 | |
219 | ; |
220 | |
221 | |
222 | |
223 | |
224 | T: Clone + Send + Sync, |
225 | |
226 | async |
227 | Ok |
228 | |
229 | |
230 | |
231 | // Temp |
232 | |
233 | |
234 | |
235 | T: DeserializeOwned + Send + Sync + Serialize + Debug, |
236 | S: Clone + Send + Sync, |
237 | |
238 | async |
239 | let payload: AuthenticatedPayload = from_slice?; |
240 | let payload = deserialize?; |
241 | |
242 | info!; |
243 | |
244 | Ok |
245 | |
246 | |
247 | |
248 | ; |
249 | |
250 | /// Handshake-specific message type. |
251 | /// |
252 | /// Uses basic serde_json-based deserialization to maintain the highest |
253 | /// level of compatibility across versions. |
254 | ; |
255 | |
256 | |
257 | |
258 | |
259 | T: DeserializeOwned + Send + Sync + Serialize, |
260 | S: Clone + Send + Sync, |
261 | |
262 | async |
263 | Ok |
264 | |
265 | |
266 |