Major post-refactor cleanup
parent: tbd commit: f90d7fb
1 | use Error; |
2 | use ; |
3 | use ; |
4 | use SystemTime; |
5 | use ; |
6 | use Table; |
7 | |
8 | use crate:: |
9 | , |
10 | , |
11 | ; |
12 | |
13 | |
14 | |
15 | pub user: User, |
16 | pub generated_for: Instance, |
17 | exp: u64, |
18 | |
19 | |
20 | |
21 | pub config: Table, |
22 | pub instance: Instance, |
23 | |
24 | |
25 | |
26 | async |
27 | let _secret_key = self.config |
28 | .as_str |
29 | .unwrap; |
30 | let mut file = open |
31 | self.config |
32 | .as_str |
33 | .unwrap, |
34 | |
35 | .await |
36 | .unwrap; |
37 | |
38 | let mut key = vec!; |
39 | file.read_to_end .await.unwrap; |
40 | |
41 | key |
42 | |
43 | |
44 | pub async |
45 | &mut self, |
46 | user: &User, |
47 | generated_for: &Instance, |
48 | |
49 | let private_key = self.private_key .await; |
50 | |
51 | let encoding_key = from_rsa_pem .unwrap; |
52 | |
53 | let claims = UserTokenMetadata |
54 | user: user.clone, |
55 | generated_for: generated_for.clone, |
56 | exp: |
57 | + from_secs |
58 | .as_secs, |
59 | ; |
60 | |
61 | encode |
62 | & new, |
63 | &claims, |
64 | &encoding_key, |
65 | |
66 | .unwrap |
67 | |
68 | |
69 | pub async |
70 | &mut self, |
71 | issued_for: impl , |
72 | username: String, |
73 | _password: String, |
74 | |
75 | let private_key = |
76 | let mut file = open |
77 | self.config |
78 | .as_str |
79 | .unwrap, |
80 | |
81 | .await |
82 | .unwrap; |
83 | |
84 | let mut key = vec!; |
85 | file.read_to_end .await.unwrap; |
86 | |
87 | key |
88 | ; |
89 | |
90 | let encoding_key = from_rsa_pem .unwrap; |
91 | |
92 | let claims = UserTokenMetadata |
93 | user: User |
94 | username, |
95 | instance: self.instance.clone, |
96 | , |
97 | generated_for: issued_for.to_owned, |
98 | exp: |
99 | + from_secs |
100 | .as_secs, |
101 | ; |
102 | |
103 | let token = encode |
104 | & new, |
105 | &claims, |
106 | &encoding_key, |
107 | |
108 | .unwrap; |
109 | |
110 | Ok |
111 | |
112 | |
113 | pub async |
114 | &mut self, |
115 | issued_for: &Instance, |
116 | token: UserAuthenticationToken, |
117 | |
118 | let server_public_key = public_key .await.unwrap; |
119 | |
120 | let verification_key = from_rsa_pem .unwrap; |
121 | |
122 | let data: = decode |
123 | token.as_ref, |
124 | &verification_key, |
125 | & new, |
126 | |
127 | .unwrap; |
128 | |
129 | if data.claims.generated_for != *issued_for |
130 | panic! |
131 | |
132 | |
133 | info!; |
134 | |
135 | let private_key = |
136 | let mut file = open |
137 | self.config |
138 | .as_str |
139 | .unwrap, |
140 | |
141 | .await |
142 | .unwrap; |
143 | |
144 | let mut key = vec!; |
145 | file.read_to_end .await.unwrap; |
146 | |
147 | key |
148 | ; |
149 | |
150 | let encoding_key = from_rsa_pem .unwrap; |
151 | |
152 | let claims = UserTokenMetadata |
153 | // TODO: Probably exploitable |
154 | user: data.claims.user, |
155 | generated_for: issued_for.clone, |
156 | exp: |
157 | + from_secs |
158 | .as_secs, |
159 | ; |
160 | |
161 | let token = encode |
162 | & new, |
163 | &claims, |
164 | &encoding_key, |
165 | |
166 | .unwrap; |
167 | |
168 | Ok |
169 | new_token: Some, |
170 | |
171 | |
172 | |
173 | |
174 | async |
175 | let key = get |
176 | .await? |
177 | .text |
178 | .await?; |
179 | |
180 | Ok |
181 | |
182 |