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