diff options
Diffstat (limited to 'src/service/revocation/test_revocation_testvectors.c')
-rw-r--r-- | src/service/revocation/test_revocation_testvectors.c | 297 |
1 files changed, 297 insertions, 0 deletions
diff --git a/src/service/revocation/test_revocation_testvectors.c b/src/service/revocation/test_revocation_testvectors.c new file mode 100644 index 000000000..a669e1b7e --- /dev/null +++ b/src/service/revocation/test_revocation_testvectors.c | |||
@@ -0,0 +1,297 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_util_lib.h" | ||
3 | #include "gnunet_revocation_service.h" | ||
4 | #include "gnunet_gnsrecord_lib.h" | ||
5 | #include <inttypes.h> | ||
6 | |||
7 | int res; | ||
8 | |||
9 | struct RevocationTv | ||
10 | { | ||
11 | char *d; | ||
12 | char *zid; | ||
13 | char *ztld; | ||
14 | char *m; | ||
15 | char *proof; | ||
16 | int diff; | ||
17 | int epochs; | ||
18 | }; | ||
19 | |||
20 | struct RevocationTv rtvs[] = { | ||
21 | { | ||
22 | .d = | ||
23 | "6f ea 32 c0 5a f5 8b fa" | ||
24 | "97 95 53 d1 88 60 5f d5" | ||
25 | "7d 8b f9 cc 26 3b 78 d5" | ||
26 | "f7 47 8c 07 b9 98 ed 70", | ||
27 | .zid = | ||
28 | "00 01 00 00 2c a2 23 e8" | ||
29 | "79 ec c4 bb de b5 da 17" | ||
30 | "31 92 81 d6 3b 2e 3b 69" | ||
31 | "55 f1 c3 77 5c 80 4a 98" | ||
32 | "d5 f8 dd aa", | ||
33 | .ztld = | ||
34 | "000G001CM8HYGYFCRJXXXDET2WRS50EP7CQ3PTANY71QEQ409ACDBY6XN8", | ||
35 | .m = | ||
36 | "00 00 00 34 00 00 00 03" | ||
37 | "00 05 fe b4 6d 86 5c 1c" | ||
38 | "00 01 00 00 2c a2 23 e8" | ||
39 | "79 ec c4 bb de b5 da 17" | ||
40 | "31 92 81 d6 3b 2e 3b 69" | ||
41 | "55 f1 c3 77 5c 80 4a 98" | ||
42 | "d5 f8 dd aa", | ||
43 | .proof = | ||
44 | "00 05 ff 1c 56 e4 b2 68" | ||
45 | "00 00 39 5d 18 27 c0 00" | ||
46 | "38 0b 54 aa 70 16 ac a2" | ||
47 | "38 0b 54 aa 70 16 ad 62" | ||
48 | "38 0b 54 aa 70 16 af 3e" | ||
49 | "38 0b 54 aa 70 16 af 93" | ||
50 | "38 0b 54 aa 70 16 b0 bf" | ||
51 | "38 0b 54 aa 70 16 b0 ee" | ||
52 | "38 0b 54 aa 70 16 b1 c9" | ||
53 | "38 0b 54 aa 70 16 b1 e5" | ||
54 | "38 0b 54 aa 70 16 b2 78" | ||
55 | "38 0b 54 aa 70 16 b2 b2" | ||
56 | "38 0b 54 aa 70 16 b2 d6" | ||
57 | "38 0b 54 aa 70 16 b2 e4" | ||
58 | "38 0b 54 aa 70 16 b3 2c" | ||
59 | "38 0b 54 aa 70 16 b3 5a" | ||
60 | "38 0b 54 aa 70 16 b3 9d" | ||
61 | "38 0b 54 aa 70 16 b3 c0" | ||
62 | "38 0b 54 aa 70 16 b3 dd" | ||
63 | "38 0b 54 aa 70 16 b3 f4" | ||
64 | "38 0b 54 aa 70 16 b4 42" | ||
65 | "38 0b 54 aa 70 16 b4 76" | ||
66 | "38 0b 54 aa 70 16 b4 8c" | ||
67 | "38 0b 54 aa 70 16 b4 a4" | ||
68 | "38 0b 54 aa 70 16 b4 c9" | ||
69 | "38 0b 54 aa 70 16 b4 f0" | ||
70 | "38 0b 54 aa 70 16 b4 f7" | ||
71 | "38 0b 54 aa 70 16 b5 79" | ||
72 | "38 0b 54 aa 70 16 b6 34" | ||
73 | "38 0b 54 aa 70 16 b6 8e" | ||
74 | "38 0b 54 aa 70 16 b7 b4" | ||
75 | "38 0b 54 aa 70 16 b8 7e" | ||
76 | "38 0b 54 aa 70 16 b8 f8" | ||
77 | "38 0b 54 aa 70 16 b9 2a" | ||
78 | "00 01 00 00 2c a2 23 e8" | ||
79 | "79 ec c4 bb de b5 da 17" | ||
80 | "31 92 81 d6 3b 2e 3b 69" | ||
81 | "55 f1 c3 77 5c 80 4a 98" | ||
82 | "d5 f8 dd aa 08 ca ff de" | ||
83 | "3c 6d f1 45 f7 e0 79 81" | ||
84 | "15 37 b2 b0 42 2d 5e 1f" | ||
85 | "b2 01 97 81 ec a2 61 d1" | ||
86 | "f9 d8 ea 81 0a bc 2f 33" | ||
87 | "47 7f 04 e3 64 81 11 be" | ||
88 | "71 c2 48 82 1a d6 04 f4" | ||
89 | "94 e7 4d 0b f5 11 d2 c1" | ||
90 | "62 77 2e 81", | ||
91 | .diff = 5, | ||
92 | .epochs = 2 | ||
93 | }, | ||
94 | { | ||
95 | .d = | ||
96 | "5a f7 02 0e e1 91 60 32" | ||
97 | "88 32 35 2b bc 6a 68 a8" | ||
98 | "d7 1a 7c be 1b 92 99 69" | ||
99 | "a7 c6 6d 41 5a 0d 8f 65", | ||
100 | .zid = | ||
101 | "00 01 00 14 3c f4 b9 24" | ||
102 | "03 20 22 f0 dc 50 58 14" | ||
103 | "53 b8 5d 93 b0 47 b6 3d" | ||
104 | "44 6c 58 45 cb 48 44 5d" | ||
105 | "db 96 68 8f", | ||
106 | .ztld = | ||
107 | "000G051WYJWJ80S04BRDRM2R2H9VGQCKP13VCFA4DHC4BJT88HEXQ5K8HW", | ||
108 | .diff = 5, | ||
109 | .epochs = 2, | ||
110 | .m = | ||
111 | "00 00 00 34 00 00 00 03" | ||
112 | "00 05 ff 1c 57 35 42 bd" | ||
113 | "00 01 00 14 3c f4 b9 24" | ||
114 | "03 20 22 f0 dc 50 58 14" | ||
115 | "53 b8 5d 93 b0 47 b6 3d" | ||
116 | "44 6c 58 45 cb 48 44 5d" | ||
117 | "db 96 68 8f", | ||
118 | .proof = | ||
119 | "00 05 ff 1c 57 35 42 bd" | ||
120 | "00 00 39 5d 18 27 c0 00" | ||
121 | "58 4c 93 3c b0 99 2a 08" | ||
122 | "58 4c 93 3c b0 99 2d f7" | ||
123 | "58 4c 93 3c b0 99 2e 21" | ||
124 | "58 4c 93 3c b0 99 2e 2a" | ||
125 | "58 4c 93 3c b0 99 2e 53" | ||
126 | "58 4c 93 3c b0 99 2e 8e" | ||
127 | "58 4c 93 3c b0 99 2f 13" | ||
128 | "58 4c 93 3c b0 99 2f 2d" | ||
129 | "58 4c 93 3c b0 99 2f 3c" | ||
130 | "58 4c 93 3c b0 99 2f 41" | ||
131 | "58 4c 93 3c b0 99 2f fd" | ||
132 | "58 4c 93 3c b0 99 30 33" | ||
133 | "58 4c 93 3c b0 99 30 82" | ||
134 | "58 4c 93 3c b0 99 30 a2" | ||
135 | "58 4c 93 3c b0 99 30 e1" | ||
136 | "58 4c 93 3c b0 99 31 ce" | ||
137 | "58 4c 93 3c b0 99 31 de" | ||
138 | "58 4c 93 3c b0 99 32 12" | ||
139 | "58 4c 93 3c b0 99 32 4e" | ||
140 | "58 4c 93 3c b0 99 32 9f" | ||
141 | "58 4c 93 3c b0 99 33 31" | ||
142 | "58 4c 93 3c b0 99 33 87" | ||
143 | "58 4c 93 3c b0 99 33 8c" | ||
144 | "58 4c 93 3c b0 99 33 e5" | ||
145 | "58 4c 93 3c b0 99 33 f3" | ||
146 | "58 4c 93 3c b0 99 34 26" | ||
147 | "58 4c 93 3c b0 99 34 30" | ||
148 | "58 4c 93 3c b0 99 34 68" | ||
149 | "58 4c 93 3c b0 99 34 88" | ||
150 | "58 4c 93 3c b0 99 34 8a" | ||
151 | "58 4c 93 3c b0 99 35 4c" | ||
152 | "58 4c 93 3c b0 99 35 bd" | ||
153 | "00 01 00 14 3c f4 b9 24" | ||
154 | "03 20 22 f0 dc 50 58 14" | ||
155 | "53 b8 5d 93 b0 47 b6 3d" | ||
156 | "44 6c 58 45 cb 48 44 5d" | ||
157 | "db 96 68 8f 04 ae 26 f7" | ||
158 | "63 56 5a b7 aa ab 01 71" | ||
159 | "72 4f 3c a8 bc c5 1a 98" | ||
160 | "b7 d4 c9 2e a3 3c d9 34" | ||
161 | "4c a8 b6 3e 04 53 3a bf" | ||
162 | "1a 3c 05 49 16 b3 68 2c" | ||
163 | "5c a8 cb 4d d0 f8 4c 3b" | ||
164 | "77 48 7a ac 6e ce 38 48" | ||
165 | "0b a9 d5 00" | ||
166 | }, | ||
167 | { .d = NULL } | ||
168 | }; | ||
169 | |||
170 | static void | ||
171 | print_bytes_ (void *buf, | ||
172 | size_t buf_len, | ||
173 | int fold, | ||
174 | int in_be) | ||
175 | { | ||
176 | int i; | ||
177 | |||
178 | for (i = 0; i < buf_len; i++) | ||
179 | { | ||
180 | if (0 != i) | ||
181 | { | ||
182 | if ((0 != fold) && (i % fold == 0)) | ||
183 | printf ("\n "); | ||
184 | else | ||
185 | printf (" "); | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | printf (" "); | ||
190 | } | ||
191 | if (in_be) | ||
192 | printf ("%02x", ((unsigned char*) buf)[buf_len - 1 - i]); | ||
193 | else | ||
194 | printf ("%02x", ((unsigned char*) buf)[i]); | ||
195 | } | ||
196 | printf ("\n"); | ||
197 | } | ||
198 | |||
199 | |||
200 | static void | ||
201 | print_bytes (void *buf, | ||
202 | size_t buf_len, | ||
203 | int fold) | ||
204 | { | ||
205 | print_bytes_ (buf, buf_len, fold, 0); | ||
206 | } | ||
207 | |||
208 | |||
209 | int | ||
210 | parsehex (char *src, char *dst, size_t dstlen, int invert) | ||
211 | { | ||
212 | int off; | ||
213 | int read_byte; | ||
214 | int data_len = 0; | ||
215 | char data[strlen (src) + 1]; | ||
216 | char *pos = data; | ||
217 | int i = 0; | ||
218 | int j = 0; | ||
219 | |||
220 | for (i = 0; i < strlen (src); i++) | ||
221 | { | ||
222 | if ((src[i] == ' ') || (src[i] == '\n')) | ||
223 | continue; | ||
224 | data[j++] = src[i]; | ||
225 | } | ||
226 | |||
227 | while (sscanf (pos, " %02x%n", &read_byte, &off) == 1) | ||
228 | { | ||
229 | if (invert) | ||
230 | dst[dstlen - 1 - data_len++] = read_byte; | ||
231 | else | ||
232 | dst[data_len++] = read_byte; | ||
233 | pos += off; | ||
234 | } | ||
235 | return data_len; | ||
236 | } | ||
237 | |||
238 | |||
239 | int | ||
240 | main () | ||
241 | { | ||
242 | struct GNUNET_CRYPTO_PrivateKey priv; | ||
243 | struct GNUNET_CRYPTO_PublicKey pub; | ||
244 | struct GNUNET_CRYPTO_PublicKey pub_parsed; | ||
245 | struct GNUNET_TIME_Relative exprel; | ||
246 | struct GNUNET_REVOCATION_PowP *pow; | ||
247 | char m[8096]; | ||
248 | char ztld[128]; | ||
249 | res = 0; | ||
250 | |||
251 | for (int i = 0; NULL != rtvs[i].d; i++) | ||
252 | { | ||
253 | printf ("Revocation test vector #%d\n", i); | ||
254 | parsehex (rtvs[i].zid,(char*) &pub_parsed, 36, 0); | ||
255 | parsehex (rtvs[i].d,(char*) &priv.ecdsa_key, sizeof (priv.ecdsa_key), | ||
256 | (GNUNET_GNSRECORD_TYPE_PKEY == ntohl (pub_parsed.type)) ? 1 : 0); | ||
257 | priv.type = pub_parsed.type; | ||
258 | GNUNET_CRYPTO_key_get_public (&priv, &pub); | ||
259 | if (0 != memcmp (&pub, &pub_parsed, GNUNET_CRYPTO_public_key_get_length ( | ||
260 | &pub))) | ||
261 | { | ||
262 | printf ("Wrong pubkey.\n"); | ||
263 | print_bytes (&pub, 36, 8); | ||
264 | print_bytes (&pub_parsed, 36, 8); | ||
265 | res = 1; | ||
266 | break; | ||
267 | } | ||
268 | GNUNET_STRINGS_data_to_string (&pub, | ||
269 | GNUNET_CRYPTO_public_key_get_length ( | ||
270 | &pub), | ||
271 | ztld, | ||
272 | sizeof (ztld)); | ||
273 | if (0 != strcmp (ztld, rtvs[i].ztld)) | ||
274 | { | ||
275 | printf ("Wrong zTLD: expected %s, got %s\n", rtvs[i].ztld, ztld); | ||
276 | res = 1; | ||
277 | break; | ||
278 | } | ||
279 | pow = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); | ||
280 | parsehex (rtvs[i].proof, (char*) pow, 0, 0); | ||
281 | // parsehex (rtvs[i].m, (char*) message, 0, 0); | ||
282 | |||
283 | exprel = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
284 | rtvs[i].epochs); | ||
285 | if (GNUNET_OK != GNUNET_REVOCATION_check_pow (pow, rtvs[i].diff, | ||
286 | exprel)) | ||
287 | { | ||
288 | printf ("FAIL: Revocation PoW invalid\n"); | ||
289 | res = 1; | ||
290 | break; | ||
291 | } | ||
292 | printf ("Good.\n"); | ||
293 | } | ||
294 | |||
295 | finish: | ||
296 | return res; | ||
297 | } | ||