Add docs
parent: tbd commit: 51aad53
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 | .await |
37 | .unwrap; |
38 | |
39 | let mut key = vec!; |
40 | file.read_to_end .await.unwrap; |
41 | |
42 | key |
43 | |
44 | |
45 | pub async |
46 | &mut self, |
47 | user: &User, |
48 | generated_for: &Instance, |
49 | |
50 | let private_key = self.private_key .await; |
51 | |
52 | let encoding_key = from_rsa_pem .unwrap; |
53 | |
54 | let claims = UserTokenMetadata |
55 | user: user.clone, |
56 | generated_for: generated_for.clone, |
57 | exp: |
58 | + from_secs |
59 | .as_secs, |
60 | ; |
61 | |
62 | encode |
63 | & new, |
64 | &claims, |
65 | &encoding_key, |
66 | |
67 | .unwrap |
68 | |
69 | |
70 | pub async |
71 | &mut self, |
72 | raw_request: , |
73 | |
74 | let request = raw_request.inner .await; |
75 | |
76 | info!; |
77 | raw_request |
78 | .validate |
79 | url: String from, |
80 | |
81 | .await |
82 | .unwrap; |
83 | |
84 | let secret_key = self.config |
85 | .as_str |
86 | .unwrap; |
87 | let private_key = |
88 | let mut file = open |
89 | .await |
90 | .unwrap; |
91 | |
92 | let mut key = vec!; |
93 | file.read_to_end .await.unwrap; |
94 | |
95 | key |
96 | ; |
97 | |
98 | if request.secret_key != secret_key |
99 | error!; |
100 | |
101 | panic! |
102 | |
103 | |
104 | let encoding_key = from_rsa_pem .unwrap; |
105 | |
106 | let claims = UserTokenMetadata |
107 | user: User |
108 | username: String from, |
109 | instance: Instance |
110 | url: String from, |
111 | , |
112 | , |
113 | generated_for: Instance |
114 | url: String from, |
115 | , |
116 | exp: |
117 | + from_secs |
118 | .as_secs, |
119 | ; |
120 | |
121 | let token = encode |
122 | & new, |
123 | &claims, |
124 | &encoding_key, |
125 | |
126 | .unwrap; |
127 | |
128 | Ok |
129 | |
130 | |
131 | pub async |
132 | &mut self, |
133 | raw_request: , |
134 | |
135 | let request = raw_request.inner .await; |
136 | |
137 | // let server_public_key = { |
138 | // let mut file = File::open(self.config["keys"]["public"].as_str().unwrap()) |
139 | // .await |
140 | // .unwrap(); |
141 | |
142 | // let mut key = String::default(); |
143 | // file.read_to_string(&mut key).await.unwrap(); |
144 | |
145 | // key |
146 | // }; |
147 | |
148 | let server_public_key = public_key |
149 | url: String from, |
150 | |
151 | .await |
152 | .unwrap; |
153 | |
154 | let verification_key = from_rsa_pem .unwrap; |
155 | |
156 | let data: = decode |
157 | &request.token, |
158 | &verification_key, |
159 | & new, |
160 | |
161 | .unwrap; |
162 | |
163 | info!; |
164 | |
165 | let secret_key = self.config |
166 | .as_str |
167 | .unwrap; |
168 | |
169 | if request.secret_key != secret_key |
170 | error!; |
171 | |
172 | panic! |
173 | |
174 | // Validate request |
175 | raw_request |
176 | .validate |
177 | .await |
178 | .unwrap; |
179 | info!; |
180 | |
181 | let private_key = |
182 | let mut file = open |
183 | .await |
184 | .unwrap; |
185 | |
186 | let mut key = vec!; |
187 | file.read_to_end .await.unwrap; |
188 | |
189 | key |
190 | ; |
191 | |
192 | let encoding_key = from_rsa_pem .unwrap; |
193 | |
194 | let claims = UserTokenMetadata |
195 | // TODO: Probably exploitable |
196 | user: data.claims.user, |
197 | generated_for: data.claims.generated_for, |
198 | exp: |
199 | + from_secs |
200 | .as_secs, |
201 | ; |
202 | |
203 | let token = encode |
204 | & new, |
205 | &claims, |
206 | &encoding_key, |
207 | |
208 | .unwrap; |
209 | |
210 | Ok |
211 | new_token: Some, |
212 | |
213 | |
214 | |
215 | |
216 | async |
217 | let key = get |
218 | .await? |
219 | .text |
220 | .await?; |
221 | |
222 | Ok |
223 | |
224 |