Add token extension
parent: tbd commit: 86d028f
1 | use ; |
2 | |
3 | use |
4 | , |
5 | , |
6 | , |
7 | , | Sha256
8 | , |
9 | RsaPrivateKey, RsaPublicKey, |
10 | ; |
11 | use ; |
12 | |
13 | use crate::; |
14 | |
15 | use ; |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | Handshake, |
25 | Repository, |
26 | Authentication, |
27 | |
28 | |
29 | /// An authenticated message, where the instance is authenticating |
30 | /// a request it is making for itself. |
31 | |
32 | |
33 | message: T, |
34 | instance: Instance, |
35 | signature: , |
36 | |
37 | |
38 | |
39 | |
40 | T: Clone + Serialize, |
41 | |
42 | |
43 | Self |
44 | message: self.message.clone, |
45 | instance: self.instance.clone, |
46 | signature: self.signature.clone, |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | T: Debug + Serialize, |
54 | |
55 | |
56 | f.debug_struct |
57 | .field |
58 | .field |
59 | .field |
60 | .finish |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | message: T, |
67 | instance: Instance, |
68 | private_key: String, |
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 = 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 |