Fixing out-of-tree build after adding dependency to config.status.
[strongswan.git] / src / pki / pki.c
1 /*
2 * Copyright (C) 2009 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 "command.h"
17 #include "pki.h"
18
19 #include <debug.h>
20
21 /**
22 * Convert a form string to a encoding type
23 */
24 bool get_form(char *form, key_encoding_type_t *type, bool pub)
25 {
26 if (streq(form, "der"))
27 {
28 /* der encoded keys usually contain the complete SubjectPublicKeyInfo */
29 *type = pub ? KEY_PUB_SPKI_ASN1_DER : KEY_PRIV_ASN1_DER;
30 }
31 else if (streq(form, "pem"))
32 {
33 *type = pub ? KEY_PUB_PEM : KEY_PRIV_PEM;
34 }
35 else if (streq(form, "pgp"))
36 {
37 *type = pub ? KEY_PUB_PGP : KEY_PRIV_PGP;
38 }
39 else
40 {
41 return FALSE;
42 }
43 return TRUE;
44 }
45
46 /**
47 * Convert a digest string to a hash algorithm
48 */
49 hash_algorithm_t get_digest(char *name)
50 {
51 if (streq(name, "md5"))
52 {
53 return HASH_MD5;
54 }
55 if (streq(name, "sha1"))
56 {
57 return HASH_SHA1;
58 }
59 if (streq(name, "sha224"))
60 {
61 return HASH_SHA224;
62 }
63 if (streq(name, "sha256"))
64 {
65 return HASH_SHA256;
66 }
67 if (streq(name, "sha384"))
68 {
69 return HASH_SHA384;
70 }
71 if (streq(name, "sha512"))
72 {
73 return HASH_SHA512;
74 }
75 return HASH_UNKNOWN;
76 }
77
78 /**
79 * Library initialization and operation parsing
80 */
81 int main(int argc, char *argv[])
82 {
83 atexit(library_deinit);
84 if (!library_init(NULL))
85 {
86 exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
87 }
88 if (lib->integrity &&
89 !lib->integrity->check_file(lib->integrity, "pki", argv[0]))
90 {
91 fprintf(stderr, "integrity check of pki failed\n");
92 exit(SS_RC_DAEMON_INTEGRITY);
93 }
94 if (!lib->plugins->load(lib->plugins, NULL,
95 lib->settings->get_str(lib->settings, "pki.load", PLUGINS)))
96 {
97 exit(SS_RC_INITIALIZATION_FAILED);
98 }
99 return command_dispatch(argc, argv);
100 }
101