]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/charon-tkm/src/tkm/tkm.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / charon-tkm / src / tkm / tkm.c
1 /*
2 * Copyright (C) 2012-2014 Reto Buerki
3 * Copyright (C) 2012 Adrian-Ken Rueegsegger
4 *
5 * Copyright (C) secunet Security Networks AG
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 #include <daemon.h>
19
20 #include <tkm/client.h>
21 #include <tkm/constants.h>
22
23 #include "tkm.h"
24
25 #define IKE_SOCKET "/tmp/tkm.rpc.ike"
26 #define EES_SOCKET "/tmp/tkm.rpc.ees"
27
28 typedef struct private_tkm_t private_tkm_t;
29
30 extern result_type ees_server_init(const char * const address);
31 extern void ees_server_finalize(void);
32 extern void ehandler_init(void);
33
34 /*
35 * Private additions to tkm_t.
36 */
37 struct private_tkm_t {
38
39 /**
40 * Public members of tkm_t.
41 */
42 tkm_t public;
43 };
44
45 /**
46 * Single instance of tkm_t.
47 */
48 tkm_t *tkm = NULL;
49
50 /**
51 * Described in header.
52 */
53 bool tkm_init()
54 {
55 private_tkm_t *this;
56 active_requests_type max_requests;
57 char *ikesock, *eessock;
58 tkm_limits_t limits;
59
60 /* initialize TKM client library */
61 tkmlib_init();
62 ehandler_init();
63
64 ikesock = lib->settings->get_str(lib->settings, "%s.ike_socket", IKE_SOCKET,
65 lib->ns);
66 if (ike_init(ikesock) != TKM_OK)
67 {
68 tkmlib_final();
69 return FALSE;
70 }
71 DBG1(DBG_DMN, "connected to TKM via socket '%s'", ikesock);
72
73 eessock = lib->settings->get_str(lib->settings, "%s.ees_socket", EES_SOCKET,
74 lib->ns);
75 ees_server_init(eessock);
76 DBG1(DBG_DMN, "serving EES requests on socket '%s'", eessock);
77
78 if (ike_tkm_reset() != TKM_OK)
79 {
80 ees_server_finalize();
81 tkmlib_final();
82 return FALSE;
83 }
84
85 /* get limits from tkm */
86 if (ike_tkm_limits(&max_requests, &limits[TKM_CTX_NONCE], &limits[TKM_CTX_DH],
87 &limits[TKM_CTX_CC], &limits[TKM_CTX_AE],
88 &limits[TKM_CTX_ISA], &limits[TKM_CTX_ESA]) != TKM_OK)
89 {
90 ees_server_finalize();
91 tkmlib_final();
92 return FALSE;
93 }
94
95 INIT(this,
96 .public = {
97 .idmgr = tkm_id_manager_create(limits),
98 .chunk_map = tkm_chunk_map_create(),
99 .sad = tkm_kernel_sad_create(),
100 },
101 );
102 tkm = &this->public;
103
104 return TRUE;
105 }
106
107 /**
108 * Described in header.
109 */
110 void tkm_deinit()
111 {
112 if (!tkm)
113 {
114 return;
115 }
116 private_tkm_t *this = (private_tkm_t*)tkm;
117 this->public.idmgr->destroy(this->public.idmgr);
118 this->public.chunk_map->destroy(this->public.chunk_map);
119 this->public.sad->destroy(this->public.sad);
120
121 ees_server_finalize();
122
123 ike_finalize();
124
125 tkmlib_final();
126 free(this);
127 tkm = NULL;
128 }