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