Moving charon to libcharon.
[strongswan.git] / src / libcharon / plugins / unit_tester / tests / test_med_db.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <library.h>
17 #include <daemon.h>
18 #include <utils/enumerator.h>
19
20 #include <unistd.h>
21
22 /*******************************************************************************
23 * fetch public key from mediation database
24 ******************************************************************************/
25
26 bool test_med_db()
27 {
28 chunk_t found, keyid = chunk_from_chars(
29 0xed,0x90,0xe6,0x4f,0xec,0xa2,0x1f,0x4b,
30 0x68,0x97,0x99,0x24,0x22,0xe0,0xde,0x21,
31 0xb9,0xd6,0x26,0x29
32 );
33 identification_t *id;
34 enumerator_t *enumerator;
35 public_key_t *public;
36 auth_cfg_t *auth;
37 bool good = FALSE;
38
39 id = identification_create_from_encoding(ID_KEY_ID, keyid);
40 enumerator = charon->credentials->create_public_enumerator(
41 charon->credentials, KEY_ANY, id, NULL);
42 while (enumerator->enumerate(enumerator, &public, &auth))
43 {
44 good = public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1, &found);
45 if (good)
46 {
47 good = chunk_equals(id->get_encoding(id), found);
48 }
49 }
50 enumerator->destroy(enumerator);
51 id->destroy(id);
52 return good;
53 }
54