b76987272df5479563513774a4b9176b254f9b23
[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 #include "pem_builder.h"
20
21 typedef struct private_pem_plugin_t private_pem_plugin_t;
22
23 /**
24 * private data of pem_plugin
25 */
26 struct private_pem_plugin_t {
27
28 /**
29 * public functions
30 */
31 pem_plugin_t public;
32 };
33
34 /**
35 * Implementation of pem_plugin_t.pemtroy
36 */
37 static void destroy(private_pem_plugin_t *this)
38 {
39 lib->creds->remove_builder(lib->creds,
40 (builder_function_t)pem_private_key_load);
41 lib->creds->remove_builder(lib->creds,
42 (builder_function_t)pem_public_key_load);
43 lib->creds->remove_builder(lib->creds,
44 (builder_function_t)pem_certificate_load);
45 free(this);
46 }
47
48 /*
49 * see header file
50 */
51 plugin_t *pem_plugin_create()
52 {
53 private_pem_plugin_t *this = malloc_thing(private_pem_plugin_t);
54
55 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
56
57 /* register private key PEM decoding builders */
58 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ANY,
59 (builder_function_t)pem_private_key_load);
60 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
61 (builder_function_t)pem_private_key_load);
62 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA,
63 (builder_function_t)pem_private_key_load);
64 lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_DSA,
65 (builder_function_t)pem_private_key_load);
66
67 /* register public key PEM decoding builders */
68 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
69 (builder_function_t)pem_public_key_load);
70 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
71 (builder_function_t)pem_public_key_load);
72 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ECDSA,
73 (builder_function_t)pem_public_key_load);
74 lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_DSA,
75 (builder_function_t)pem_public_key_load);
76
77 /* register certificate PEM decoding builders */
78 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_ANY,
79 (builder_function_t)pem_certificate_load);
80 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509,
81 (builder_function_t)pem_certificate_load);
82 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_CRL,
83 (builder_function_t)pem_certificate_load);
84 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_OCSP_REQUEST,
85 (builder_function_t)pem_certificate_load);
86 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_OCSP_RESPONSE,
87 (builder_function_t)pem_certificate_load);
88 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_X509_AC,
89 (builder_function_t)pem_certificate_load);
90 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_PKCS10_REQUEST,
91 (builder_function_t)pem_certificate_load);
92 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_TRUSTED_PUBKEY,
93 (builder_function_t)pem_certificate_load);
94 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_GPG,
95 (builder_function_t)pem_certificate_load);
96
97 /* register pluto specific certificate formats */
98 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_PLUTO_CERT,
99 (builder_function_t)pem_certificate_load);
100 lib->creds->add_builder(lib->creds, CRED_CERTIFICATE, CERT_PLUTO_CRL,
101 (builder_function_t)pem_certificate_load);
102
103 return &this->public.plugin;
104 }
105