Add Instance Authentication
parent: tbd commit: 5a042fd
1 | use ; |
2 | |
3 | use |
4 | , |
5 | , |
6 | , | Sha256
7 | , |
8 | RsaPrivateKey, RsaPublicKey, |
9 | ; |
10 | use ; |
11 | |
12 | use crate::; |
13 | |
14 | use ; |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | Handshake, |
24 | Repository, |
25 | Authentication, |
26 | |
27 | |
28 | /// An authenticated message, where the instance is authenticating |
29 | /// a request it is making for itself. |
30 | |
31 | |
32 | message: T, |
33 | instance: Instance, |
34 | signature: , |
35 | |
36 | |
37 | |
38 | |
39 | T: Clone + Serialize, |
40 | |
41 | |
42 | Self |
43 | message: self.message.clone, |
44 | instance: self.instance.clone, |
45 | signature: self.signature.clone, |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | T: Debug + Serialize, |
53 | |
54 | |
55 | f.debug_struct |
56 | .field |
57 | .field |
58 | .field |
59 | .finish |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | message: T, |
66 | instance: Instance, |
67 | private_key: String, |
68 | |
69 | let mut rng = thread_rng; |
70 | |
71 | let private_key = from_pkcs1_pem?; |
72 | let signing_key = new; |
73 | |
74 | let message_json = to_vec?; |
75 | |
76 | let signature = signing_key.sign_with_rng; |
77 | |
78 | Ok |
79 | message, |
80 | instance, |
81 | signature: signature.to_vec, |
82 | |
83 | |
84 | |
85 | pub async |
86 | &self.message |
87 | |
88 | |
89 | pub async |
90 | let public_key = public_key .await?; |
91 | let public_key = from_pkcs1_pem .unwrap; |
92 | |
93 | let verifying_key: = new; |
94 | |
95 | let message_json = to_vec .unwrap; |
96 | |
97 | verifying_key |
98 | .verify |
99 | &message_json, |
100 | & try_from .unwrap, |
101 | |
102 | .unwrap; |
103 | |
104 | Ok |
105 | |
106 | |
107 | |
108 | /// An authenticated message. |
109 | /// |
110 | /// Includes the message, with a digest generated with |
111 | /// our private key. |
112 | |
113 | |
114 | #[serde(flatten)] |
115 | message: T, |
116 | token: String, |
117 | digest: , |
118 | |
119 | |
120 | |
121 | |
122 | T: Clone + Serialize, |
123 | |
124 | |
125 | Self |
126 | message: self.message.clone, |
127 | token: self.token.clone, |
128 | digest: self.digest.clone, |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | T: Debug + Serialize, |
136 | |
137 | |
138 | f.debug_struct |
139 | .field |
140 | .field |
141 | .field |
142 | .finish |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | let mut rng = thread_rng; |
149 | |
150 | let private_key = from_pkcs1_pem?; |
151 | let signing_key = new; |
152 | |
153 | let message_json = to_vec?; |
154 | |
155 | let signature = signing_key.sign_with_rng; |
156 | |
157 | Ok |
158 | message, |
159 | token, |
160 | digest: signature.to_vec, |
161 | |
162 | |
163 | |
164 | pub async |
165 | &self.message |
166 | |
167 | |
168 | pub async |
169 | let public_key = from_pkcs1_pem .unwrap; |
170 | |
171 | let verifying_key: = new; |
172 | |
173 | let message_json = to_vec .unwrap; |
174 | |
175 | verifying_key |
176 | .verify |
177 | &message_json, |
178 | & try_from .unwrap, |
179 | |
180 | .unwrap; |
181 | |
182 | Ok |
183 | |
184 | |
185 | |
186 | async |
187 | let key = get |
188 | .await? |
189 | .text |
190 | .await?; |
191 | |
192 | Ok |
193 | |
194 |