2 * Copyright (c) 2010 Your File System Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * Tests for the afsconf key handling functions
29 #include <afsconfig.h>
30 #include <afs/param.h>
34 #include <afs/cellconfig.h>
36 #include <afs/afsutil.h>
39 #include <tap/basic.h>
45 copy(char *inFile, char *outFile)
51 in = open(inFile, O_RDONLY);
55 out = open(outFile, O_WRONLY | O_CREAT, 0600);
61 len = read(in, block, 1024);
63 write(out, block, len);
77 keyMatches(struct afsconf_typedKey *typedKey,
78 afsconf_keyType type, int kvno, int subType,
79 void *keyMaterial, size_t keyLen)
81 afsconf_keyType keyType;
84 struct rx_opaque *buffer;
86 afsconf_typedKey_values(typedKey, &keyType, &keyKvno, &keySubType,
89 return (keyType == type && keyKvno == kvno && keySubType == subType &&
90 buffer->len == keyLen &&
91 memcmp(keyMaterial, buffer->val, buffer->len) == 0);
94 int main(int argc, char **argv)
96 struct afsconf_dir *dir;
97 struct afsconf_keys keys;
98 struct ktc_encryptionKey key;
99 struct rx_opaque *keyMaterial;
100 struct afsconf_typedKey *typedKey;
101 struct afsconf_typedKeyList *typedKeyList;
110 /* Create a temporary afs configuration directory */
112 dirname = buildTestConfig();
114 if (asprintf(&keyfile, "%s/KeyFile", dirname) == -1)
117 /* First, copy in a known keyfile */
118 code = copy("KeyFile", keyfile);
122 /* Start with a blank configuration directory */
123 dir = afsconf_Open(dirname);
124 ok(dir != NULL, "Sucessfully re-opened config directory");
128 /* Verify that GetKeys returns the entire set of keys correctly */
129 code = afsconf_GetKeys(dir, &keys);
130 is_int(0, code, "afsconf_GetKeys returns successfully");
131 is_int(3, keys.nkeys, "... and returns the right number of keys");
132 is_int(1, keys.key[0].kvno, " ... first key number is correct");
133 is_int(2, keys.key[1].kvno, " ... second key number is correct");
134 is_int(4, keys.key[2].kvno, " ... third key number is correct");
135 ok(memcmp(keys.key[0].key, "\x01\x02\x04\x08\x10\x20\x40\x80", 8) == 0,
136 " ... first key matches");
137 ok(memcmp(keys.key[1].key, "\x04\x04\x04\x04\x04\x04\x04\x04", 8) == 0,
138 " ... second key matches");
139 ok(memcmp(keys.key[2].key, "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 8) == 0,
140 " ... third key matches");
142 /* Verify that GetLatestKey returns the newest key */
143 code = afsconf_GetLatestKey(dir, &kvno, &key);
144 is_int(0, code, "afsconf_GetLatestKey returns sucessfully");
145 is_int(4, kvno, " ... with correct key number");
146 ok(memcmp(&key, "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 8) == 0,
147 " ... and correct key");
149 /* Check that GetLatestKey works if called with NULL parameters */
150 code = afsconf_GetLatestKey(dir, NULL, NULL);
151 is_int(0, code, "afsconf_GetLatestKey works if parameters are NULL");
153 /* Verify that random access using GetKey works properly */
154 code = afsconf_GetKey(dir, 2, &key);
155 is_int(0, code, "afsconf_GetKey returns successfully");
156 ok(memcmp(&key, "\x04\x04\x04\x04\x04\x04\x04\x04", 8) == 0,
157 " ... and with correct key");
159 /* And that it fails if the key number doesn't exist */
160 code = afsconf_GetKey(dir, 3, &key);
161 is_int(code, AFSCONF_NOTFOUND,
162 "afsconf_GetKey returns not found for missing key");
164 /* Check that AddKey can be used to add a new 'newest' key */
165 code = afsconf_AddKey(dir, 5, "\x08\x08\x08\x08\x08\x08\x08\x08", 0);
166 is_int(0, code, "afsconf_AddKey sucessfully adds a new key");
168 /* And that we can get it back with GetKeys, GetLatestKey and GetKey */
169 code = afsconf_GetKeys(dir, &keys);
170 is_int(0, code, " ... and GetKeys still works");
171 is_int(4, keys.nkeys, "... and has the correct number of keys");
172 is_int(5, keys.key[3].kvno, " ... and the fourth key has the correct kvno");
173 ok(memcmp(keys.key[3].key, "\x08\x08\x08\x08\x08\x08\x08\x08", 8) == 0,
174 " ... and is the correct key");
176 code = afsconf_GetLatestKey(dir, &kvno, &key);
177 is_int(0, code, " ... and GetLatestKey returns successfully");
178 is_int(5, kvno, " ... with the correct key number");
179 ok(memcmp(&key, "\x08\x08\x08\x08\x08\x08\x08\x08", 8) == 0,
180 " ... and the correct key");
182 code = afsconf_GetKey(dir, 5, &key);
183 is_int(0, code, " ... and GetKey still works");
184 ok(memcmp(&key, "\x08\x08\x08\x08\x08\x08\x08\x08", 8) == 0,
185 " ... and returns the correct key");
187 /* Check that AddKey without the overwrite flag won't overwrite an existing
189 code = afsconf_AddKey(dir, 5, "\x10\x10\x10\x10\x10\x10\x10", 0);
190 is_int(AFSCONF_KEYINUSE, code, "AddKey won't overwrite without being told to");
192 /* Check with GetKey that it didn't */
193 code = afsconf_GetKey(dir, 5, &key);
194 is_int(0, code, " ... and GetKey still works");
195 ok(memcmp(&key, "\x08\x08\x08\x08\x08\x08\x08\x08", 8) == 0,
196 " ... and key hasn't been overwritten");
198 /* Check that AddKey with the overwrite flag will overwrite an existing key */
199 code = afsconf_AddKey(dir, 5, "\x10\x10\x10\x10\x10\x10\x10\x10", 1);
200 is_int(0, code, "AddKey overwrites when asked");
202 /* Use GetKey to check that it did so */
203 code = afsconf_GetKey(dir, 5, &key);
204 is_int(0, code, " ... and GetKey still works");
205 ok(memcmp(&key, "\x10\x10\x10\x10\x10\x10\x10\x10", 8) == 0,
206 " ... and key has been overwritten");
208 /* Check that deleting a key that doesn't exist fails */
209 code = afsconf_DeleteKey(dir, 6);
210 is_int(AFSCONF_NOTFOUND, code,
211 "afsconf_DeleteKey returns NOTFOUND if key doesn't exist");
213 /* Check that we can delete a key using afsconf_DeleteKey */
214 code = afsconf_DeleteKey(dir, 2);
215 is_int(0, code, "afsconf_DeleteKey can delete a key");
216 code = afsconf_GetKey(dir, 2, &key);
217 is_int(AFSCONF_NOTFOUND, code, " ... and afsconf_GetKey can't find it");
219 /* Check that deleting it doesn't leave a hole in what GetKeys returns */
220 code = afsconf_GetKeys(dir, &keys);
221 is_int(0, code, "... and afsconf_GetKeys returns it");
222 is_int(3, keys.nkeys, "... and returns the right number of keys");
223 is_int(1, keys.key[0].kvno, " ... first key number is correct");
224 is_int(4, keys.key[1].kvno, " ... second key number is correct");
225 is_int(5, keys.key[2].kvno, " ... third key number is correct");
227 /* Make sure that if we drop the dir structure, and then rebuild it, we
228 * still have the same KeyFile */
231 dir = afsconf_Open(dirname);
232 ok(dir != NULL, "Sucessfully re-opened config directory");
236 code = afsconf_GetKeys(dir, &keys);
237 is_int(0, code, "afsconf_GetKeys still works");
238 is_int(3, keys.nkeys, "... and returns the right number of keys");
239 is_int(1, keys.key[0].kvno, " ... first key number is correct");
240 is_int(4, keys.key[1].kvno, " ... second key number is correct");
241 is_int(5, keys.key[2].kvno, " ... third key number is correct");
243 /* Now check that we're limited to 8 keys */
244 for (i=0; i<5; i++) {
245 code = afsconf_AddKey(dir, 10+i, "\x10\x10\x10\x10\x10\x10\x10\x10",
247 is_int(0, code, "Adding %dth key with AddKey works", i+4);
249 code = afsconf_AddKey(dir, 20, "\x10\x10\x10\x10\x10\x10\x10\x10",0);
250 is_int(AFSCONF_FULL, code, "afsconf_AddKey fails once we've got 8 keys");
252 /* Check that the new interface also fails when we've got too many
254 keyMaterial = rx_opaque_new("\x10\x10\x10\x10\x10\x10\x10\x10", 8);
255 typedKey = afsconf_typedKey_new(afsconf_rxkad, 20, 0, keyMaterial);
256 rx_opaque_free(&keyMaterial);
257 code = afsconf_AddTypedKey(dir, typedKey, 0);
258 afsconf_typedKey_put(&typedKey);
259 is_int(AFSCONF_FULL, code,
260 "afsconf_AddTypedKey fails for rxkad once we've got 8 keys");
262 /* Check the new accessors work for rxkad keys */
263 code = afsconf_GetKeyByTypes(dir, afsconf_rxkad, 4, 0, &typedKey);
265 "afsconf_GetKeyByTypes works for rxkad");
266 ok(keyMatches(typedKey, afsconf_rxkad, 4, 0,
267 "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 8),
268 " ... and returned key matches");
270 afsconf_typedKey_put(&typedKey);
272 code = afsconf_GetKeysByType(dir, afsconf_rxkad, 4, &typedKeyList);
274 "afsconf_GetKeysByType works for rxkad");
275 is_int(1, typedKeyList->nkeys,
276 " ... and returns 1 key, as expected");
277 ok(keyMatches(typedKeyList->keys[0], afsconf_rxkad, 4, 0,
278 "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 8),
279 " ... and returned key matches");
281 afsconf_PutTypedKeyList(&typedKeyList);
283 code = afsconf_GetLatestKeyByTypes(dir, afsconf_rxkad, 0, &typedKey);
285 "afsconf_GetLatestKeyByTypes works for rxkad");
286 ok(keyMatches(typedKey, afsconf_rxkad, 14, 0,
287 "\x10\x10\x10\x10\x10\x10\x10\x10", 8),
288 " ... and returned key matches");
290 afsconf_typedKey_put(&typedKey);
292 code = afsconf_GetLatestKeysByType(dir, afsconf_rxkad, &typedKeyList);
294 "afsconf_GetLatestKeysByType works for rxkad");
295 is_int(1, typedKeyList->nkeys,
296 " ... and returns 1 key, as expected");
297 ok(keyMatches(typedKeyList->keys[0], afsconf_rxkad, 14, 0,
298 "\x10\x10\x10\x10\x10\x10\x10\x10", 8),
299 " ... and returned key matches");
300 afsconf_PutTypedKeyList(&typedKeyList);
302 /* Check that we can't delete a key that doesn't exist */
303 code = afsconf_DeleteKeyByType(dir, afsconf_rxkad, 6);
304 is_int(AFSCONF_NOTFOUND, code,
305 "afsconf_DeleteKeyByType returns NOTFOUND if key doesn't exist");
306 code = afsconf_DeleteKeyBySubType(dir, afsconf_rxkad, 6, 0);
307 is_int(AFSCONF_NOTFOUND, code,
308 "afsconf_DeleteKeyBySubType returns NOTFOUND if key doesn't exist");
309 code = afsconf_DeleteKeyBySubType(dir, afsconf_rxkad, 14, 1);
310 is_int(AFSCONF_NOTFOUND, code,
311 "afsconf_DeleteKeyBySubType doesn't delete with wrong subtype");
312 code = afsconf_GetKeyByTypes(dir, afsconf_rxkad, 14, 0, &typedKey);
313 is_int(0, code, " ... and key is still there!");
314 afsconf_typedKey_put(&typedKey);
316 /* Check that we can delete a key that does */
317 code = afsconf_DeleteKeyByType(dir, afsconf_rxkad, 13);
318 is_int(0, code, "afsconf_DeleteKeyByType works");
319 code = afsconf_GetKeysByType(dir, afsconf_rxkad, 13, &typedKeyList);
320 is_int(AFSCONF_NOTFOUND, code, " ... and is really gone");
322 code = afsconf_DeleteKeyBySubType(dir, afsconf_rxkad, 14, 0);
323 is_int(0, code, "afsconf_DeleteKeyBySubType works");
324 code = afsconf_GetKeyByTypes(dir, afsconf_rxkad, 14, 0, &typedKey);
325 is_int(AFSCONF_NOTFOUND, code, " ... and is really gone");
327 /* Unlink the KeyFile */
330 /* Force a rebuild of the directory structure, just in case */
333 dir = afsconf_Open(dirname);
334 ok(dir != NULL, "Sucessfully re-opened config directory");
338 /* Check that all of the various functions work properly if the file
340 code = afsconf_GetKeys(dir, &keys);
341 is_int(0, code, "afsconf_GetKeys works with an empty KeyFile");
342 is_int(0, keys.nkeys, " ... and returns the right number of keys");
343 code = afsconf_GetKey(dir, 1, &key);
344 is_int(AFSCONF_NOTFOUND, code,
345 "afsconf_GetKey returns NOTFOUND with an empty KeyFile");
346 code = afsconf_DeleteKey(dir, 1);
347 is_int(AFSCONF_NOTFOUND, code,
348 "afsconf_DeleteKey returns NOTFOUND with an empty KeyFile");
349 code = afsconf_GetLatestKey(dir, &kvno, &key);
350 is_int(AFSCONF_NOTFOUND, code,
351 "afsconf_GetLatestKey returns NOTFOUND with an empty KeyFile");
352 code = afsconf_GetKeysByType(dir, afsconf_rxkad, 1, &typedKeyList);
353 is_int(AFSCONF_NOTFOUND, code,
354 "afsconf_GetKeysByType returns NOTFOUND with an empty KeyFile");
355 code = afsconf_GetKeyByTypes(dir, afsconf_rxkad, 1, 0, &typedKey);
356 is_int(AFSCONF_NOTFOUND, code,
357 "afsconf_GetKeyByTypes returns NOTFOUND with an empty KeyFile");
358 code = afsconf_GetLatestKeysByType(dir, afsconf_rxkad, &typedKeyList);
359 is_int(AFSCONF_NOTFOUND, code,
360 "afsconf_GetLatestKeysByType returns NOTFOUND with empty KeyFile");
361 code = afsconf_GetLatestKeyByTypes(dir, afsconf_rxkad, 0, &typedKey);
362 is_int(AFSCONF_NOTFOUND, code,
363 "afsconf_GetLatestKeyByTypes returns NOTFOUND with empty KeyFile");
365 /* Now try adding a key to an empty file */
366 code = afsconf_AddKey(dir, 1, "\x10\x10\x10\x10\x10\x10\x10\x10", 1);
367 is_int(0, code, "afsconf_AddKey succeeds with an empty KeyFile");
368 code = afsconf_GetLatestKey(dir, &kvno, &key);
369 is_int(0, code, " ... and afsconf_GetLatestKey succeeds");
370 is_int(1, kvno, " ... with correct kvno");
371 ok(memcmp(&key, "\x10\x10\x10\x10\x10\x10\x10\x10", 8) == 0,
374 /* And adding a key using the new interface */
376 keyMaterial = rx_opaque_new("\x20\x20\x20\x20\x20\x20\x20\x20", 8);
377 typedKey = afsconf_typedKey_new(afsconf_rxkad, 2, 0, keyMaterial);
378 rx_opaque_free(&keyMaterial);
379 code = afsconf_AddTypedKey(dir, typedKey, 0);
380 afsconf_typedKey_put(&typedKey);
381 is_int(0, code, "afsconf_AddTypedKey works");
382 code = afsconf_GetLatestKey(dir, &kvno, &key);
383 is_int(0, code, " ... and afsconf_GetLatestKey succeeds");
384 is_int(2, kvno, " ... with correct kvno");
385 ok(memcmp(&key, "\x20\x20\x20\x20\x20\x20\x20\x20", 8) == 0,
387 code = afsconf_GetLatestKeyByTypes(dir, afsconf_rxkad, 0, &typedKey);
388 is_int(0, code, " ... and so does afsconf_GetLatestKeyByTypes");
389 ok(keyMatches(typedKey, afsconf_rxkad, 2, 0,
390 "\x20\x20\x20\x20\x20\x20\x20\x20", 8),
391 " ... with correct key");
392 afsconf_typedKey_put(&typedKey);
394 /* And that we can't add a key to an existing kvno and type */
395 keyMaterial = rx_opaque_new("\x30\x30\x30\x30\x30\x30\x30\x30", 8);
396 typedKey = afsconf_typedKey_new(afsconf_rxkad, 2, 0, keyMaterial);
397 rx_opaque_free(&keyMaterial);
398 code = afsconf_AddTypedKey(dir, typedKey, 0);
399 afsconf_typedKey_put(&typedKey);
400 is_int(AFSCONF_KEYINUSE, code,
401 "afsconf_AddTypedKey won't overwrite without being told to");
402 code = afsconf_GetKeyByTypes(dir, afsconf_rxkad, 2, 0, &typedKey);
403 is_int(0, code, " ... and key still exists");
404 ok(keyMatches(typedKey, afsconf_rxkad, 2, 0,
405 "\x20\x20\x20\x20\x20\x20\x20\x20", 8),
406 " ... and hasn't changed");
407 afsconf_typedKey_put(&typedKey);
409 /* But we can if we force */
410 keyMaterial = rx_opaque_new("\x30\x30\x30\x30\x30\x30\x30\x30", 8);
411 typedKey = afsconf_typedKey_new(afsconf_rxkad, 2, 0, keyMaterial);
412 rx_opaque_free(&keyMaterial);
413 code = afsconf_AddTypedKey(dir, typedKey, 1);
414 afsconf_typedKey_put(&typedKey);
415 is_int(0, code, "afsconf_AddTypedKey overwrites when asked");
416 code = afsconf_GetKeyByTypes(dir, afsconf_rxkad, 2, 0, &typedKey);
417 is_int(0, code, " ... and GetKeyByTypes retrieves new key");
418 ok(keyMatches(typedKey, afsconf_rxkad, 2, 0,
419 "\x30\x30\x30\x30\x30\x30\x30\x30", 8),
420 " ... and it is the new key");
422 /* Check that we can't add bad rxkad keys */
423 keyMaterial = rx_opaque_new("\x30\x30\x30\x30\x30\x30\x30", 7);
424 typedKey = afsconf_typedKey_new(afsconf_rxkad, 3, 0, keyMaterial);
425 rx_opaque_free(&keyMaterial);
426 code = afsconf_AddTypedKey(dir, typedKey, 1);
427 afsconf_typedKey_put(&typedKey);
428 is_int(AFSCONF_BADKEY, code,
429 "afsconf_AddTypedKey won't add short rxkad keys");
430 keyMaterial = rx_opaque_new("\x30\x30\x30\x30\x30\x30\x30\x30\x30", 9);
431 typedKey = afsconf_typedKey_new(afsconf_rxkad, 3, 0, keyMaterial);
432 rx_opaque_free(&keyMaterial);
433 code = afsconf_AddTypedKey(dir, typedKey, 1);
434 afsconf_typedKey_put(&typedKey);
435 is_int(AFSCONF_BADKEY, code,
436 "afsconf_AddTypedKey won't add long rxkad keys");
437 keyMaterial = rx_opaque_new("\x30\x30\x30\x30\x30\x30\x30\x30", 8);
438 typedKey = afsconf_typedKey_new(afsconf_rxkad, 3, 1, keyMaterial);
439 rx_opaque_free(&keyMaterial);
440 code = afsconf_AddTypedKey(dir, typedKey, 1);
441 afsconf_typedKey_put(&typedKey);
442 is_int(AFSCONF_BADKEY, code,
443 "afsconf_AddTypedKey won't add rxkad keys with non-zero subtype");
445 /* Now, test things with other key types. */
447 /* Add a different key type, but with same kvno as rxkad */
448 keyMaterial = rx_opaque_new("\x01", 1);
449 typedKey = afsconf_typedKey_new(1, 2, 0, keyMaterial);
450 code = afsconf_AddTypedKey(dir, typedKey, 0);
451 afsconf_typedKey_put(&typedKey);
453 "afsconf_AddTypedKey can add keys with different key type");
455 /* Add a different subtype, with same kvno */
456 keyMaterial = rx_opaque_new("\x02\x03", 2);
457 typedKey = afsconf_typedKey_new(1, 2, 1, keyMaterial);
458 code = afsconf_AddTypedKey(dir, typedKey, 0);
459 afsconf_typedKey_put(&typedKey);
461 "afsconf_AddTypedKey can add keys with different sub type");
463 /* Check the GetKeyByTypes returns one of the keys */
464 code = afsconf_GetKeyByTypes(dir, 1, 2, 1, &typedKey);
465 is_int(0, code, "afsconf_GetKeyByTypes returns");
466 ok(keyMatches(typedKey, 1, 2, 1, "\x02\x03", 2),
467 " ... with the right key");
469 /* Check that GetKeysByType returns both of the keys */
470 code = afsconf_GetKeysByType(dir, 1, 2, &typedKeyList);
471 is_int(0, code, "afsconf_GetKeysByType returns");
472 is_int(2, typedKeyList->nkeys, " ... with correct number of keys");
473 ok(keyMatches(typedKeyList->keys[0], 1, 2, 0, "\x01", 1),
474 " ... with the right key in slot 0");
475 ok(keyMatches(typedKeyList->keys[1], 1, 2, 1, "\x02\x03", 2),
476 " ... with the right key in slot 1");
477 afsconf_PutTypedKeyList(&typedKeyList);
479 /* Add another key, before these ones, so we can check that
480 * latest really works */
481 keyMaterial = rx_opaque_new("\x03", 1);
482 typedKey = afsconf_typedKey_new(1, 1, 0, keyMaterial);
483 code = afsconf_AddTypedKey(dir, typedKey, 0);
484 afsconf_typedKey_put(&typedKey);
485 is_int(0, code, "afsconf_AddTypedKey worked again");
487 /* Check that GetLatestKeyByTypes returns one */
488 code = afsconf_GetLatestKeyByTypes(dir, 1, 1, &typedKey);
489 is_int(0, code, "afsconf_GetLatestKeyByTypes returns");
490 ok(keyMatches(typedKey, 1, 2, 1, "\x02\x03", 2),
491 " ... with the right key");
493 /* Check that GetLatestKeysByType returns both */
494 code = afsconf_GetLatestKeysByType(dir, 1, &typedKeyList);
495 is_int(0, code, "afsconf_GetLatestKeysByType returns");
496 is_int(2, typedKeyList->nkeys, " ... with correct number of keys");
497 ok(keyMatches(typedKeyList->keys[0], 1, 2, 0, "\x01", 1),
498 " ... with the right key in slot 0");
499 ok(keyMatches(typedKeyList->keys[1], 1, 2, 1, "\x02\x03", 2),
500 " ... with the right key in slot 1");
501 afsconf_PutTypedKeyList(&typedKeyList);
503 /* Check that closing this instance, and reopening, still has all of
508 dir = afsconf_Open(dirname);
509 ok(dir != NULL, "Sucessfully re-opened config directory");
513 /* Check that GetKeysByType returns all of the keys */
514 code = afsconf_GetKeysByType(dir, 1, 1, &typedKeyList);
515 is_int(0, code, "afsconf_GetKeysByType returns after reopening");
516 is_int(1, typedKeyList->nkeys, " ... First kvno has correct number of keys");
517 ok(keyMatches(typedKeyList->keys[0], 1, 1, 0, "\x03", 1),
518 " ... and key material is correct");
519 afsconf_PutTypedKeyList(&typedKeyList);
521 code = afsconf_GetKeysByType(dir, 1, 2, &typedKeyList);
522 is_int(0, code, "afsconf_GetKeysByType returns after reopening");
523 is_int(2, typedKeyList->nkeys, " ... with correct number of keys");
524 ok(keyMatches(typedKeyList->keys[0], 1, 2, 0, "\x01", 1),
525 " ... with the right key in slot 0");
526 ok(keyMatches(typedKeyList->keys[1], 1, 2, 1, "\x02\x03", 2),
527 " ... with the right key in slot 1");
528 afsconf_PutTypedKeyList(&typedKeyList);
532 unlinkTestConfig(dirname);
536 /* Start a new test configuration */
537 dirname = buildTestConfig();
538 dir = afsconf_Open(dirname);
539 ok(dir != NULL, "Sucessfully opened brand new config directory");
543 /* Check that directories with just new style keys work */
544 keyMaterial = rx_opaque_new("\x02\x03", 2);
545 typedKey = afsconf_typedKey_new(1, 2, 1, keyMaterial);
546 code = afsconf_AddTypedKey(dir, typedKey, 0);
547 afsconf_typedKey_put(&typedKey);
549 "afsconf_AddTypedKey can add keys with different sub type");
551 /* Check the GetKeyByTypes returns one of the keys */
552 code = afsconf_GetKeyByTypes(dir, 1, 2, 1, &typedKey);
553 is_int(0, code, "afsconf_GetKeyByTypes returns it");
554 ok(keyMatches(typedKey, 1, 2, 1, "\x02\x03", 2),
555 " ... with the right key");
558 unlinkTestConfig(dirname);