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