add discovery stub
parent: tbd commit: cb91a68
1 | use Error; |
2 | use ; |
3 | use |
4 | , |
5 | , |
6 | , | Sha256
7 | , |
8 | RsaPrivateKey, RsaPublicKey, |
9 | ; |
10 | use ; |
11 | use Debug; |
12 | |
13 | use crate:: |
14 | , | UserTokenMetadata
15 | , | HandshakeMessage
16 | , |
17 | ; |
18 | |
19 | use ; |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | Handshake, |
30 | Repository, |
31 | Authentication, |
32 | |
33 | |
34 | /// An authenticated message, where the instance is authenticating |
35 | /// a request it is making for itself. |
36 | |
37 | |
38 | message: T, |
39 | instance: Instance, |
40 | signature: , |
41 | |
42 | |
43 | |
44 | |
45 | T: PartialEq + Serialize, |
46 | |
47 | |
48 | self.message == other.message |
49 | && self.instance == other.instance |
50 | && self.signature == other.signature |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | T: Hash + Serialize, |
59 | |
60 | |
61 | self.message.hash; |
62 | self.instance.hash; |
63 | self.signature.hash; |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | T: Clone + Serialize, |
70 | |
71 | |
72 | Self |
73 | message: self.message.clone, |
74 | instance: self.instance.clone, |
75 | signature: self.signature.clone, |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | T: Debug + Serialize, |
83 | |
84 | |
85 | f.debug_struct |
86 | .field |
87 | .field |
88 | .field |
89 | .finish |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | let mut rng = thread_rng; |
96 | |
97 | let private_key = from_pkcs1_pem?; |
98 | let signing_key = new; |
99 | |
100 | let message_json = to_vec?; |
101 | |
102 | let signature = signing_key.sign_with_rng; |
103 | |
104 | Ok |
105 | message, |
106 | instance, |
107 | signature: signature.to_vec, |
108 | |
109 | |
110 | |
111 | pub async |
112 | &self.message |
113 | |
114 | |
115 | pub async |
116 | let public_key = public_key .await?; |
117 | let public_key = from_pkcs1_pem .unwrap; |
118 | |
119 | let verifying_key: = new; |
120 | |
121 | let message_json = to_vec .unwrap; |
122 | |
123 | verifying_key |
124 | .verify |
125 | &message_json, |
126 | & try_from .unwrap, |
127 | |
128 | .unwrap; |
129 | |
130 | Ok |
131 | |
132 | |
133 | |
134 | /// An authenticated message. |
135 | /// |
136 | /// Includes the message, with a digest generated with |
137 | /// our private key. |
138 | |
139 | |
140 | #[serde(flatten)] |
141 | message: T, |
142 | pub(crate) user: User, |
143 | |
144 | |
145 | |
146 | |
147 | T: Clone + Serialize, |
148 | |
149 | |
150 | Self |
151 | message: self.message.clone, |
152 | user: self.user.clone, |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | T: Debug + Serialize, |
160 | |
161 | |
162 | f.debug_struct |
163 | .field |
164 | .field |
165 | .finish |
166 | |
167 | |
168 | |
169 | |
170 | pub async |
171 | &self.message |
172 | |
173 | |
174 | pub async |
175 | &self.user |
176 | |
177 | |
178 | |
179 | /// An unvalidated authenticated message. |
180 | /// |
181 | /// Includes the message, with a digest generated with |
182 | /// our private key. |
183 | |
184 | |
185 | #[serde(flatten)] |
186 | message: T, |
187 | token: String, |
188 | digest: , |
189 | |
190 | |
191 | |
192 | |
193 | T: Clone + Serialize, |
194 | |
195 | |
196 | Self |
197 | message: self.message.clone, |
198 | token: self.token.clone, |
199 | digest: self.digest.clone, |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | T: Debug + Serialize, |
207 | |
208 | |
209 | f.debug_struct |
210 | .field |
211 | .field |
212 | .field |
213 | .finish |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | let mut rng = thread_rng; |
220 | |
221 | let private_key = from_pkcs1_pem?; |
222 | let signing_key = new; |
223 | |
224 | let message_json = to_vec?; |
225 | |
226 | let signature = signing_key.sign_with_rng; |
227 | |
228 | Ok |
229 | message, |
230 | token, |
231 | digest: signature.to_vec, |
232 | |
233 | |
234 | |
235 | pub async |
236 | &self.message |
237 | |
238 | |
239 | pub async |
240 | let instance = |
241 | let mut validation = new; |
242 | validation.insecure_disable_signature_validation; |
243 | |
244 | let value: = |
245 | decode .unwrap; |
246 | |
247 | value.claims.generated_for.clone |
248 | ; |
249 | |
250 | let public_key_raw = public_key .await?; |
251 | let public_key = from_pkcs1_pem .unwrap; |
252 | |
253 | let verifying_key: = new; |
254 | |
255 | let message_json = to_vec .unwrap; |
256 | |
257 | verifying_key |
258 | .verify |
259 | &message_json, |
260 | & try_from .unwrap, |
261 | |
262 | .unwrap; |
263 | |
264 | let verification_key = from_rsa_pem .unwrap; |
265 | |
266 | let data: = decode |
267 | &self.token, |
268 | &verification_key, |
269 | & new, |
270 | |
271 | .unwrap; |
272 | |
273 | assert_eq!; |
274 | |
275 | Ok |
276 | message: self.message, |
277 | user: data.claims.user, |
278 | |
279 | |
280 | |
281 | |
282 | async |
283 | let key = get |
284 | .await? |
285 | .text |
286 | .await?; |
287 | |
288 | Ok |
289 | |
290 |