2012-05-18 12:09:24 +00:00
|
|
|
/*
|
2014-12-18 15:24:07 +00:00
|
|
|
* Copyright (C) 2012-2014 Reto Buerki
|
2012-05-18 12:09:24 +00:00
|
|
|
* Copyright (C) 2012 Adrian-Ken Rueegsegger
|
2018-05-23 14:04:50 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2012-05-18 12:09:24 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2012-12-18 16:15:58 +00:00
|
|
|
#include <daemon.h>
|
|
|
|
|
2012-06-07 15:45:34 +00:00
|
|
|
#include <tkm/client.h>
|
|
|
|
#include <tkm/constants.h>
|
|
|
|
|
2012-05-18 12:09:24 +00:00
|
|
|
#include "tkm.h"
|
|
|
|
|
2012-06-07 15:45:34 +00:00
|
|
|
#define IKE_SOCKET "/tmp/tkm.rpc.ike"
|
2012-09-26 13:40:27 +00:00
|
|
|
#define EES_SOCKET "/tmp/tkm.rpc.ees"
|
2012-06-07 15:45:34 +00:00
|
|
|
|
2012-05-18 12:09:24 +00:00
|
|
|
typedef struct private_tkm_t private_tkm_t;
|
|
|
|
|
2012-09-26 13:40:27 +00:00
|
|
|
extern result_type ees_server_init(const char * const address);
|
|
|
|
extern void ees_server_finalize(void);
|
2012-10-02 15:03:39 +00:00
|
|
|
extern void ehandler_init(void);
|
2012-09-26 13:40:27 +00:00
|
|
|
|
|
|
|
/*
|
2012-05-18 12:09:24 +00:00
|
|
|
* Private additions to tkm_t.
|
|
|
|
*/
|
|
|
|
struct private_tkm_t {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public members of tkm_t.
|
|
|
|
*/
|
|
|
|
tkm_t public;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Single instance of tkm_t.
|
|
|
|
*/
|
|
|
|
tkm_t *tkm = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Described in header.
|
|
|
|
*/
|
|
|
|
bool tkm_init()
|
|
|
|
{
|
|
|
|
private_tkm_t *this;
|
2012-08-09 13:12:40 +00:00
|
|
|
active_requests_type max_requests;
|
2013-03-18 17:47:16 +00:00
|
|
|
char *ikesock, *eessock;
|
|
|
|
tkm_limits_t limits;
|
2012-08-09 13:12:40 +00:00
|
|
|
|
2012-06-07 15:45:34 +00:00
|
|
|
/* initialize TKM client library */
|
|
|
|
tkmlib_init();
|
2012-10-02 15:03:39 +00:00
|
|
|
ehandler_init();
|
|
|
|
|
2013-03-18 17:47:16 +00:00
|
|
|
ikesock = lib->settings->get_str(lib->settings, "%s.ike_socket", IKE_SOCKET,
|
2014-01-22 14:19:24 +00:00
|
|
|
lib->ns);
|
2012-12-18 16:15:58 +00:00
|
|
|
if (ike_init(ikesock) != TKM_OK)
|
2012-06-07 15:45:34 +00:00
|
|
|
{
|
|
|
|
tkmlib_final();
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-12-18 16:15:58 +00:00
|
|
|
DBG1(DBG_DMN, "connected to TKM via socket '%s'", ikesock);
|
|
|
|
|
2013-03-18 17:47:16 +00:00
|
|
|
eessock = lib->settings->get_str(lib->settings, "%s.ees_socket", EES_SOCKET,
|
2014-01-22 14:19:24 +00:00
|
|
|
lib->ns);
|
2012-12-18 16:15:58 +00:00
|
|
|
ees_server_init(eessock);
|
|
|
|
DBG1(DBG_DMN, "serving EES requests on socket '%s'", eessock);
|
2012-06-07 15:45:34 +00:00
|
|
|
|
|
|
|
if (ike_tkm_reset() != TKM_OK)
|
|
|
|
{
|
2012-09-26 13:40:27 +00:00
|
|
|
ees_server_finalize();
|
2012-06-07 15:45:34 +00:00
|
|
|
tkmlib_final();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:12:40 +00:00
|
|
|
/* get limits from tkm */
|
2013-03-18 17:47:16 +00:00
|
|
|
if (ike_tkm_limits(&max_requests, &limits[TKM_CTX_NONCE], &limits[TKM_CTX_DH],
|
|
|
|
&limits[TKM_CTX_CC], &limits[TKM_CTX_AE],
|
|
|
|
&limits[TKM_CTX_ISA], &limits[TKM_CTX_ESA]) != TKM_OK)
|
2012-08-09 13:12:40 +00:00
|
|
|
{
|
2012-09-26 13:40:27 +00:00
|
|
|
ees_server_finalize();
|
2012-08-09 13:12:40 +00:00
|
|
|
tkmlib_final();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-18 12:09:24 +00:00
|
|
|
INIT(this,
|
|
|
|
.public = {
|
2012-08-09 13:18:05 +00:00
|
|
|
.idmgr = tkm_id_manager_create(limits),
|
2012-08-22 08:17:59 +00:00
|
|
|
.chunk_map = tkm_chunk_map_create(),
|
2014-12-18 15:24:07 +00:00
|
|
|
.sad = tkm_kernel_sad_create(),
|
2012-05-18 12:09:24 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
tkm = &this->public;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Described in header.
|
|
|
|
*/
|
|
|
|
void tkm_deinit()
|
|
|
|
{
|
|
|
|
if (!tkm)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
private_tkm_t *this = (private_tkm_t*)tkm;
|
|
|
|
this->public.idmgr->destroy(this->public.idmgr);
|
2012-08-22 08:17:59 +00:00
|
|
|
this->public.chunk_map->destroy(this->public.chunk_map);
|
2014-12-18 15:24:07 +00:00
|
|
|
this->public.sad->destroy(this->public.sad);
|
2012-06-07 15:45:34 +00:00
|
|
|
|
2012-09-26 13:40:27 +00:00
|
|
|
ees_server_finalize();
|
|
|
|
|
2012-06-07 15:45:34 +00:00
|
|
|
tkmlib_final();
|
2012-05-18 12:09:24 +00:00
|
|
|
free(this);
|
|
|
|
tkm = NULL;
|
|
|
|
}
|