woo
parent: tbd commit: 2d48bc0
1 | use Error; |
2 | use ; |
3 | use ; |
4 | use SystemTime; |
5 | use ; |
6 | use Table; |
7 | |
8 | use crate:: |
9 | |
10 | |
11 | AuthenticationTokenRequest, AuthenticationTokenResponse, TokenExtensionRequest, |
12 | TokenExtensionResponse, |
13 | , |
14 | InstanceAuthenticated, |
15 | , |
16 | , |
17 | ; |
18 | |
19 | |
20 | |
21 | pub user: User, |
22 | pub generated_for: Instance, |
23 | exp: u64, |
24 | |
25 | |
26 | |
27 | pub config: Table, |
28 | |
29 | |
30 | |
31 | async |
32 | let _secret_key = self.config |
33 | .as_str |
34 | .unwrap; |
35 | let mut file = open |
36 | self.config |
37 | .as_str |
38 | .unwrap, |
39 | |
40 | .await |
41 | .unwrap; |
42 | |
43 | let mut key = vec!; |
44 | file.read_to_end .await.unwrap; |
45 | |
46 | key |
47 | |
48 | |
49 | pub async |
50 | &mut self, |
51 | user: &User, |
52 | generated_for: &Instance, |
53 | |
54 | let private_key = self.private_key .await; |
55 | |
56 | let encoding_key = from_rsa_pem .unwrap; |
57 | |
58 | let claims = UserTokenMetadata |
59 | user: user.clone, |
60 | generated_for: generated_for.clone, |
61 | exp: |
62 | + from_secs |
63 | .as_secs, |
64 | ; |
65 | |
66 | encode |
67 | & new, |
68 | &claims, |
69 | &encoding_key, |
70 | |
71 | .unwrap |
72 | |
73 | |
74 | pub async |
75 | &mut self, |
76 | raw_request: , |
77 | |
78 | let request = raw_request.inner .await; |
79 | |
80 | info!; |
81 | raw_request |
82 | .validate |
83 | url: String from, |
84 | |
85 | .await |
86 | .unwrap; |
87 | |
88 | let secret_key = self.config |
89 | .as_str |
90 | .unwrap; |
91 | let private_key = |
92 | let mut file = open |
93 | self.config |
94 | .as_str |
95 | .unwrap, |
96 | |
97 | .await |
98 | .unwrap; |
99 | |
100 | let mut key = vec!; |
101 | file.read_to_end .await.unwrap; |
102 | |
103 | key |
104 | ; |
105 | |
106 | if request.secret_key != secret_key |
107 | error!; |
108 | |
109 | panic! |
110 | |
111 | |
112 | let encoding_key = from_rsa_pem .unwrap; |
113 | |
114 | let claims = UserTokenMetadata |
115 | user: User |
116 | username: String from, |
117 | instance: Instance |
118 | url: String from, |
119 | , |
120 | , |
121 | generated_for: Instance |
122 | url: String from, |
123 | , |
124 | exp: |
125 | + from_secs |
126 | .as_secs, |
127 | ; |
128 | |
129 | let token = encode |
130 | & new, |
131 | &claims, |
132 | &encoding_key, |
133 | |
134 | .unwrap; |
135 | |
136 | Ok |
137 | |
138 | |
139 | pub async |
140 | &mut self, |
141 | raw_request: , |
142 | |
143 | let request = raw_request.inner .await; |
144 | |
145 | // let server_public_key = { |
146 | // let mut file = File::open(self.config["keys"]["public"].as_str().unwrap()) |
147 | // .await |
148 | // .unwrap(); |
149 | |
150 | // let mut key = String::default(); |
151 | // file.read_to_string(&mut key).await.unwrap(); |
152 | |
153 | // key |
154 | // }; |
155 | |
156 | let server_public_key = public_key |
157 | url: String from, |
158 | |
159 | .await |
160 | .unwrap; |
161 | |
162 | let verification_key = from_rsa_pem .unwrap; |
163 | |
164 | let data: = decode |
165 | &request.token, |
166 | &verification_key, |
167 | & new, |
168 | |
169 | .unwrap; |
170 | |
171 | info!; |
172 | |
173 | let secret_key = self.config |
174 | .as_str |
175 | .unwrap; |
176 | |
177 | if request.secret_key != secret_key |
178 | error!; |
179 | |
180 | panic! |
181 | |
182 | // Validate request |
183 | raw_request |
184 | .validate |
185 | .await |
186 | .unwrap; |
187 | info!; |
188 | |
189 | let private_key = |
190 | let mut file = open |
191 | self.config |
192 | .as_str |
193 | .unwrap, |
194 | |
195 | .await |
196 | .unwrap; |
197 | |
198 | let mut key = vec!; |
199 | file.read_to_end .await.unwrap; |
200 | |
201 | key |
202 | ; |
203 | |
204 | let encoding_key = from_rsa_pem .unwrap; |
205 | |
206 | let claims = UserTokenMetadata |
207 | // TODO: Probably exploitable |
208 | user: data.claims.user, |
209 | generated_for: data.claims.generated_for, |
210 | exp: |
211 | + from_secs |
212 | .as_secs, |
213 | ; |
214 | |
215 | let token = encode |
216 | & new, |
217 | &claims, |
218 | &encoding_key, |
219 | |
220 | .unwrap; |
221 | |
222 | Ok |
223 | new_token: Some, |
224 | |
225 | |
226 | |
227 | |
228 | async |
229 | let key = get |
230 | .await? |
231 | .text |
232 | .await?; |
233 | |
234 | Ok |
235 | |
236 |