Separated libcharon/sa directory with ikev1 and ikev2 subfolders
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "hybrid_authenticator.h"
|
||||
|
||||
#include <daemon.h>
|
||||
|
||||
typedef struct private_hybrid_authenticator_t private_hybrid_authenticator_t;
|
||||
|
||||
/**
|
||||
* Private data of an hybrid_authenticator_t object.
|
||||
*/
|
||||
struct private_hybrid_authenticator_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
hybrid_authenticator_t public;
|
||||
|
||||
/**
|
||||
* Public key authenticator
|
||||
*/
|
||||
authenticator_t *sig;
|
||||
|
||||
/**
|
||||
* HASH payload authenticator without credentials
|
||||
*/
|
||||
authenticator_t *hash;
|
||||
};
|
||||
|
||||
METHOD(authenticator_t, build_i, status_t,
|
||||
private_hybrid_authenticator_t *this, message_t *message)
|
||||
{
|
||||
return this->hash->build(this->hash, message);
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, process_r, status_t,
|
||||
private_hybrid_authenticator_t *this, message_t *message)
|
||||
{
|
||||
return this->hash->process(this->hash, message);
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, build_r, status_t,
|
||||
private_hybrid_authenticator_t *this, message_t *message)
|
||||
{
|
||||
return this->sig->build(this->sig, message);
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, process_i, status_t,
|
||||
private_hybrid_authenticator_t *this, message_t *message)
|
||||
{
|
||||
return this->sig->process(this->sig, message);
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, destroy, void,
|
||||
private_hybrid_authenticator_t *this)
|
||||
{
|
||||
DESTROY_IF(this->hash);
|
||||
DESTROY_IF(this->sig);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
hybrid_authenticator_t *hybrid_authenticator_create(ike_sa_t *ike_sa,
|
||||
bool initiator, diffie_hellman_t *dh,
|
||||
chunk_t dh_value, chunk_t sa_payload,
|
||||
chunk_t id_payload)
|
||||
{
|
||||
private_hybrid_authenticator_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.authenticator = {
|
||||
.is_mutual = (void*)return_false,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
.sig = authenticator_create_v1(ike_sa, initiator, AUTH_RSA, dh,
|
||||
dh_value, sa_payload, id_payload),
|
||||
.hash = authenticator_create_v1(ike_sa, initiator, AUTH_PSK,
|
||||
dh, dh_value, sa_payload, chunk_clone(id_payload)),
|
||||
);
|
||||
if (!this->sig || !this->hash)
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
if (initiator)
|
||||
{
|
||||
this->public.authenticator.build = _build_i;
|
||||
this->public.authenticator.process = _process_i;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->public.authenticator.build = _build_r;
|
||||
this->public.authenticator.process = _process_r;
|
||||
}
|
||||
return &this->public;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup hybrid_authenticator hybrid_authenticator
|
||||
* @{ @ingroup authenticators
|
||||
*/
|
||||
|
||||
#ifndef HYBRID_AUTHENTICATOR_H_
|
||||
#define HYBRID_AUTHENTICATOR_H_
|
||||
|
||||
typedef struct hybrid_authenticator_t hybrid_authenticator_t;
|
||||
|
||||
#include <sa/authenticator.h>
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t using IKEv1 hybrid authentication.
|
||||
*/
|
||||
struct hybrid_authenticator_t {
|
||||
|
||||
/**
|
||||
* Implemented authenticator_t interface.
|
||||
*/
|
||||
authenticator_t authenticator;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an authenticator to build hybrid signatures.
|
||||
*
|
||||
* @param ike_sa associated IKE_SA
|
||||
* @param initiator TRUE if we are the IKE_SA initiator
|
||||
* @param dh diffie hellman key exchange
|
||||
* @param dh_value others public diffie hellman value
|
||||
* @param sa_payload generated SA payload data, without payload header
|
||||
* @param id_payload encoded ID payload of peer to authenticate or verify
|
||||
* without payload header (gets owned)
|
||||
* @return hybrid authenticator
|
||||
*/
|
||||
hybrid_authenticator_t *hybrid_authenticator_create(ike_sa_t *ike_sa,
|
||||
bool initiator, diffie_hellman_t *dh,
|
||||
chunk_t dh_value, chunk_t sa_payload,
|
||||
chunk_t id_payload);
|
||||
|
||||
#endif /** HYBRID_AUTHENTICATOR_H_ @}*/
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "psk_v1_authenticator.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <sa/ikev1/keymat_v1.h>
|
||||
#include <encoding/payloads/hash_payload.h>
|
||||
|
||||
typedef struct private_psk_v1_authenticator_t private_psk_v1_authenticator_t;
|
||||
|
||||
/**
|
||||
* Private data of an psk_v1_authenticator_t object.
|
||||
*/
|
||||
struct private_psk_v1_authenticator_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
psk_v1_authenticator_t public;
|
||||
|
||||
/**
|
||||
* Assigned IKE_SA
|
||||
*/
|
||||
ike_sa_t *ike_sa;
|
||||
|
||||
/**
|
||||
* TRUE if we are initiator
|
||||
*/
|
||||
bool initiator;
|
||||
|
||||
/**
|
||||
* DH key exchange
|
||||
*/
|
||||
diffie_hellman_t *dh;
|
||||
|
||||
/**
|
||||
* Others DH public value
|
||||
*/
|
||||
chunk_t dh_value;
|
||||
|
||||
/**
|
||||
* Encoded SA payload, without fixed header
|
||||
*/
|
||||
chunk_t sa_payload;
|
||||
|
||||
/**
|
||||
* Encoded ID payload, without fixed header
|
||||
*/
|
||||
chunk_t id_payload;
|
||||
};
|
||||
|
||||
METHOD(authenticator_t, build, status_t,
|
||||
private_psk_v1_authenticator_t *this, message_t *message)
|
||||
{
|
||||
hash_payload_t *hash_payload;
|
||||
keymat_v1_t *keymat;
|
||||
chunk_t hash, dh;
|
||||
|
||||
this->dh->get_my_public_value(this->dh, &dh);
|
||||
keymat = (keymat_v1_t*)this->ike_sa->get_keymat(this->ike_sa);
|
||||
hash = keymat->get_hash(keymat, this->initiator, dh, this->dh_value,
|
||||
this->ike_sa->get_id(this->ike_sa), this->sa_payload,
|
||||
this->id_payload);
|
||||
free(dh.ptr);
|
||||
|
||||
hash_payload = hash_payload_create(HASH_V1);
|
||||
hash_payload->set_hash(hash_payload, hash);
|
||||
message->add_payload(message, &hash_payload->payload_interface);
|
||||
free(hash.ptr);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, process, status_t,
|
||||
private_psk_v1_authenticator_t *this, message_t *message)
|
||||
{
|
||||
hash_payload_t *hash_payload;
|
||||
keymat_v1_t *keymat;
|
||||
chunk_t hash, dh;
|
||||
|
||||
hash_payload = (hash_payload_t*)message->get_payload(message, HASH_V1);
|
||||
if (!hash_payload)
|
||||
{
|
||||
DBG1(DBG_IKE, "HASH payload missing in message");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
this->dh->get_my_public_value(this->dh, &dh);
|
||||
keymat = (keymat_v1_t*)this->ike_sa->get_keymat(this->ike_sa);
|
||||
hash = keymat->get_hash(keymat, !this->initiator, this->dh_value, dh,
|
||||
this->ike_sa->get_id(this->ike_sa), this->sa_payload,
|
||||
this->id_payload);
|
||||
free(dh.ptr);
|
||||
if (chunk_equals(hash, hash_payload->get_hash(hash_payload)))
|
||||
{
|
||||
free(hash.ptr);
|
||||
return SUCCESS;
|
||||
}
|
||||
free(hash.ptr);
|
||||
DBG1(DBG_IKE, "calculated HASH does not match HASH payload");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, destroy, void,
|
||||
private_psk_v1_authenticator_t *this)
|
||||
{
|
||||
chunk_free(&this->id_payload);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
psk_v1_authenticator_t *psk_v1_authenticator_create(ike_sa_t *ike_sa,
|
||||
bool initiator, diffie_hellman_t *dh,
|
||||
chunk_t dh_value, chunk_t sa_payload,
|
||||
chunk_t id_payload)
|
||||
{
|
||||
private_psk_v1_authenticator_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.authenticator = {
|
||||
.build = _build,
|
||||
.process = _process,
|
||||
.is_mutual = (void*)return_false,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
.ike_sa = ike_sa,
|
||||
.initiator = initiator,
|
||||
.dh = dh,
|
||||
.dh_value = dh_value,
|
||||
.sa_payload = sa_payload,
|
||||
.id_payload = id_payload,
|
||||
);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup psk_v1_authenticator psk_v1_authenticator
|
||||
* @{ @ingroup authenticators
|
||||
*/
|
||||
|
||||
#ifndef PSK_V1_AUTHENTICATOR_H_
|
||||
#define PSK_V1_AUTHENTICATOR_H_
|
||||
|
||||
typedef struct psk_v1_authenticator_t psk_v1_authenticator_t;
|
||||
|
||||
#include <sa/authenticator.h>
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t using pre-shared keys for IKEv1.
|
||||
*/
|
||||
struct psk_v1_authenticator_t {
|
||||
|
||||
/**
|
||||
* Implemented authenticator_t interface.
|
||||
*/
|
||||
authenticator_t authenticator;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an authenticator to build PSK signatures.
|
||||
*
|
||||
* @param ike_sa associated IKE_SA
|
||||
* @param initiator TRUE if we are the IKE_SA initiator
|
||||
* @param dh diffie hellman key exchange
|
||||
* @param dh_value others public diffie hellman value
|
||||
* @param sa_payload generated SA payload data, without payload header
|
||||
* @param id_payload encoded ID payload of peer to authenticate or verify
|
||||
* without payload header (gets owned)
|
||||
* @return PSK authenticator
|
||||
*/
|
||||
psk_v1_authenticator_t *psk_v1_authenticator_create(ike_sa_t *ike_sa,
|
||||
bool initiator, diffie_hellman_t *dh,
|
||||
chunk_t dh_value, chunk_t sa_payload,
|
||||
chunk_t id_payload);
|
||||
|
||||
#endif /** PSK_V1_AUTHENTICATOR_H_ @}*/
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "pubkey_v1_authenticator.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <sa/ikev1/keymat_v1.h>
|
||||
#include <encoding/payloads/hash_payload.h>
|
||||
|
||||
typedef struct private_pubkey_v1_authenticator_t private_pubkey_v1_authenticator_t;
|
||||
|
||||
/**
|
||||
* Private data of an pubkey_v1_authenticator_t object.
|
||||
*/
|
||||
struct private_pubkey_v1_authenticator_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
pubkey_v1_authenticator_t public;
|
||||
|
||||
/**
|
||||
* Assigned IKE_SA
|
||||
*/
|
||||
ike_sa_t *ike_sa;
|
||||
|
||||
/**
|
||||
* TRUE if we are initiator
|
||||
*/
|
||||
bool initiator;
|
||||
|
||||
/**
|
||||
* DH key exchange
|
||||
*/
|
||||
diffie_hellman_t *dh;
|
||||
|
||||
/**
|
||||
* Others DH public value
|
||||
*/
|
||||
chunk_t dh_value;
|
||||
|
||||
/**
|
||||
* Encoded SA payload, without fixed header
|
||||
*/
|
||||
chunk_t sa_payload;
|
||||
|
||||
/**
|
||||
* Encoded ID payload, without fixed header
|
||||
*/
|
||||
chunk_t id_payload;
|
||||
};
|
||||
|
||||
METHOD(authenticator_t, build, status_t,
|
||||
private_pubkey_v1_authenticator_t *this, message_t *message)
|
||||
{
|
||||
hash_payload_t *sig_payload;
|
||||
chunk_t hash, sig, dh;
|
||||
keymat_v1_t *keymat;
|
||||
status_t status;
|
||||
private_key_t *private;
|
||||
identification_t *id;
|
||||
auth_cfg_t *auth;
|
||||
key_type_t type;
|
||||
signature_scheme_t scheme;
|
||||
|
||||
/* TODO-IKEv1: other key types */
|
||||
type = KEY_RSA;
|
||||
scheme = SIGN_RSA_EMSA_PKCS1_NULL;
|
||||
|
||||
id = this->ike_sa->get_my_id(this->ike_sa);
|
||||
auth = this->ike_sa->get_auth_cfg(this->ike_sa, TRUE);
|
||||
private = lib->credmgr->get_private(lib->credmgr, type, id, auth);
|
||||
if (!private)
|
||||
{
|
||||
DBG1(DBG_IKE, "no private key found for '%Y'", id);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
this->dh->get_my_public_value(this->dh, &dh);
|
||||
keymat = (keymat_v1_t*)this->ike_sa->get_keymat(this->ike_sa);
|
||||
hash = keymat->get_hash(keymat, this->initiator, dh, this->dh_value,
|
||||
this->ike_sa->get_id(this->ike_sa), this->sa_payload,
|
||||
this->id_payload);
|
||||
free(dh.ptr);
|
||||
|
||||
if (private->sign(private, scheme, hash, &sig))
|
||||
{
|
||||
sig_payload = hash_payload_create(SIGNATURE_V1);
|
||||
sig_payload->set_hash(sig_payload, sig);
|
||||
free(sig.ptr);
|
||||
message->add_payload(message, &sig_payload->payload_interface);
|
||||
status = SUCCESS;
|
||||
DBG1(DBG_IKE, "authentication of '%Y' (myself) successful", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(DBG_IKE, "authentication of '%Y' (myself) failed", id);
|
||||
status = FAILED;
|
||||
}
|
||||
private->destroy(private);
|
||||
free(hash.ptr);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, process, status_t,
|
||||
private_pubkey_v1_authenticator_t *this, message_t *message)
|
||||
{
|
||||
chunk_t hash, sig, dh;
|
||||
keymat_v1_t *keymat;
|
||||
public_key_t *public;
|
||||
hash_payload_t *sig_payload;
|
||||
auth_cfg_t *auth, *current_auth;
|
||||
enumerator_t *enumerator;
|
||||
status_t status = NOT_FOUND;
|
||||
key_type_t type;
|
||||
signature_scheme_t scheme;
|
||||
identification_t *id;
|
||||
|
||||
/* TODO-IKEv1: currently RSA only */
|
||||
type = KEY_RSA;
|
||||
scheme = SIGN_RSA_EMSA_PKCS1_NULL;
|
||||
|
||||
sig_payload = (hash_payload_t*)message->get_payload(message, SIGNATURE_V1);
|
||||
if (!sig_payload)
|
||||
{
|
||||
DBG1(DBG_IKE, "SIG payload missing in message");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
id = this->ike_sa->get_other_id(this->ike_sa);
|
||||
this->dh->get_my_public_value(this->dh, &dh);
|
||||
keymat = (keymat_v1_t*)this->ike_sa->get_keymat(this->ike_sa);
|
||||
hash = keymat->get_hash(keymat, !this->initiator, this->dh_value, dh,
|
||||
this->ike_sa->get_id(this->ike_sa), this->sa_payload,
|
||||
this->id_payload);
|
||||
free(dh.ptr);
|
||||
|
||||
sig = sig_payload->get_hash(sig_payload);
|
||||
auth = this->ike_sa->get_auth_cfg(this->ike_sa, FALSE);
|
||||
enumerator = lib->credmgr->create_public_enumerator(lib->credmgr, type,
|
||||
id, auth);
|
||||
while (enumerator->enumerate(enumerator, &public, ¤t_auth))
|
||||
{
|
||||
if (public->verify(public, scheme, hash, sig))
|
||||
{
|
||||
DBG1(DBG_IKE, "authentication of '%Y' with %N successful",
|
||||
id, key_type_names, type);
|
||||
status = SUCCESS;
|
||||
auth->merge(auth, current_auth, FALSE);
|
||||
auth->add(auth, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(DBG_IKE, "signature validation failed, looking for another key");
|
||||
status = FAILED;
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
free(hash.ptr);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "no trusted %N public key found for '%Y'",
|
||||
key_type_names, type, id);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
METHOD(authenticator_t, destroy, void,
|
||||
private_pubkey_v1_authenticator_t *this)
|
||||
{
|
||||
chunk_free(&this->id_payload);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
pubkey_v1_authenticator_t *pubkey_v1_authenticator_create(ike_sa_t *ike_sa,
|
||||
bool initiator, diffie_hellman_t *dh,
|
||||
chunk_t dh_value, chunk_t sa_payload,
|
||||
chunk_t id_payload)
|
||||
{
|
||||
private_pubkey_v1_authenticator_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.authenticator = {
|
||||
.build = _build,
|
||||
.process = _process,
|
||||
.is_mutual = (void*)return_false,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
.ike_sa = ike_sa,
|
||||
.initiator = initiator,
|
||||
.dh = dh,
|
||||
.dh_value = dh_value,
|
||||
.sa_payload = sa_payload,
|
||||
.id_payload = id_payload,
|
||||
);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup pubkey_v1_authenticator pubkey_v1_authenticator
|
||||
* @{ @ingroup authenticators
|
||||
*/
|
||||
|
||||
#ifndef PUBKEY_V1_AUTHENTICATOR_H_
|
||||
#define PUBKEY_V1_AUTHENTICATOR_H_
|
||||
|
||||
typedef struct pubkey_v1_authenticator_t pubkey_v1_authenticator_t;
|
||||
|
||||
#include <sa/authenticator.h>
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t using public keys for IKEv1.
|
||||
*/
|
||||
struct pubkey_v1_authenticator_t {
|
||||
|
||||
/**
|
||||
* Implemented authenticator_t interface.
|
||||
*/
|
||||
authenticator_t authenticator;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an authenticator to build and verify public key signatures.
|
||||
*
|
||||
* @param ike_sa associated IKE_SA
|
||||
* @param initiator TRUE if we are IKE_SA initiator
|
||||
* @param dh diffie hellman key exchange
|
||||
* @param dh_value others public diffie hellman value
|
||||
* @param sa_payload generated SA payload data, without payload header
|
||||
* @param id_payload encoded ID payload of peer to authenticate or verify
|
||||
* without payload header (gets owned)
|
||||
* @return pubkey authenticator
|
||||
*/
|
||||
pubkey_v1_authenticator_t *pubkey_v1_authenticator_create(ike_sa_t *ike_sa,
|
||||
bool initiator, diffie_hellman_t *dh,
|
||||
chunk_t dh_value, chunk_t sa_payload,
|
||||
chunk_t id_payload);
|
||||
|
||||
#endif /** PUBKEY_V1_AUTHENTICATOR_H_ @}*/
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "xauth_manager.h"
|
||||
|
||||
#include <utils/linked_list.h>
|
||||
#include <threading/rwlock.h>
|
||||
|
||||
typedef struct private_xauth_manager_t private_xauth_manager_t;
|
||||
typedef struct xauth_entry_t xauth_entry_t;
|
||||
|
||||
/**
|
||||
* XAuth constructor entry
|
||||
*/
|
||||
struct xauth_entry_t {
|
||||
|
||||
/**
|
||||
* Xauth backend name
|
||||
*/
|
||||
char *name;
|
||||
|
||||
/**
|
||||
* Role of the method, XAUTH_SERVER or XAUTH_PEER
|
||||
*/
|
||||
xauth_role_t role;
|
||||
|
||||
/**
|
||||
* constructor function to create instance
|
||||
*/
|
||||
xauth_constructor_t constructor;
|
||||
};
|
||||
|
||||
/**
|
||||
* private data of xauth_manager
|
||||
*/
|
||||
struct private_xauth_manager_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
xauth_manager_t public;
|
||||
|
||||
/**
|
||||
* list of eap_entry_t's
|
||||
*/
|
||||
linked_list_t *methods;
|
||||
|
||||
/**
|
||||
* rwlock to lock methods
|
||||
*/
|
||||
rwlock_t *lock;
|
||||
};
|
||||
|
||||
METHOD(xauth_manager_t, add_method, void,
|
||||
private_xauth_manager_t *this, char *name, xauth_role_t role,
|
||||
xauth_constructor_t constructor)
|
||||
{
|
||||
xauth_entry_t *entry;
|
||||
|
||||
INIT(entry,
|
||||
.name = name,
|
||||
.role = role,
|
||||
.constructor = constructor,
|
||||
);
|
||||
|
||||
this->lock->write_lock(this->lock);
|
||||
this->methods->insert_last(this->methods, entry);
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
METHOD(xauth_manager_t, remove_method, void,
|
||||
private_xauth_manager_t *this, xauth_constructor_t constructor)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
xauth_entry_t *entry;
|
||||
|
||||
this->lock->write_lock(this->lock);
|
||||
enumerator = this->methods->create_enumerator(this->methods);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
if (constructor == entry->constructor)
|
||||
{
|
||||
this->methods->remove_at(this->methods, enumerator);
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
METHOD(xauth_manager_t, create_instance, xauth_method_t*,
|
||||
private_xauth_manager_t *this, char *name, xauth_role_t role,
|
||||
identification_t *server, identification_t *peer)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
xauth_entry_t *entry;
|
||||
xauth_method_t *method = NULL;
|
||||
|
||||
this->lock->read_lock(this->lock);
|
||||
enumerator = this->methods->create_enumerator(this->methods);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
if (role == entry->role &&
|
||||
(!name || streq(name, entry->name)))
|
||||
{
|
||||
method = entry->constructor(server, peer);
|
||||
if (method)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
this->lock->unlock(this->lock);
|
||||
return method;
|
||||
}
|
||||
|
||||
METHOD(xauth_manager_t, destroy, void,
|
||||
private_xauth_manager_t *this)
|
||||
{
|
||||
this->methods->destroy_function(this->methods, free);
|
||||
this->lock->destroy(this->lock);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* See header
|
||||
*/
|
||||
xauth_manager_t *xauth_manager_create()
|
||||
{
|
||||
private_xauth_manager_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.add_method = _add_method,
|
||||
.remove_method = _remove_method,
|
||||
.create_instance = _create_instance,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.methods = linked_list_create(),
|
||||
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
|
||||
);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Martin Willi
|
||||
* Copyright (C) 2011 revosec AG
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup xauth_manager xauth_manager
|
||||
* @{ @ingroup xauth
|
||||
*/
|
||||
|
||||
#ifndef XAUTH_MANAGER_H_
|
||||
#define XAUTH_MANAGER_H_
|
||||
|
||||
#include <sa/ikev1/authenticators/xauth/xauth_method.h>
|
||||
|
||||
typedef struct xauth_manager_t xauth_manager_t;
|
||||
|
||||
/**
|
||||
* The XAuth manager manages all XAuth implementations and creates instances.
|
||||
*
|
||||
* A plugin registers it's implemented XAuth method at the manager by
|
||||
* providing type and a contructor function. The manager then instanciates
|
||||
* xauth_method_t instances through the provided constructor to handle
|
||||
* XAuth authentication.
|
||||
*/
|
||||
struct xauth_manager_t {
|
||||
|
||||
/**
|
||||
* Register a XAuth method implementation.
|
||||
*
|
||||
* @param name backend name to register
|
||||
* @param role XAUTH_SERVER or XAUTH_PEER
|
||||
* @param constructor constructor function, returns an xauth_method_t
|
||||
*/
|
||||
void (*add_method)(xauth_manager_t *this, char *name,
|
||||
xauth_role_t role, xauth_constructor_t constructor);
|
||||
|
||||
/**
|
||||
* Unregister a XAuth method implementation using it's constructor.
|
||||
*
|
||||
* @param constructor constructor function, as added in add_method
|
||||
*/
|
||||
void (*remove_method)(xauth_manager_t *this, xauth_constructor_t constructor);
|
||||
|
||||
/**
|
||||
* Create a new XAuth method instance.
|
||||
*
|
||||
* @param name backend name, as it was registered with
|
||||
* @param role XAUTH_SERVER or XAUTH_PEER
|
||||
* @param server identity of the server
|
||||
* @param peer identity of the peer (client)
|
||||
* @return XAUTH method instance, NULL if no constructor found
|
||||
*/
|
||||
xauth_method_t* (*create_instance)(xauth_manager_t *this,
|
||||
char *name, xauth_role_t role,
|
||||
identification_t *server, identification_t *peer);
|
||||
|
||||
/**
|
||||
* Destroy a eap_manager instance.
|
||||
*/
|
||||
void (*destroy)(xauth_manager_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a eap_manager instance.
|
||||
*/
|
||||
xauth_manager_t *xauth_manager_create();
|
||||
|
||||
#endif /** XAUTH_MANAGER_H_ @}*/
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "xauth_method.h"
|
||||
|
||||
#include <daemon.h>
|
||||
|
||||
ENUM(xauth_role_names, XAUTH_SERVER, XAUTH_PEER,
|
||||
"XAUTH_SERVER",
|
||||
"XAUTH_PEER",
|
||||
);
|
||||
|
||||
/**
|
||||
* See header
|
||||
*/
|
||||
bool xauth_method_register(plugin_t *plugin, plugin_feature_t *feature,
|
||||
bool reg, void *data)
|
||||
{
|
||||
if (reg)
|
||||
{
|
||||
charon->xauth->add_method(charon->xauth, feature->arg.xauth,
|
||||
feature->type == FEATURE_XAUTH_SERVER ? XAUTH_SERVER : XAUTH_PEER,
|
||||
(xauth_constructor_t)data);
|
||||
}
|
||||
else
|
||||
{
|
||||
charon->xauth->remove_method(charon->xauth, (xauth_constructor_t)data);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup xauth_method xauth_method
|
||||
* @{ @ingroup xauth
|
||||
*/
|
||||
|
||||
#ifndef XAUTH_METHOD_H_
|
||||
#define XAUTH_METHOD_H_
|
||||
|
||||
typedef struct xauth_method_t xauth_method_t;
|
||||
typedef enum xauth_role_t xauth_role_t;
|
||||
|
||||
#include <library.h>
|
||||
#include <plugins/plugin.h>
|
||||
#include <utils/identification.h>
|
||||
#include <encoding/payloads/cp_payload.h>
|
||||
|
||||
/**
|
||||
* Role of an xauth_method, SERVER or PEER (client)
|
||||
*/
|
||||
enum xauth_role_t {
|
||||
XAUTH_SERVER,
|
||||
XAUTH_PEER,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum names for xauth_role_t.
|
||||
*/
|
||||
extern enum_name_t *xauth_role_names;
|
||||
|
||||
/**
|
||||
* Interface of an XAuth method for server and client side.
|
||||
*
|
||||
* An XAuth method initiates an XAuth exchange and processes requests and
|
||||
* responses. An XAuth method may need multiple exchanges before succeeding.
|
||||
* Sending of XAUTH(STATUS) message is done by the framework, not a method.
|
||||
*/
|
||||
struct xauth_method_t {
|
||||
|
||||
/**
|
||||
* Initiate the XAuth exchange.
|
||||
*
|
||||
* initiate() is only useable for server implementations, as clients only
|
||||
* reply to server requests.
|
||||
* A cp_payload is created in "out" if result is NEED_MORE.
|
||||
*
|
||||
* @param out cp_payload to send to the client
|
||||
* @return
|
||||
* - NEED_MORE, if an other exchange is required
|
||||
* - FAILED, if unable to create XAuth request payload
|
||||
*/
|
||||
status_t (*initiate) (xauth_method_t *this, cp_payload_t **out);
|
||||
|
||||
/**
|
||||
* Process a received XAuth message.
|
||||
*
|
||||
* A cp_payload is created in "out" if result is NEED_MORE.
|
||||
*
|
||||
* @param in cp_payload response received
|
||||
* @param out created cp_payload to send
|
||||
* @return
|
||||
* - NEED_MORE, if an other exchange is required
|
||||
* - FAILED, if XAuth method failed
|
||||
* - SUCCESS, if XAuth method succeeded
|
||||
*/
|
||||
status_t (*process) (xauth_method_t *this, cp_payload_t *in,
|
||||
cp_payload_t **out);
|
||||
|
||||
/**
|
||||
* Get the XAuth username received as XAuth initiator.
|
||||
*
|
||||
* @return used XAuth username, pointer to internal data
|
||||
*/
|
||||
identification_t* (*get_identity)(xauth_method_t *this);
|
||||
|
||||
/**
|
||||
* Destroys a eap_method_t object.
|
||||
*/
|
||||
void (*destroy) (xauth_method_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor definition for a pluggable XAuth method.
|
||||
*
|
||||
* Each XAuth module must define a constructor function which will return
|
||||
* an initialized object with the methods defined in xauth_method_t.
|
||||
* Constructors for server and peers are identical, to support both roles
|
||||
* of a XAuth method, a plugin needs register two constructors in the
|
||||
* xauth_manager_t.
|
||||
*
|
||||
* @param server ID of the server to use for credential lookup
|
||||
* @param peer ID of the peer to use for credential lookup
|
||||
* @return implementation of the eap_method_t interface
|
||||
*/
|
||||
typedef xauth_method_t *(*xauth_constructor_t)(identification_t *server,
|
||||
identification_t *peer);
|
||||
|
||||
/**
|
||||
* Helper function to (un-)register XAuth methods from plugin features.
|
||||
*
|
||||
* This function is a plugin_feature_callback_t and can be used with the
|
||||
* PLUGIN_CALLBACK macro to register a XAuth method constructor.
|
||||
*
|
||||
* @param plugin plugin registering the XAuth method constructor
|
||||
* @param feature associated plugin feature
|
||||
* @param reg TRUE to register, FALSE to unregister.
|
||||
* @param data data passed to callback, an xauth_constructor_t
|
||||
*/
|
||||
bool xauth_method_register(plugin_t *plugin, plugin_feature_t *feature,
|
||||
bool reg, void *data);
|
||||
|
||||
#endif /** XAUTH_METHOD_H_ @}*/
|
||||
Reference in New Issue
Block a user