2012-05-18 12:09:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Reto Buerki
|
|
|
|
* Copyright (C) 2012 Adrian-Ken Rueegsegger
|
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* 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-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-05-18 12:09:24 +00:00
|
|
|
typedef struct private_tkm_t private_tkm_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
nc_id_type nc;
|
|
|
|
dh_id_type dh;
|
|
|
|
cc_id_type cc;
|
|
|
|
ae_id_type ae;
|
|
|
|
isa_id_type isa;
|
|
|
|
esa_id_type esa;
|
|
|
|
|
2012-06-07 15:45:34 +00:00
|
|
|
/* initialize TKM client library */
|
|
|
|
tkmlib_init();
|
|
|
|
if (ike_init(IKE_SOCKET) != TKM_OK)
|
|
|
|
{
|
|
|
|
tkmlib_final();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ike_tkm_reset() != TKM_OK)
|
|
|
|
{
|
|
|
|
tkmlib_final();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:12:40 +00:00
|
|
|
/* get limits from tkm */
|
|
|
|
if (ike_tkm_limits(&max_requests, &nc, &dh, &cc, &ae, &isa, &esa) != TKM_OK)
|
|
|
|
{
|
|
|
|
tkmlib_final();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:18:05 +00:00
|
|
|
/* only nonce and DH context limits are currently needed */
|
|
|
|
const tkm_limits_t limits = {nc, dh};
|
|
|
|
|
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-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-06-07 15:45:34 +00:00
|
|
|
|
|
|
|
tkmlib_final();
|
2012-05-18 12:09:24 +00:00
|
|
|
free(this);
|
|
|
|
tkm = NULL;
|
|
|
|
}
|