Unified stack refactor clean up
Clean up obsolete code and some warnings
parent: tbd commit: 356f714
1 | use |
2 | , | SocketAddr
3 | , | Deref
4 | , |
5 | ; |
6 | |
7 | use Error; |
8 | use ; |
9 | |
10 | use |
11 | , |
12 | , | OperationError
13 | , | Instance
14 | ; |
15 | |
16 | use ObjectBackend; |
17 | |
18 | use |
19 | , GiteratedMessage, AnyObject, | AuthenticatedPayload
20 | , | AnyOperation
21 | ; |
22 | use |
23 | , AuthenticatedInstance, AuthenticatedUser, StackOperationState, | GiteratedRuntime
24 | ; |
25 | use ; |
26 | use |
27 | , | DecodeRsaPublicKey
28 | , |
29 | , | Sha256
30 | , | Verifier
31 | RsaPublicKey, |
32 | ; |
33 | use Serialize; |
34 | |
35 | use ; |
36 | use ; |
37 | use Table; |
38 | |
39 | use crate:: |
40 | , | AuthenticationTokenGranter
41 | , |
42 | , | InstanceConnections
43 | , | PublicKeyCache
44 | ; |
45 | |
46 | use Connections; |
47 | |
48 | pub async |
49 | socket: , |
50 | connections: , |
51 | repository_backend: , |
52 | user_backend: , |
53 | auth_granter: , |
54 | settings_backend: , |
55 | addr: SocketAddr, |
56 | instance: impl , |
57 | instance_connections: , |
58 | config: Table, |
59 | runtime: , |
60 | mut operation_state: StackOperationState, |
61 | |
62 | let connection_state = ConnectionState |
63 | socket: new, |
64 | connections, |
65 | repository_backend, |
66 | user_backend, |
67 | auth_granter, |
68 | settings_backend, |
69 | addr, |
70 | instance: instance.to_owned, |
71 | handshaked: new, |
72 | key_cache: default, |
73 | instance_connections: instance_connections.clone, |
74 | config, |
75 | ; |
76 | |
77 | let _handshaked = false; |
78 | let mut key_cache = default; |
79 | |
80 | loop |
81 | let mut socket = connection_state.socket.lock .await; |
82 | let message = socket.next .await; |
83 | drop; |
84 | |
85 | match message |
86 | Some => |
87 | let payload = match message |
88 | => payload, | Binary
89 | => | Ping
90 | let mut socket = connection_state.socket.lock .await; |
91 | let _ = socket.send .await; |
92 | drop; |
93 | continue; |
94 | |
95 | => return, | Close
96 | _ => continue, |
97 | ; |
98 | |
99 | let message: AuthenticatedPayload = deserialize .unwrap; |
100 | |
101 | // Get authentication |
102 | let instance = |
103 | let mut verified_instance: = None; |
104 | for source in &message.source |
105 | if let Instance |
106 | instance, |
107 | signature, |
108 | = source |
109 | |
110 | let public_key = key_cache.get .await.unwrap; |
111 | let public_key = from_pkcs1_pem .unwrap; |
112 | let verifying_key = new; |
113 | |
114 | if verifying_key |
115 | .verify |
116 | &message.payload, |
117 | & try_from .unwrap, |
118 | |
119 | .is_ok |
120 | |
121 | verified_instance = |
122 | Some; |
123 | |
124 | break; |
125 | |
126 | |
127 | |
128 | |
129 | verified_instance |
130 | ; |
131 | |
132 | let user = |
133 | let mut verified_user = None; |
134 | if let Some = &instance |
135 | for source in &message.source |
136 | if let User = source |
137 | // Get token |
138 | let public_key = key_cache.get .await.unwrap; |
139 | |
140 | let token: = decode |
141 | token.as_ref, |
142 | & from_rsa_pem .unwrap, |
143 | & new, |
144 | |
145 | .unwrap; |
146 | |
147 | if token.claims.generated_for != *verified_instance.deref |
148 | // Nope! |
149 | break; |
150 | |
151 | |
152 | if token.claims.user != *user |
153 | // Nope! |
154 | break; |
155 | |
156 | |
157 | verified_user = Some; |
158 | break; |
159 | |
160 | |
161 | |
162 | |
163 | verified_user |
164 | ; |
165 | |
166 | let message: = message.into_message; |
167 | |
168 | operation_state.user = user; |
169 | operation_state.instance = instance; |
170 | |
171 | let result = runtime |
172 | .object_operation |
173 | message.object, |
174 | &message.operation, |
175 | message.payload, |
176 | &operation_state, |
177 | |
178 | .await; |
179 | |
180 | // Asking for exploits here |
181 | operation_state.user = None; |
182 | operation_state.instance = None; |
183 | |
184 | // Map result to Vec<u8> on both |
185 | let result = match result |
186 | Ok => Ok, |
187 | Err => Err |
188 | => | Operation
189 | Operation |
190 | |
191 | => Internal, | Internal
192 | => Unhandled, | Unhandled
193 | , |
194 | ; |
195 | |
196 | let mut socket = connection_state.socket.lock .await; |
197 | let _ = socket |
198 | .send |
199 | .await; |
200 | |
201 | drop; |
202 | |
203 | _ => |
204 | return; |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | socket: , |
213 | pub connections: , |
214 | pub repository_backend: , |
215 | pub user_backend: , |
216 | pub auth_granter: , |
217 | pub settings_backend: , |
218 | pub addr: SocketAddr, |
219 | pub instance: Instance, |
220 | pub handshaked: , |
221 | pub key_cache: , |
222 | pub instance_connections: , |
223 | pub config: Table, |
224 | |
225 | |
226 | |
227 | pub async |
228 | let payload = to_string?; |
229 | self.socket |
230 | .lock |
231 | .await |
232 | .send |
233 | .await?; |
234 | |
235 | Ok |
236 | |
237 | |
238 | pub async |
239 | let payload = to_string?; |
240 | self.socket |
241 | .lock |
242 | .await |
243 | .send |
244 | .await?; |
245 | |
246 | Ok |
247 | |
248 | |
249 | pub async |
250 | let mut keys = self.key_cache.lock .await; |
251 | keys.get .await |
252 | |
253 | |
254 |