c81605ae5448ebd76f5646ff23eaeb4c9cb7b5c6
[strongswan.git] / src / libstrongswan / plugins / pem / pem_plugin.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 "pem_plugin.h"
17
18 #include <library.h>
19
20 #include "pem_builder.h"
21 #include "pem_encoder.h"
22
23 typedef struct private_pem_plugin_t private_pem_plugin_t;
24
25 /**
26 * private data of pem_plugin
27 */
28 struct private_pem_plugin_t {
29
30 /**
31 * public functions
32 */
33 pem_plugin_t public;
34 };
35
36 METHOD(plugin_t, get_name, char*,
37 private_pem_plugin_t *this)
38 {
39 return "pem";
40 }
41
42 METHOD(plugin_t, destroy, void,
43 private_pem_plugin_t *this)
44 {
45 lib->creds->remove_builder(lib->creds,
46 (builder_function_t)pem_private_key_load);
47 lib->creds->remove_builder(lib->creds,
48 (builder_function_t)pem_public_key_load);
49 lib->creds->remove_builder(lib->creds,
50 (builder_function_t)pem_certificate_load);
51 free(this);
52 }
53
54 /*
55 * see header file
56 */
57 plugin_t *pem_plugin_create()
58 {
59 private_pem_plugin_t *this;
60
61 INIT(this,
62 .public = {
63 .plugin = {
64 .get_name = _get_name,
65 .reload = (void*)return_false,
66 .destroy = _destroy,
67 },
68 },
69 );
70
71 /* register private key PEM decoding builders */
72 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ANY, FALSE,
73 (builder_function_t)pem_private_key_load);
74 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA, FALSE,
75 (builder_function_t)pem_private_key_load);
76 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA, FALSE,
77 (builder_function_t)pem_private_key_load);
78 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_DSA, FALSE,
79 (builder_function_t)pem_private_key_load);
80
81 /* register public key PEM decoding builders */
82 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ANY, FALSE,
83 (builder_function_t)pem_public_key_load);
84 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA, FALSE,
85 (builder_function_t)pem_public_key_load);
86 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ECDSA, FALSE,
87 (builder_function_t)pem_public_key_load);
88 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_DSA, FALSE,
89 (builder_function_t)pem_public_key_load);
90
91 /* register certificate PEM decoding builders */
92 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_ANY, FALSE,
93 (builder_function_t)pem_certificate_load);
94 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509, FALSE,
95 (builder_function_t)pem_certificate_load);
96 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_CRL, FALSE,
97 (builder_function_t)pem_certificate_load);
98 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_OCSP_REQUEST, FALSE,
99 (builder_function_t)pem_certificate_load);
100 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_OCSP_RESPONSE, FALSE,
101 (builder_function_t)pem_certificate_load);
102 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_AC, FALSE,
103 (builder_function_t)pem_certificate_load);
104 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_PKCS10_REQUEST, FALSE,
105 (builder_function_t)pem_certificate_load);
106 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_TRUSTED_PUBKEY, FALSE,
107 (builder_function_t)pem_certificate_load);
108 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_GPG, FALSE,
109 (builder_function_t)pem_certificate_load);
110
111 /* register pluto specific certificate formats */
112 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_PLUTO_CERT, FALSE,
113 (builder_function_t)pem_certificate_load);
114 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_PLUTO_CRL, FALSE,
115 (builder_function_t)pem_certificate_load);
116
117 /* register PEM encoder */
118 lib->encoding->add_encoder(lib->encoding, pem_encoder_encode);
119
120 return &this->public.plugin;
121 }
122