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