moved typedefs to beginning of files to solve some include problems
splitted authenticator to have a separate implementation for each auth_method_t using va_copy to clone va_lists, should fix proplems on AMD64 some other cleanups
This commit is contained in:
@@ -1,356 +0,0 @@
|
||||
/**
|
||||
* @file authenticator.c
|
||||
*
|
||||
* @brief Implementation of authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* 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 <string.h>
|
||||
|
||||
#include "authenticator.h"
|
||||
|
||||
#include <config/policies/policy.h>
|
||||
#include <daemon.h>
|
||||
|
||||
/**
|
||||
* Key pad for the AUTH method SHARED_KEY_MESSAGE_INTEGRITY_CODE.
|
||||
*/
|
||||
#define IKEV2_KEY_PAD "Key Pad for IKEv2"
|
||||
|
||||
|
||||
typedef struct private_authenticator_t private_authenticator_t;
|
||||
|
||||
/**
|
||||
* Private data of an authenticator_t object.
|
||||
*/
|
||||
struct private_authenticator_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
authenticator_t public;
|
||||
|
||||
/**
|
||||
* Assigned IKE_SA
|
||||
*/
|
||||
ike_sa_t *ike_sa;
|
||||
|
||||
/**
|
||||
* auth_method to create own signature/mac/whatever..
|
||||
*/
|
||||
auth_method_t auth_method;
|
||||
|
||||
/**
|
||||
* PRF taken from the IKE_SA.
|
||||
*/
|
||||
prf_t *prf;
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds the octets to be signed (RSA or PSK) as described in section 2.15 of RFC 4306
|
||||
*/
|
||||
static chunk_t build_tbs_octets(private_authenticator_t *this,
|
||||
chunk_t last_message,
|
||||
chunk_t other_nonce,
|
||||
identification_t *id,
|
||||
bool initiator)
|
||||
{
|
||||
prf_t *prf;
|
||||
|
||||
chunk_t id_encoding = id->get_encoding(id);
|
||||
u_int8_t id_with_header[4 + id_encoding.len];
|
||||
chunk_t id_with_header_chunk = {ptr:id_with_header, len: sizeof(id_with_header)};
|
||||
|
||||
u_int8_t *current_pos;
|
||||
chunk_t octets;
|
||||
|
||||
id_with_header[0] = id->get_type(id);
|
||||
id_with_header[1] = 0x00;
|
||||
id_with_header[2] = 0x00;
|
||||
id_with_header[3] = 0x00;
|
||||
memcpy(id_with_header + 4, id_encoding.ptr, id_encoding.len);
|
||||
|
||||
if (initiator)
|
||||
{
|
||||
prf = this->ike_sa->get_prf_auth_i(this->ike_sa);
|
||||
}
|
||||
else
|
||||
{
|
||||
prf = this->ike_sa->get_prf_auth_r(this->ike_sa);
|
||||
}
|
||||
|
||||
/* 4 bytes are id type and reserved fields of id payload */
|
||||
octets.len = last_message.len + other_nonce.len + prf->get_block_size(prf);
|
||||
octets.ptr = malloc(octets.len);
|
||||
current_pos = octets.ptr;
|
||||
memcpy(current_pos, last_message.ptr, last_message.len);
|
||||
current_pos += last_message.len;
|
||||
memcpy(current_pos, other_nonce.ptr, other_nonce.len);
|
||||
current_pos += other_nonce.len;
|
||||
prf->get_bytes(prf, id_with_header_chunk, current_pos);
|
||||
|
||||
return octets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the AUTH data using auth method SHARED_KEY_MESSAGE_INTEGRITY_CODE.
|
||||
*/
|
||||
static chunk_t build_shared_key_signature(private_authenticator_t *this,
|
||||
chunk_t last_message,
|
||||
chunk_t nonce,
|
||||
identification_t *id,
|
||||
bool initiator,
|
||||
chunk_t secret)
|
||||
{
|
||||
chunk_t key_pad = {ptr: IKEV2_KEY_PAD, len:strlen(IKEV2_KEY_PAD)};
|
||||
u_int8_t key_buffer[this->prf->get_block_size(this->prf)];
|
||||
chunk_t key = {ptr: key_buffer, len: sizeof(key_buffer)};
|
||||
chunk_t auth_data;
|
||||
|
||||
chunk_t octets = build_tbs_octets(this, last_message, nonce, id, initiator);
|
||||
|
||||
/* AUTH = prf(prf(Shared Secret,"Key Pad for IKEv2"), <msg octets>) */
|
||||
this->prf->set_key(this->prf, secret);
|
||||
this->prf->get_bytes(this->prf, key_pad, key_buffer);
|
||||
this->prf->set_key(this->prf, key);
|
||||
this->prf->allocate_bytes(this->prf, octets, &auth_data);
|
||||
DBG3(DBG_IKE, "octets = message + nonce + prf(Sk_px, IDx') %B", &octets);
|
||||
DBG3(DBG_IKE, "secret %B", &secret);
|
||||
DBG3(DBG_IKE, "keypad %B", &key_pad);
|
||||
DBG3(DBG_IKE, "prf(secret, keypad) %B", &key);
|
||||
DBG3(DBG_IKE, "AUTH = prf(prf(secret, keypad), octets) %B", &auth_data);
|
||||
chunk_free(&octets);
|
||||
|
||||
return auth_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.verify_auth_data.
|
||||
*/
|
||||
static status_t verify_auth_data (private_authenticator_t *this,
|
||||
auth_payload_t *auth_payload,
|
||||
chunk_t last_received_packet,
|
||||
chunk_t my_nonce,
|
||||
identification_t *my_id,
|
||||
identification_t *other_id,
|
||||
bool initiator)
|
||||
{
|
||||
status_t status;
|
||||
chunk_t auth_data = auth_payload->get_data(auth_payload);
|
||||
auth_method_t auth_method = auth_payload->get_auth_method(auth_payload);
|
||||
|
||||
switch (auth_method)
|
||||
{
|
||||
case SHARED_KEY_MESSAGE_INTEGRITY_CODE:
|
||||
{
|
||||
chunk_t shared_key;
|
||||
chunk_t my_auth_data;
|
||||
|
||||
status = charon->credentials->get_shared_key(charon->credentials,
|
||||
my_id,
|
||||
other_id,
|
||||
&shared_key);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "no shared key found for '%D' - '%D'",
|
||||
my_id, other_id);
|
||||
chunk_free(&shared_key);
|
||||
break;
|
||||
}
|
||||
|
||||
my_auth_data = build_shared_key_signature(this, last_received_packet,
|
||||
my_nonce, other_id,
|
||||
initiator, shared_key);
|
||||
chunk_free(&shared_key);
|
||||
|
||||
|
||||
status = (auth_data.len == my_auth_data.len &&
|
||||
memeq(auth_data.ptr, my_auth_data.ptr, my_auth_data.len))
|
||||
? SUCCESS : FAILED;
|
||||
chunk_free(&my_auth_data);
|
||||
break;
|
||||
}
|
||||
case RSA_DIGITAL_SIGNATURE:
|
||||
{
|
||||
chunk_t octets;
|
||||
|
||||
rsa_public_key_t *public_key =
|
||||
charon->credentials->get_trusted_public_key(charon->credentials, other_id);
|
||||
|
||||
if (public_key == NULL)
|
||||
{
|
||||
DBG1(DBG_IKE, "no RSA public key found for '%D'", other_id);
|
||||
status = NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
octets = build_tbs_octets(this, last_received_packet, my_nonce,
|
||||
other_id, initiator);
|
||||
status = public_key->verify_emsa_pkcs1_signature(public_key, octets,
|
||||
auth_data);
|
||||
chunk_free(&octets);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "authentication of '%D' with %N successful",
|
||||
other_id, auth_method_names, auth_method);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.compute_auth_data.
|
||||
*/
|
||||
static status_t compute_auth_data (private_authenticator_t *this,
|
||||
auth_payload_t **auth_payload,
|
||||
chunk_t last_sent_packet,
|
||||
chunk_t other_nonce,
|
||||
identification_t *my_id,
|
||||
identification_t *other_id,
|
||||
bool initiator)
|
||||
{
|
||||
DBG1(DBG_IKE, "authentication of '%D' with %N (myself)",
|
||||
my_id, auth_method_names, this->auth_method);
|
||||
|
||||
switch (this->auth_method)
|
||||
{
|
||||
case SHARED_KEY_MESSAGE_INTEGRITY_CODE:
|
||||
{
|
||||
chunk_t shared_key;
|
||||
chunk_t auth_data;
|
||||
|
||||
status_t status = charon->credentials->get_shared_key(charon->credentials,
|
||||
my_id,
|
||||
other_id,
|
||||
&shared_key);
|
||||
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "no shared key found for '%D' - '%D'",
|
||||
my_id, other_id);
|
||||
return status;
|
||||
}
|
||||
|
||||
auth_data = build_shared_key_signature(this, last_sent_packet,
|
||||
other_nonce, my_id,
|
||||
initiator, shared_key);
|
||||
chunk_free(&shared_key);
|
||||
*auth_payload = auth_payload_create();
|
||||
(*auth_payload)->set_auth_method(*auth_payload,
|
||||
SHARED_KEY_MESSAGE_INTEGRITY_CODE);
|
||||
(*auth_payload)->set_data(*auth_payload, auth_data);
|
||||
|
||||
chunk_free(&auth_data);
|
||||
return SUCCESS;
|
||||
}
|
||||
case RSA_DIGITAL_SIGNATURE:
|
||||
{
|
||||
chunk_t chunk;
|
||||
chunk_t octets;
|
||||
chunk_t auth_data;
|
||||
status_t status;
|
||||
rsa_public_key_t *my_pubkey;
|
||||
rsa_private_key_t *my_key;
|
||||
|
||||
DBG2(DBG_IKE, "looking for RSA public key belonging to '%D'",
|
||||
my_id);
|
||||
|
||||
my_pubkey = charon->credentials->get_rsa_public_key(charon->credentials, my_id);
|
||||
if (my_pubkey == NULL)
|
||||
{
|
||||
DBG1(DBG_IKE, "no RSA public key found for '%D'", my_id);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
DBG2(DBG_IKE, "matching RSA public key found");
|
||||
|
||||
chunk = my_pubkey->get_keyid(my_pubkey);
|
||||
DBG2(DBG_IKE, "looking for RSA private key with keyid %#B", &chunk);
|
||||
|
||||
my_key = charon->credentials->get_rsa_private_key(charon->credentials, my_pubkey);
|
||||
if (my_key == NULL)
|
||||
{
|
||||
DBG1(DBG_IKE, "no RSA private key found with for %D with keyid %#B",
|
||||
my_id, &chunk);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
DBG2(DBG_IKE, "matching RSA private key found");
|
||||
|
||||
octets = build_tbs_octets(this, last_sent_packet, other_nonce,
|
||||
my_id, initiator);
|
||||
status = my_key->build_emsa_pkcs1_signature(my_key, HASH_SHA1,
|
||||
octets, &auth_data);
|
||||
chunk_free(&octets);
|
||||
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
my_key->destroy(my_key);
|
||||
return status;
|
||||
}
|
||||
DBG2(DBG_IKE, "successfully signed with RSA private key");
|
||||
|
||||
*auth_payload = auth_payload_create();
|
||||
(*auth_payload)->set_auth_method(*auth_payload, RSA_DIGITAL_SIGNATURE);
|
||||
(*auth_payload)->set_data(*auth_payload, auth_data);
|
||||
|
||||
my_key->destroy(my_key);
|
||||
chunk_free(&auth_data);
|
||||
return SUCCESS;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.destroy.
|
||||
*/
|
||||
static void destroy (private_authenticator_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
authenticator_t *authenticator_create(ike_sa_t *ike_sa, auth_method_t auth_method)
|
||||
{
|
||||
private_authenticator_t *this = malloc_thing(private_authenticator_t);
|
||||
|
||||
/* Public functions */
|
||||
this->public.destroy = (void(*)(authenticator_t*))destroy;
|
||||
this->public.verify_auth_data = (status_t (*) (authenticator_t*,auth_payload_t*,chunk_t,chunk_t,identification_t*,identification_t*,bool)) verify_auth_data;
|
||||
this->public.compute_auth_data = (status_t (*) (authenticator_t*,auth_payload_t**,chunk_t,chunk_t,identification_t*,identification_t*,bool)) compute_auth_data;
|
||||
|
||||
/* private data */
|
||||
this->ike_sa = ike_sa;
|
||||
this->auth_method = auth_method;
|
||||
this->prf = this->ike_sa->get_prf(this->ike_sa);
|
||||
|
||||
return &(this->public);
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/**
|
||||
* @file authenticator.h
|
||||
*
|
||||
* @brief Interface of authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AUTHENTICATOR_H_
|
||||
#define AUTHENTICATOR_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <sa/ike_sa.h>
|
||||
#include <network/packet.h>
|
||||
#include <encoding/payloads/auth_payload.h>
|
||||
#include <encoding/payloads/id_payload.h>
|
||||
|
||||
|
||||
typedef struct authenticator_t authenticator_t;
|
||||
|
||||
/**
|
||||
* @brief Class used to authenticate a peer.
|
||||
*
|
||||
* Currently the following two AUTH methods are supported:
|
||||
* - SHARED_KEY_MESSAGE_INTEGRITY_CODE
|
||||
* - RSA_DIGITAL_SIGNATURE
|
||||
*
|
||||
* This class retrieves needed data for specific AUTH methods (RSA keys, shared secrets, etc.)
|
||||
* over an internal stored protected_ike_sa_t object or directly from the configuration_t over
|
||||
* the daemon_t object "charon".
|
||||
*
|
||||
* @b Constructors:
|
||||
* - authenticator_create()
|
||||
*
|
||||
* @ingroup sa
|
||||
*/
|
||||
struct authenticator_t {
|
||||
|
||||
/**
|
||||
* @brief Verify's given authentication data.
|
||||
*
|
||||
* To verify a received AUTH payload the following data must be provided:
|
||||
* - the last received IKEv2 Message from the other peer in binary form
|
||||
* - the nonce value sent to the other peer
|
||||
* - the ID payload of the other peer
|
||||
*
|
||||
* @param this calling object
|
||||
* @param last_received_packet binary representation of the last received IKEv2-Message
|
||||
* @param my_nonce the sent nonce (without payload header)
|
||||
* @param my_id my ID
|
||||
* @param other_id peer ID
|
||||
* @param initiator type of peer. TRUE, if it is original initiator, FALSE otherwise
|
||||
*
|
||||
* @todo Document RSA error status types
|
||||
*
|
||||
* @return
|
||||
* - SUCCESS if verification successful
|
||||
* - FAILED if verification failed
|
||||
* - NOT_SUPPORTED if AUTH method not supported
|
||||
* - NOT_FOUND if the data for specific AUTH method could not be found
|
||||
* (e.g. shared secret, rsa key)
|
||||
*/
|
||||
status_t (*verify_auth_data) (authenticator_t *this,
|
||||
auth_payload_t *auth_payload,
|
||||
chunk_t last_received_packet,
|
||||
chunk_t my_nonce,
|
||||
identification_t *my_id,
|
||||
identification_t *other_id,
|
||||
bool initiator);
|
||||
|
||||
/**
|
||||
* @brief Computes authentication data and creates specific AUTH payload.
|
||||
*
|
||||
* To create an AUTH payload, the following data must be provided:
|
||||
* - the last sent IKEv2 Message in binary form
|
||||
* - the nonce value received from the other peer
|
||||
* - the ID payload of myself
|
||||
*
|
||||
* @param this calling object
|
||||
* @param[out] auth_payload The object of typee auth_payload_t will be created at pointing location
|
||||
* @param last_sent_packet binary representation of the last sent IKEv2-Message
|
||||
* @param other_nonce the received nonce (without payload header)
|
||||
* @param my_id my ID
|
||||
* @param other_id peer ID
|
||||
* @param initiator type of myself. TRUE, if I'm original initiator, FALSE otherwise
|
||||
*
|
||||
* @todo Document RSA error status types
|
||||
*
|
||||
* @return
|
||||
* - SUCCESS if authentication data could be computed
|
||||
* - NOT_SUPPORTED if AUTH method not supported
|
||||
* - NOT_FOUND if the data for AUTH method could not be found
|
||||
*/
|
||||
status_t (*compute_auth_data) (authenticator_t *this,
|
||||
auth_payload_t **auth_payload,
|
||||
chunk_t last_sent_packet,
|
||||
chunk_t other_nonce,
|
||||
identification_t *my_id,
|
||||
identification_t *other_id,
|
||||
bool initiator);
|
||||
|
||||
/**
|
||||
* @brief Destroys a authenticator_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (authenticator_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an authenticator object.
|
||||
*
|
||||
* @param ike_sa associated ike_sa
|
||||
* @param auth_method authentication method to use for own signature/mac
|
||||
*
|
||||
* @return authenticator_t object
|
||||
*
|
||||
* @ingroup sa
|
||||
*/
|
||||
authenticator_t *authenticator_create(ike_sa_t *ike_sa, auth_method_t auth_method);
|
||||
|
||||
#endif /* AUTHENTICATOR_H_ */
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file authenticator.c
|
||||
*
|
||||
* @brief Generic constructor for authenticators.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "authenticator.h"
|
||||
|
||||
#include <sa/authenticators/rsa_authenticator.h>
|
||||
#include <sa/authenticators/psk_authenticator.h>
|
||||
|
||||
|
||||
ENUM_BEGIN(auth_method_names, AUTH_RSA, AUTH_DSS,
|
||||
"RSA signature",
|
||||
"pre-shared key",
|
||||
"DSS signature");
|
||||
ENUM_NEXT(auth_method_names, AUTH_EAP, AUTH_EAP, AUTH_DSS,
|
||||
"EAP");
|
||||
ENUM_END(auth_method_names, AUTH_EAP);
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
authenticator_t *authenticator_create(ike_sa_t *ike_sa, auth_method_t auth_method)
|
||||
{
|
||||
switch (auth_method)
|
||||
{
|
||||
case AUTH_RSA:
|
||||
return (authenticator_t*)rsa_authenticator_create(ike_sa);
|
||||
case AUTH_PSK:
|
||||
return (authenticator_t*)psk_authenticator_create(ike_sa);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* @file authenticator.h
|
||||
*
|
||||
* @brief Interface of authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AUTHENTICATOR_H_
|
||||
#define AUTHENTICATOR_H_
|
||||
|
||||
typedef enum auth_method_t auth_method_t;
|
||||
typedef struct authenticator_t authenticator_t;
|
||||
|
||||
#include <types.h>
|
||||
#include <sa/ike_sa.h>
|
||||
#include <encoding/payloads/auth_payload.h>
|
||||
|
||||
/**
|
||||
* Method to use for authentication.
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
enum auth_method_t {
|
||||
/**
|
||||
* Computed as specified in section 2.15 of RFC using
|
||||
* an RSA private key over a PKCS#1 padded hash.
|
||||
*/
|
||||
AUTH_RSA = 1,
|
||||
|
||||
/**
|
||||
* Computed as specified in section 2.15 of RFC using the
|
||||
* shared key associated with the identity in the ID payload
|
||||
* and the negotiated prf function
|
||||
*/
|
||||
AUTH_PSK = 2,
|
||||
|
||||
/**
|
||||
* Computed as specified in section 2.15 of RFC using a
|
||||
* DSS private key over a SHA-1 hash.
|
||||
*/
|
||||
AUTH_DSS = 3,
|
||||
|
||||
/**
|
||||
* EAP authentication. This value is never negotiated and therefore
|
||||
* a value from private use.
|
||||
*/
|
||||
AUTH_EAP = 201,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum names for auth_method_t.
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
extern enum_name_t *auth_method_names;
|
||||
|
||||
/**
|
||||
* @brief Authenticator interface implemented by the various authenticators.
|
||||
*
|
||||
* Currently the following two AUTH methods are supported:
|
||||
* - shared key message integrity code (AUTH_PSK)
|
||||
* - RSA digital signature (AUTH_RSA)
|
||||
*
|
||||
* @b Constructors:
|
||||
* - authenticator_create()
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
struct authenticator_t {
|
||||
|
||||
/**
|
||||
* @brief Verify a received authentication payload.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param ike_sa_init binary representation of received ike_sa_init
|
||||
* @param my_nonce the sent nonce
|
||||
* @param auth_payload authentication payload to verify
|
||||
*
|
||||
* @return
|
||||
* - SUCCESS,
|
||||
* - FAILED if verification failed
|
||||
* - INVALID_ARG if auth_method does not match
|
||||
* - NOT_FOUND if credentials not found
|
||||
*/
|
||||
status_t (*verify) (authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t my_nonce, auth_payload_t *auth_payload);
|
||||
|
||||
/**
|
||||
* @brief Build an authentication payload to send to the other peer.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param ike_sa_init binary representation of sent ike_sa_init
|
||||
* @param other_nonce the received nonce
|
||||
* @param[out] auth_payload the resulting authentication payload
|
||||
*
|
||||
* @return
|
||||
* - SUCCESS,
|
||||
* - NOT_FOUND if the data for AUTH method could not be found
|
||||
*/
|
||||
status_t (*build) (authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t other_nonce, auth_payload_t **auth_payload);
|
||||
|
||||
/**
|
||||
* @brief Destroys a authenticator_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (authenticator_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an authenticator for the specified auth method.
|
||||
*
|
||||
* @param ike_sa associated ike_sa
|
||||
* @param auth_method authentication method to use for build()/verify()
|
||||
*
|
||||
* @return authenticator_t object
|
||||
*
|
||||
* @ingroup sa
|
||||
*/
|
||||
authenticator_t *authenticator_create(ike_sa_t *ike_sa, auth_method_t auth_method);
|
||||
|
||||
#endif /* AUTHENTICATOR_H_ */
|
||||
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* @file authenticator.c
|
||||
*
|
||||
* @brief Implementation of authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* 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 <string.h>
|
||||
|
||||
#include "psk_authenticator.h"
|
||||
|
||||
#include <config/policies/policy.h>
|
||||
#include <daemon.h>
|
||||
|
||||
/**
|
||||
* Key pad for the AUTH method SHARED_KEY_MESSAGE_INTEGRITY_CODE.
|
||||
*/
|
||||
#define IKEV2_KEY_PAD "Key Pad for IKEv2"
|
||||
#define IKEV2_KEY_PAD_LENGTH 17
|
||||
|
||||
|
||||
typedef struct private_psk_authenticator_t private_psk_authenticator_t;
|
||||
|
||||
/**
|
||||
* Private data of an psk_authenticator_t object.
|
||||
*/
|
||||
struct private_psk_authenticator_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
psk_authenticator_t public;
|
||||
|
||||
/**
|
||||
* Assigned IKE_SA
|
||||
*/
|
||||
ike_sa_t *ike_sa;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function implemented in rsa_authenticator.c
|
||||
*/
|
||||
extern chunk_t build_tbs_octets(private_psk_authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t nonce, identification_t *id, prf_t *prf);
|
||||
|
||||
/**
|
||||
* Creates the AUTH data using auth method SHARED_KEY_MESSAGE_INTEGRITY_CODE.
|
||||
*/
|
||||
static chunk_t build_shared_key_signature(private_psk_authenticator_t *this,
|
||||
chunk_t ike_sa_init,
|
||||
chunk_t nonce,
|
||||
chunk_t secret,
|
||||
identification_t *id,
|
||||
prf_t *prf)
|
||||
{
|
||||
chunk_t key_pad, key, auth_data, octets;
|
||||
|
||||
octets = build_tbs_octets(this, ike_sa_init, nonce, id, prf);
|
||||
/* AUTH = prf(prf(Shared Secret,"Key Pad for IKEv2"), <msg octets>) */
|
||||
key_pad.ptr = IKEV2_KEY_PAD;
|
||||
key_pad.len = IKEV2_KEY_PAD_LENGTH;
|
||||
prf->set_key(prf, secret);
|
||||
prf->allocate_bytes(prf, key_pad, &key);
|
||||
prf->set_key(prf, key);
|
||||
prf->allocate_bytes(prf, octets, &auth_data);
|
||||
DBG3(DBG_IKE, "octets = message + nonce + prf(Sk_px, IDx') %B", &octets);
|
||||
DBG3(DBG_IKE, "secret %B", &secret);
|
||||
DBG3(DBG_IKE, "keypad %B", &key_pad);
|
||||
DBG3(DBG_IKE, "prf(secret, keypad) %B", &key);
|
||||
DBG3(DBG_IKE, "AUTH = prf(prf(secret, keypad), octets) %B", &auth_data);
|
||||
chunk_free(&octets);
|
||||
chunk_free(&key);
|
||||
|
||||
return auth_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.verify.
|
||||
*/
|
||||
static status_t verify(private_psk_authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t my_nonce, auth_payload_t *auth_payload)
|
||||
{
|
||||
status_t status;
|
||||
chunk_t auth_data, recv_auth_data, shared_key;
|
||||
identification_t *my_id, *other_id;
|
||||
|
||||
my_id = this->ike_sa->get_my_id(this->ike_sa);
|
||||
other_id = this->ike_sa->get_other_id(this->ike_sa);
|
||||
status = charon->credentials->get_shared_key(charon->credentials, my_id,
|
||||
other_id, &shared_key);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "no shared key found for '%D' - '%D'", my_id, other_id);
|
||||
return status;
|
||||
}
|
||||
|
||||
auth_data = build_shared_key_signature(this, ike_sa_init, my_nonce,
|
||||
shared_key, other_id,
|
||||
this->ike_sa->get_auth_verify(this->ike_sa));
|
||||
chunk_free(&shared_key);
|
||||
|
||||
recv_auth_data = auth_payload->get_data(auth_payload);
|
||||
if (auth_data.len != recv_auth_data.len ||
|
||||
!memeq(auth_data.ptr, recv_auth_data.ptr, auth_data.len))
|
||||
{
|
||||
DBG1(DBG_IKE, "PSK MAC verification failed");
|
||||
chunk_free(&auth_data);
|
||||
return FAILED;
|
||||
}
|
||||
chunk_free(&auth_data);
|
||||
|
||||
DBG1(DBG_IKE, "authentication of '%D' with %N successful",
|
||||
other_id, auth_method_names, AUTH_PSK);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.build.
|
||||
*/
|
||||
static status_t build(private_psk_authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t other_nonce, auth_payload_t **auth_payload)
|
||||
{
|
||||
chunk_t shared_key;
|
||||
chunk_t auth_data;
|
||||
status_t status;
|
||||
identification_t *my_id, *other_id;
|
||||
|
||||
my_id = this->ike_sa->get_my_id(this->ike_sa);
|
||||
other_id = this->ike_sa->get_other_id(this->ike_sa);
|
||||
DBG1(DBG_IKE, "authentication of '%D' (myself) with %N",
|
||||
my_id, auth_method_names, AUTH_PSK);
|
||||
status = charon->credentials->get_shared_key(charon->credentials, my_id,
|
||||
other_id, &shared_key);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "no shared key found for '%D' - '%D'", my_id, other_id);
|
||||
return status;
|
||||
}
|
||||
|
||||
auth_data = build_shared_key_signature(this, ike_sa_init,
|
||||
other_nonce, shared_key, my_id,
|
||||
this->ike_sa->get_auth_build(this->ike_sa));
|
||||
DBG2(DBG_IKE, "successfully created shared key MAC");
|
||||
chunk_free(&shared_key);
|
||||
*auth_payload = auth_payload_create();
|
||||
(*auth_payload)->set_auth_method(*auth_payload, AUTH_PSK);
|
||||
(*auth_payload)->set_data(*auth_payload, auth_data);
|
||||
|
||||
chunk_free(&auth_data);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.destroy.
|
||||
*/
|
||||
static void destroy(private_psk_authenticator_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
psk_authenticator_t *psk_authenticator_create(ike_sa_t *ike_sa)
|
||||
{
|
||||
private_psk_authenticator_t *this = malloc_thing(private_psk_authenticator_t);
|
||||
|
||||
/* public functions */
|
||||
this->public.authenticator_interface.verify = (status_t(*)(authenticator_t*,chunk_t,chunk_t,auth_payload_t*))verify;
|
||||
this->public.authenticator_interface.build = (status_t(*)(authenticator_t*,chunk_t,chunk_t,auth_payload_t**))build;
|
||||
this->public.authenticator_interface.destroy = (void(*)(authenticator_t*))destroy;
|
||||
|
||||
/* private data */
|
||||
this->ike_sa = ike_sa;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @file psk_authenticator.h
|
||||
*
|
||||
* @brief Interface of psk_authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef PSK_AUTHENTICATOR_H_
|
||||
#define PSK_AUTHENTICATOR_H_
|
||||
|
||||
typedef struct psk_authenticator_t psk_authenticator_t;
|
||||
|
||||
#include <sa/authenticators/authenticator.h>
|
||||
|
||||
/**
|
||||
* @brief Implementation of the authenticator_t interface using AUTH_PSK.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - psk_authenticator_create()
|
||||
* - authenticator_create() using auth_method AUTH_PSK
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
struct psk_authenticator_t {
|
||||
|
||||
/**
|
||||
* Implemented authenticator_t interface.
|
||||
*/
|
||||
authenticator_t authenticator_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an authenticator for AUTH_PSK.
|
||||
*
|
||||
* @param ike_sa associated ike_sa
|
||||
* @return psk_authenticator_t object
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
psk_authenticator_t *psk_authenticator_create(ike_sa_t *ike_sa);
|
||||
|
||||
#endif /* PSK_AUTHENTICATOR_H_ */
|
||||
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* @file authenticator.c
|
||||
*
|
||||
* @brief Implementation of authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* 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 <string.h>
|
||||
|
||||
#include "rsa_authenticator.h"
|
||||
|
||||
#include <config/policies/policy.h>
|
||||
#include <daemon.h>
|
||||
|
||||
|
||||
typedef struct private_rsa_authenticator_t private_rsa_authenticator_t;
|
||||
|
||||
/**
|
||||
* Private data of an rsa_authenticator_t object.
|
||||
*/
|
||||
struct private_rsa_authenticator_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
rsa_authenticator_t public;
|
||||
|
||||
/**
|
||||
* Assigned IKE_SA
|
||||
*/
|
||||
ike_sa_t *ike_sa;
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds the octets to be signed as described in section 2.15 of RFC 4306
|
||||
*/
|
||||
chunk_t build_tbs_octets(private_rsa_authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t nonce, identification_t *id, prf_t *prf)
|
||||
{
|
||||
u_int8_t id_header_buf[] = {0x00, 0x00, 0x00, 0x00};
|
||||
chunk_t id_header = chunk_from_buf(id_header_buf);
|
||||
chunk_t id_with_header, id_prfd, id_encoding;
|
||||
|
||||
id_header_buf[0] = id->get_type(id);
|
||||
id_encoding = id->get_encoding(id);
|
||||
|
||||
id_with_header = chunk_cat("cc", id_header, id_encoding);
|
||||
prf->allocate_bytes(prf, id_with_header, &id_prfd);
|
||||
chunk_free(&id_with_header);
|
||||
|
||||
return chunk_cat("ccm", ike_sa_init, nonce, id_prfd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.verify.
|
||||
*/
|
||||
static status_t verify(private_rsa_authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t my_nonce, auth_payload_t *auth_payload)
|
||||
{
|
||||
status_t status;
|
||||
chunk_t auth_data, octets;
|
||||
rsa_public_key_t *public_key;
|
||||
identification_t *other_id;
|
||||
|
||||
other_id = this->ike_sa->get_other_id(this->ike_sa);
|
||||
|
||||
if (auth_payload->get_auth_method(auth_payload) != AUTH_RSA)
|
||||
{
|
||||
return INVALID_ARG;
|
||||
}
|
||||
auth_data = auth_payload->get_data(auth_payload);
|
||||
public_key = charon->credentials->get_trusted_public_key(charon->credentials,
|
||||
other_id);
|
||||
if (public_key == NULL)
|
||||
{
|
||||
DBG1(DBG_IKE, "no RSA public key found for '%D'", other_id);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
octets = build_tbs_octets(this, ike_sa_init, my_nonce, other_id,
|
||||
this->ike_sa->get_auth_verify(this->ike_sa));
|
||||
status = public_key->verify_emsa_pkcs1_signature(public_key, octets, auth_data);
|
||||
chunk_free(&octets);
|
||||
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "RSA signature verification failed");
|
||||
return status;
|
||||
}
|
||||
|
||||
DBG1(DBG_IKE, "authentication of '%D' with %N successful",
|
||||
other_id, auth_method_names, AUTH_RSA);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.build.
|
||||
*/
|
||||
static status_t build(private_rsa_authenticator_t *this, chunk_t ike_sa_init,
|
||||
chunk_t other_nonce, auth_payload_t **auth_payload)
|
||||
{
|
||||
chunk_t chunk;
|
||||
chunk_t octets;
|
||||
chunk_t auth_data;
|
||||
status_t status;
|
||||
rsa_public_key_t *my_pubkey;
|
||||
rsa_private_key_t *my_key;
|
||||
identification_t *my_id;
|
||||
|
||||
my_id = this->ike_sa->get_my_id(this->ike_sa);
|
||||
DBG1(DBG_IKE, "authentication of '%D' with %N (myself)",
|
||||
my_id, auth_method_names, AUTH_RSA);
|
||||
DBG2(DBG_IKE, "looking for RSA public key belonging to '%D'", my_id);
|
||||
|
||||
my_pubkey = charon->credentials->get_rsa_public_key(charon->credentials, my_id);
|
||||
if (my_pubkey == NULL)
|
||||
{
|
||||
DBG1(DBG_IKE, "no RSA public key found for '%D'", my_id);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
DBG2(DBG_IKE, "matching RSA public key found");
|
||||
chunk = my_pubkey->get_keyid(my_pubkey);
|
||||
DBG2(DBG_IKE, "looking for RSA private key with keyid %#B", &chunk);
|
||||
my_key = charon->credentials->get_rsa_private_key(charon->credentials, my_pubkey);
|
||||
if (my_key == NULL)
|
||||
{
|
||||
DBG1(DBG_IKE, "no RSA private key found with for %D with keyid %#B",
|
||||
my_id, &chunk);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
DBG2(DBG_IKE, "matching RSA private key found");
|
||||
|
||||
octets = build_tbs_octets(this, ike_sa_init, other_nonce, my_id,
|
||||
this->ike_sa->get_auth_build(this->ike_sa));
|
||||
status = my_key->build_emsa_pkcs1_signature(my_key, HASH_SHA1, octets, &auth_data);
|
||||
chunk_free(&octets);
|
||||
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
my_key->destroy(my_key);
|
||||
DBG1(DBG_IKE, "build signature of SHA1 hash failed");
|
||||
return status;
|
||||
}
|
||||
DBG2(DBG_IKE, "successfully signed with RSA private key");
|
||||
|
||||
*auth_payload = auth_payload_create();
|
||||
(*auth_payload)->set_auth_method(*auth_payload, AUTH_RSA);
|
||||
(*auth_payload)->set_data(*auth_payload, auth_data);
|
||||
|
||||
my_key->destroy(my_key);
|
||||
chunk_free(&auth_data);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of authenticator_t.destroy.
|
||||
*/
|
||||
static void destroy(private_rsa_authenticator_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
rsa_authenticator_t *rsa_authenticator_create(ike_sa_t *ike_sa)
|
||||
{
|
||||
private_rsa_authenticator_t *this = malloc_thing(private_rsa_authenticator_t);
|
||||
|
||||
/* public functions */
|
||||
this->public.authenticator_interface.verify = (status_t(*)(authenticator_t*,chunk_t,chunk_t,auth_payload_t*))verify;
|
||||
this->public.authenticator_interface.build = (status_t(*)(authenticator_t*,chunk_t,chunk_t,auth_payload_t**))build;
|
||||
this->public.authenticator_interface.destroy = (void(*)(authenticator_t*))destroy;
|
||||
|
||||
/* private data */
|
||||
this->ike_sa = ike_sa;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @file rsa_authenticator.h
|
||||
*
|
||||
* @brief Interface of rsa_authenticator_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef RSA_AUTHENTICATOR_H_
|
||||
#define RSA_AUTHENTICATOR_H_
|
||||
|
||||
typedef struct rsa_authenticator_t rsa_authenticator_t;
|
||||
|
||||
#include <sa/authenticators/authenticator.h>
|
||||
|
||||
/**
|
||||
* @brief Implementation of the authenticator_t interface using AUTH_RSA.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - rsa_authenticator_create()
|
||||
* - authenticator_create() using auth_method AUTH_RSA
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
struct rsa_authenticator_t {
|
||||
|
||||
/**
|
||||
* Implemented authenticator_t interface.
|
||||
*/
|
||||
authenticator_t authenticator_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an authenticator for AUTH_RSA.
|
||||
*
|
||||
* @param ike_sa associated ike_sa
|
||||
* @return rsa_authenticator_t object
|
||||
*
|
||||
* @ingroup authenticator
|
||||
*/
|
||||
rsa_authenticator_t *rsa_authenticator_create(ike_sa_t *ike_sa);
|
||||
|
||||
#endif /* RSA_AUTHENTICATOR_H_ */
|
||||
@@ -151,7 +151,7 @@ struct private_child_sa_t {
|
||||
/**
|
||||
* transaction which is rekeying this CHILD_SA
|
||||
*/
|
||||
void *rekeying_transaction;
|
||||
transaction_t *rekeying_transaction;
|
||||
|
||||
/**
|
||||
* Updown script
|
||||
@@ -696,7 +696,7 @@ static linked_list_t *get_other_traffic_selectors(private_child_sa_t *this)
|
||||
/**
|
||||
* Implementation of child_sa_t.set_rekeying_transaction.
|
||||
*/
|
||||
static void set_rekeying_transaction(private_child_sa_t *this, void *transaction)
|
||||
static void set_rekeying_transaction(private_child_sa_t *this, transaction_t *transaction)
|
||||
{
|
||||
this->rekeying_transaction = transaction;
|
||||
}
|
||||
@@ -704,7 +704,7 @@ static void set_rekeying_transaction(private_child_sa_t *this, void *transaction
|
||||
/**
|
||||
* Implementation of child_sa_t.get_rekeying_transaction.
|
||||
*/
|
||||
static void* get_rekeying_transaction(private_child_sa_t *this)
|
||||
static transaction_t* get_rekeying_transaction(private_child_sa_t *this)
|
||||
{
|
||||
return this->rekeying_transaction;
|
||||
}
|
||||
@@ -1104,8 +1104,8 @@ child_sa_t * child_sa_create(u_int32_t rekey, host_t *me, host_t* other,
|
||||
this->public.get_my_traffic_selectors = (linked_list_t*(*)(child_sa_t*))get_my_traffic_selectors;
|
||||
this->public.get_other_traffic_selectors = (linked_list_t*(*)(child_sa_t*))get_other_traffic_selectors;
|
||||
this->public.get_use_time = (status_t (*)(child_sa_t*,bool,time_t*))get_use_time;
|
||||
this->public.set_rekeying_transaction = (void (*)(child_sa_t*,void*))set_rekeying_transaction;
|
||||
this->public.get_rekeying_transaction = (void* (*)(child_sa_t*))get_rekeying_transaction;
|
||||
this->public.set_rekeying_transaction = (void (*)(child_sa_t*,transaction_t*))set_rekeying_transaction;
|
||||
this->public.get_rekeying_transaction = (transaction_t* (*)(child_sa_t*))get_rekeying_transaction;
|
||||
this->public.set_state = (void(*)(child_sa_t*,child_sa_state_t))set_state;
|
||||
this->public.get_state = (child_sa_state_t(*)(child_sa_t*))get_state;
|
||||
this->public.destroy = (void(*)(child_sa_t*))destroy;
|
||||
|
||||
@@ -25,10 +25,14 @@
|
||||
#ifndef CHILD_SA_H_
|
||||
#define CHILD_SA_H_
|
||||
|
||||
typedef enum child_sa_state_t child_sa_state_t;
|
||||
typedef struct child_sa_t child_sa_t;
|
||||
|
||||
#include <types.h>
|
||||
#include <crypto/prf_plus.h>
|
||||
#include <encoding/payloads/proposal_substructure.h>
|
||||
#include <config/proposal.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
/**
|
||||
* Where we should start with reqid enumeration
|
||||
@@ -40,8 +44,6 @@
|
||||
*/
|
||||
#define CHILD_SA_PRINTF_SPEC 'P'
|
||||
|
||||
typedef enum child_sa_state_t child_sa_state_t;
|
||||
|
||||
/**
|
||||
* @brief States of a CHILD_SA
|
||||
*/
|
||||
@@ -78,8 +80,6 @@ enum child_sa_state_t {
|
||||
*/
|
||||
extern enum_name_t *child_sa_state_names;
|
||||
|
||||
typedef struct child_sa_t child_sa_t;
|
||||
|
||||
/**
|
||||
* @brief Represents an IPsec SAs between two hosts.
|
||||
*
|
||||
@@ -266,22 +266,17 @@ struct child_sa_t {
|
||||
* such situations to handle them cleanly. A rekeying transaction
|
||||
* registers itself to the CHILD_SA, and checks later if another
|
||||
* transaction is in progress of a rekey.
|
||||
*
|
||||
* @todo Fix include problematics to allow inclusion of
|
||||
* the create_child_sa_t transaction.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*set_rekeying_transaction) (child_sa_t *this, void *transaction);
|
||||
void (*set_rekeying_transaction) (child_sa_t *this, transaction_t *transaction);
|
||||
|
||||
/**
|
||||
* @brief Get the transaction which rekeys this CHILD_SA.
|
||||
*
|
||||
* @see set_rekeying_transactoin().
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void* (*get_rekeying_transaction) (child_sa_t *this);
|
||||
transaction_t* (*get_rekeying_transaction) (child_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Destroys a child_sa.
|
||||
|
||||
+38
-26
@@ -149,14 +149,14 @@ struct private_ike_sa_t {
|
||||
prf_t *child_prf;
|
||||
|
||||
/**
|
||||
* PRF, with key set to pi_key, used for authentication
|
||||
* PRF to build outging authentication data
|
||||
*/
|
||||
prf_t *prf_auth_i;
|
||||
prf_t *auth_build;
|
||||
|
||||
/**
|
||||
* PRF, with key set to pr_key, used for authentication
|
||||
* PRF to verify incoming authentication data
|
||||
*/
|
||||
prf_t *prf_auth_r;
|
||||
prf_t *auth_verify;
|
||||
|
||||
/**
|
||||
* NAT hasher.
|
||||
@@ -231,7 +231,7 @@ struct private_ike_sa_t {
|
||||
/**
|
||||
* Transaction which rekeys this IKE_SA, used do detect simultaneus rekeying
|
||||
*/
|
||||
rekey_ike_sa_t *rekeying_transaction;
|
||||
transaction_t *rekeying_transaction;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1357,19 +1357,19 @@ static prf_t *get_child_prf(private_ike_sa_t *this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_t.get_prf_auth_i.
|
||||
* Implementation of ike_sa_t.get_auth_bild
|
||||
*/
|
||||
static prf_t *get_prf_auth_i(private_ike_sa_t *this)
|
||||
static prf_t *get_auth_build(private_ike_sa_t *this)
|
||||
{
|
||||
return this->prf_auth_i;
|
||||
return this->auth_build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_t.get_prf_auth_r.
|
||||
* Implementation of ike_sa_t.get_auth_verify
|
||||
*/
|
||||
static prf_t *get_prf_auth_r(private_ike_sa_t *this)
|
||||
static prf_t *get_auth_verify(private_ike_sa_t *this)
|
||||
{
|
||||
return this->prf_auth_r;
|
||||
return this->auth_verify;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1428,6 +1428,7 @@ static status_t derive_keys(private_ike_sa_t *this,
|
||||
size_t key_size;
|
||||
crypter_t *crypter_i, *crypter_r;
|
||||
signer_t *signer_i, *signer_r;
|
||||
prf_t *prf_i, *prf_r;
|
||||
u_int8_t spi_i_buf[sizeof(u_int64_t)], spi_r_buf[sizeof(u_int64_t)];
|
||||
chunk_t spi_i = chunk_from_buf(spi_i_buf);
|
||||
chunk_t spi_r = chunk_from_buf(spi_r_buf);
|
||||
@@ -1571,20 +1572,31 @@ static status_t derive_keys(private_ike_sa_t *this,
|
||||
|
||||
/* SK_pi/SK_pr used for authentication => prf_auth_i, prf_auth_r */
|
||||
proposal->get_algorithm(proposal, PSEUDO_RANDOM_FUNCTION, &algo);
|
||||
this->prf_auth_i = prf_create(algo->algorithm);
|
||||
this->prf_auth_r = prf_create(algo->algorithm);
|
||||
prf_i = prf_create(algo->algorithm);
|
||||
prf_r = prf_create(algo->algorithm);
|
||||
|
||||
key_size = this->prf_auth_i->get_key_size(this->prf_auth_i);
|
||||
key_size = prf_i->get_key_size(prf_i);
|
||||
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
||||
DBG4(DBG_IKE, "Sk_pi secret %B", &key);
|
||||
this->prf_auth_i->set_key(this->prf_auth_i, key);
|
||||
prf_i->set_key(prf_i, key);
|
||||
chunk_free(&key);
|
||||
|
||||
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
||||
DBG4(DBG_IKE, "Sk_pr secret %B", &key);
|
||||
this->prf_auth_r->set_key(this->prf_auth_r, key);
|
||||
prf_r->set_key(prf_r, key);
|
||||
chunk_free(&key);
|
||||
|
||||
if (initiator)
|
||||
{
|
||||
this->auth_verify = prf_r;
|
||||
this->auth_build = prf_i;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->auth_verify = prf_i;
|
||||
this->auth_build = prf_r;
|
||||
}
|
||||
|
||||
/* all done, prf_plus not needed anymore */
|
||||
prf_plus->destroy(prf_plus);
|
||||
|
||||
@@ -1764,7 +1776,7 @@ static status_t rekey(private_ike_sa_t *this)
|
||||
/**
|
||||
* Implementation of ike_sa_t.get_rekeying_transaction.
|
||||
*/
|
||||
static rekey_ike_sa_t* get_rekeying_transaction(private_ike_sa_t *this)
|
||||
static transaction_t* get_rekeying_transaction(private_ike_sa_t *this)
|
||||
{
|
||||
return this->rekeying_transaction;
|
||||
}
|
||||
@@ -1772,7 +1784,7 @@ static rekey_ike_sa_t* get_rekeying_transaction(private_ike_sa_t *this)
|
||||
/**
|
||||
* Implementation of ike_sa_t.set_rekeying_transaction.
|
||||
*/
|
||||
static void set_rekeying_transaction(private_ike_sa_t *this, rekey_ike_sa_t *rekey)
|
||||
static void set_rekeying_transaction(private_ike_sa_t *this, transaction_t *rekey)
|
||||
{
|
||||
this->rekeying_transaction = rekey;
|
||||
}
|
||||
@@ -1920,8 +1932,8 @@ static void destroy(private_ike_sa_t *this)
|
||||
DESTROY_IF(this->signer_out);
|
||||
DESTROY_IF(this->prf);
|
||||
DESTROY_IF(this->child_prf);
|
||||
DESTROY_IF(this->prf_auth_i);
|
||||
DESTROY_IF(this->prf_auth_r);
|
||||
DESTROY_IF(this->auth_verify);
|
||||
DESTROY_IF(this->auth_build);
|
||||
|
||||
DESTROY_IF(this->my_host);
|
||||
DESTROY_IF(this->other_host);
|
||||
@@ -1967,8 +1979,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
||||
this->public.send_keepalive = (void (*)(ike_sa_t*)) send_keepalive;
|
||||
this->public.get_prf = (prf_t *(*) (ike_sa_t *)) get_prf;
|
||||
this->public.get_child_prf = (prf_t *(*) (ike_sa_t *)) get_child_prf;
|
||||
this->public.get_prf_auth_i = (prf_t *(*) (ike_sa_t *)) get_prf_auth_i;
|
||||
this->public.get_prf_auth_r = (prf_t *(*) (ike_sa_t *)) get_prf_auth_r;
|
||||
this->public.get_auth_verify = (prf_t *(*) (ike_sa_t *)) get_auth_verify;
|
||||
this->public.get_auth_build = (prf_t *(*) (ike_sa_t *)) get_auth_build;
|
||||
this->public.derive_keys = (status_t (*) (ike_sa_t *,proposal_t*,diffie_hellman_t*,chunk_t,chunk_t,bool,prf_t*,prf_t*)) derive_keys;
|
||||
this->public.add_child_sa = (void (*) (ike_sa_t*,child_sa_t*)) add_child_sa;
|
||||
this->public.has_child_sa = (bool(*)(ike_sa_t*,u_int32_t)) has_child_sa;
|
||||
@@ -1982,8 +1994,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
||||
this->public.set_lifetimes = (void(*)(ike_sa_t*,u_int32_t,u_int32_t))set_lifetimes;
|
||||
this->public.apply_connection = (void(*)(ike_sa_t*,connection_t*))apply_connection;
|
||||
this->public.rekey = (status_t(*)(ike_sa_t*))rekey;
|
||||
this->public.get_rekeying_transaction = (void*(*)(ike_sa_t*))get_rekeying_transaction;
|
||||
this->public.set_rekeying_transaction = (void(*)(ike_sa_t*,void*))set_rekeying_transaction;
|
||||
this->public.get_rekeying_transaction = (transaction_t*(*)(ike_sa_t*))get_rekeying_transaction;
|
||||
this->public.set_rekeying_transaction = (void(*)(ike_sa_t*,transaction_t*))set_rekeying_transaction;
|
||||
this->public.adopt_children = (void(*)(ike_sa_t*,ike_sa_t*))adopt_children;
|
||||
|
||||
/* initialize private fields */
|
||||
@@ -1999,8 +2011,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
||||
this->signer_in = NULL;
|
||||
this->signer_out = NULL;
|
||||
this->prf = NULL;
|
||||
this->prf_auth_i = NULL;
|
||||
this->prf_auth_r = NULL;
|
||||
this->auth_verify = NULL;
|
||||
this->auth_build = NULL;
|
||||
this->child_prf = NULL;
|
||||
this->nat_here = FALSE;
|
||||
this->nat_there = FALSE;
|
||||
|
||||
+10
-14
@@ -25,11 +25,15 @@
|
||||
#ifndef IKE_SA_H_
|
||||
#define IKE_SA_H_
|
||||
|
||||
typedef enum ike_sa_state_t ike_sa_state_t;
|
||||
typedef struct ike_sa_t ike_sa_t;
|
||||
|
||||
#include <types.h>
|
||||
#include <encoding/message.h>
|
||||
#include <encoding/payloads/proposal_substructure.h>
|
||||
#include <sa/ike_sa_id.h>
|
||||
#include <sa/child_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
#include <config/configuration.h>
|
||||
#include <utils/randomizer.h>
|
||||
#include <crypto/prfs/prf.h>
|
||||
@@ -39,11 +43,8 @@
|
||||
#include <config/policies/policy.h>
|
||||
#include <config/proposal.h>
|
||||
|
||||
|
||||
#define IKE_SA_PRINTF_SPEC 'K'
|
||||
|
||||
typedef enum ike_sa_state_t ike_sa_state_t;
|
||||
|
||||
/**
|
||||
* @brief State of an IKE_SA.
|
||||
*
|
||||
@@ -116,9 +117,6 @@ enum ike_sa_state_t {
|
||||
*/
|
||||
extern enum_name_t *ike_sa_state_names;
|
||||
|
||||
|
||||
typedef struct ike_sa_t ike_sa_t;
|
||||
|
||||
/**
|
||||
* @brief Class ike_sa_t representing an IKE_SA.
|
||||
*
|
||||
@@ -444,20 +442,20 @@ struct ike_sa_t {
|
||||
prf_t *(*get_child_prf) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get the prf used for authentication of initiator.
|
||||
* @brief Get the prf to build outgoing authentication data.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return pointer to prf_t object
|
||||
*/
|
||||
prf_t *(*get_prf_auth_i) (ike_sa_t *this);
|
||||
prf_t *(*get_auth_build) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get the prf used for authentication of responder.
|
||||
* @brief Get the prf to verify incoming authentication data.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return pointer to prf_t object
|
||||
*/
|
||||
prf_t *(*get_prf_auth_r) (ike_sa_t *this);
|
||||
prf_t *(*get_auth_verify) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Associates a child SA to this IKE SA
|
||||
@@ -567,13 +565,11 @@ struct ike_sa_t {
|
||||
|
||||
/**
|
||||
* @brief Get the transaction which rekeys this IKE_SA.
|
||||
*
|
||||
* @todo Fix include for rekey_ike_sa.h
|
||||
*
|
||||
* @param this calling object
|
||||
* @return rekey_ike_sa_t transaction or NULL
|
||||
*/
|
||||
void* (*get_rekeying_transaction) (ike_sa_t *this);
|
||||
transaction_t* (*get_rekeying_transaction) (ike_sa_t *this);
|
||||
|
||||
/**
|
||||
* @brief Set the transaction which rekeys this IKE_SA.
|
||||
@@ -581,7 +577,7 @@ struct ike_sa_t {
|
||||
* @param this calling object
|
||||
* @param rekey rekey_ike_sa_t transaction or NULL
|
||||
*/
|
||||
void (*set_rekeying_transaction) (ike_sa_t *this, void *rekey);
|
||||
void (*set_rekeying_transaction) (ike_sa_t *this, transaction_t *rekey);
|
||||
|
||||
/**
|
||||
* @brief Move all children from other IKE_SA to this IKE_SA.
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#ifndef IKE_SA_ID_H_
|
||||
#define IKE_SA_ID_H_
|
||||
|
||||
typedef struct ike_sa_id_t ike_sa_id_t;
|
||||
|
||||
#include <types.h>
|
||||
|
||||
/**
|
||||
@@ -32,8 +34,6 @@
|
||||
*/
|
||||
#define IKE_SA_ID_PRINTF_SPEC 'J'
|
||||
|
||||
typedef struct ike_sa_id_t ike_sa_id_t;
|
||||
|
||||
/**
|
||||
* @brief An object of type ike_sa_id_t is used to identify an IKE_SA.
|
||||
*
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
#ifndef IKE_SA_MANAGER_H_
|
||||
#define IKE_SA_MANAGER_H_
|
||||
|
||||
typedef struct ike_sa_manager_t ike_sa_manager_t;
|
||||
|
||||
#include <types.h>
|
||||
#include <sa/ike_sa.h>
|
||||
|
||||
typedef struct ike_sa_manager_t ike_sa_manager_t;
|
||||
|
||||
/**
|
||||
* @brief The IKE_SA-Manager is responsible for managing all initiated and responded IKE_SA's.
|
||||
*
|
||||
|
||||
@@ -337,7 +337,8 @@ static status_t get_request(private_create_child_sa_t *this, message_t **result)
|
||||
request->add_payload(request, (payload_t*)notify);
|
||||
|
||||
/* register us as rekeying to detect multiple rekeying */
|
||||
this->rekeyed_sa->set_rekeying_transaction(this->rekeyed_sa, &this->public);
|
||||
this->rekeyed_sa->set_rekeying_transaction(this->rekeyed_sa,
|
||||
&this->public.transaction);
|
||||
}
|
||||
|
||||
this->message_id = this->ike_sa->get_next_message_id(this->ike_sa);
|
||||
@@ -718,7 +719,8 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
|
||||
{
|
||||
private_create_child_sa_t *other;
|
||||
|
||||
other = this->rekeyed_sa->get_rekeying_transaction(this->rekeyed_sa);
|
||||
other = (private_create_child_sa_t*)
|
||||
this->rekeyed_sa->get_rekeying_transaction(this->rekeyed_sa);
|
||||
if (other)
|
||||
{
|
||||
/* store our lower nonce in the simultaneus transaction, it
|
||||
|
||||
@@ -23,12 +23,11 @@
|
||||
#ifndef CREATE_CHILD_SA_H_
|
||||
#define CREATE_CHILD_SA_H_
|
||||
|
||||
typedef struct create_child_sa_t create_child_sa_t;
|
||||
|
||||
#include <sa/transactions/transaction.h>
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/child_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
|
||||
typedef struct create_child_sa_t create_child_sa_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction to create a new or rekey an existing CHILD_SA.
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
#ifndef DEAD_PEER_DETECTION_H_
|
||||
#define DEAD_PEER_DETECTION_H_
|
||||
|
||||
typedef struct dead_peer_detection_t dead_peer_detection_t;
|
||||
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
|
||||
typedef struct dead_peer_detection_t dead_peer_detection_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction used to detect dead peers.
|
||||
*
|
||||
|
||||
@@ -180,7 +180,7 @@ static status_t process_delete(private_delete_child_sa_t *this, delete_payload_t
|
||||
DBG1(DBG_IKE, "received DELETE for %N CHILD_SA with SPI 0x%x, deleting",
|
||||
protocol_id_names, protocol, ntohl(spi));
|
||||
|
||||
rekey = child_sa->get_rekeying_transaction(child_sa);
|
||||
rekey = (create_child_sa_t*)child_sa->get_rekeying_transaction(child_sa);
|
||||
if (rekey)
|
||||
{
|
||||
/* we have received a delete for an SA which we are still rekeying.
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
#ifndef DELETE_CHILD_SA_H_
|
||||
#define DELETE_CHILD_SA_H_
|
||||
|
||||
typedef struct delete_child_sa_t delete_child_sa_t;
|
||||
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
|
||||
typedef struct delete_child_sa_t delete_child_sa_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction used to delete a CHILD_SA.
|
||||
*
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
#ifndef DELETE_IKE_SA_H_
|
||||
#define DELETE_IKE_SA_H_
|
||||
|
||||
typedef struct delete_ike_sa_t delete_ike_sa_t;
|
||||
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
|
||||
typedef struct delete_ike_sa_t delete_ike_sa_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction used to delete the IKE_SA.
|
||||
*
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <encoding/payloads/certreq_payload.h>
|
||||
#include <encoding/payloads/auth_payload.h>
|
||||
#include <encoding/payloads/ts_payload.h>
|
||||
#include <sa/authenticator.h>
|
||||
#include <sa/authenticators/authenticator.h>
|
||||
#include <sa/child_sa.h>
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ static status_t get_request(private_ike_auth_t *this, message_t **result)
|
||||
}
|
||||
|
||||
/* build certificate payload. TODO: Handle certreq from init_ike_sa. */
|
||||
if (this->policy->get_auth_method(this->policy) == RSA_DIGITAL_SIGNATURE
|
||||
if (this->policy->get_auth_method(this->policy) == AUTH_RSA
|
||||
&& this->connection->get_cert_policy(this->connection) != CERT_NEVER_SEND)
|
||||
{
|
||||
cert_payload_t *cert_payload;
|
||||
@@ -273,13 +273,15 @@ static status_t get_request(private_ike_auth_t *this, message_t **result)
|
||||
|
||||
auth_method = this->policy->get_auth_method(this->policy);
|
||||
authenticator = authenticator_create(this->ike_sa, auth_method);
|
||||
status = authenticator->compute_auth_data(authenticator,
|
||||
&auth_payload,
|
||||
this->init_request,
|
||||
this->nonce_r,
|
||||
my_id,
|
||||
other_id,
|
||||
TRUE);
|
||||
if (authenticator == NULL)
|
||||
{
|
||||
SIG(IKE_UP_FAILED, "auth method %N not supported, deleting IKE_SA",
|
||||
auth_method_names, auth_method);
|
||||
SIG(CHILD_UP_FAILED, "initiating CHILD_SA failed, unable to create IKE_SA");
|
||||
return DESTROY_ME;
|
||||
}
|
||||
status = authenticator->build(authenticator, this->init_request,
|
||||
this->nonce_r, &auth_payload);
|
||||
authenticator->destroy(authenticator);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
@@ -718,7 +720,7 @@ static status_t get_response(private_ike_auth_t *this, message_t *request,
|
||||
response->add_payload(response, (payload_t*)idr_response);
|
||||
}
|
||||
|
||||
if (this->policy->get_auth_method(this->policy) == RSA_DIGITAL_SIGNATURE
|
||||
if (this->policy->get_auth_method(this->policy) == AUTH_RSA
|
||||
&& this->connection->get_cert_policy(this->connection) != CERT_NEVER_SEND)
|
||||
{ /* build certificate payload */
|
||||
x509_t *cert;
|
||||
@@ -747,28 +749,37 @@ static status_t get_response(private_ike_auth_t *this, message_t *request,
|
||||
auth_method_t auth_method;
|
||||
status_t status;
|
||||
|
||||
auth_method = this->policy->get_auth_method(this->policy);
|
||||
auth_method = auth_request->get_auth_method(auth_request);
|
||||
authenticator = authenticator_create(this->ike_sa, auth_method);
|
||||
status = authenticator->verify_auth_data(authenticator, auth_request,
|
||||
this->init_request,
|
||||
this->nonce_r,
|
||||
my_id,
|
||||
other_id,
|
||||
TRUE);
|
||||
if (authenticator == NULL)
|
||||
{
|
||||
SIG(IKE_UP_FAILED, "auth method %N not supported, deleting IKE_SA",
|
||||
auth_method_names, auth_method);
|
||||
SIG(CHILD_UP_FAILED, "initiating CHILD_SA failed, unable to create IKE_SA");
|
||||
return DESTROY_ME;
|
||||
}
|
||||
status = authenticator->verify(authenticator, this->init_request,
|
||||
this->nonce_r, auth_request);
|
||||
authenticator->destroy(authenticator);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
SIG(IKE_UP_FAILED, "authentication failed, deleting IKE_SA");
|
||||
SIG(CHILD_UP_FAILED, "initiating CHILD_SA failed, unable to create IKE_SA");
|
||||
build_notify(AUTHENTICATION_FAILED, response, TRUE);
|
||||
authenticator->destroy(authenticator);
|
||||
return DESTROY_ME;
|
||||
}
|
||||
status = authenticator->compute_auth_data(authenticator, &auth_response,
|
||||
this->init_response,
|
||||
this->nonce_i,
|
||||
my_id,
|
||||
other_id,
|
||||
FALSE);
|
||||
|
||||
auth_method = this->policy->get_auth_method(this->policy);
|
||||
authenticator = authenticator_create(this->ike_sa, auth_method);
|
||||
if (authenticator == NULL)
|
||||
{
|
||||
SIG(IKE_UP_FAILED, "auth method %N not supported, deleting IKE_SA",
|
||||
auth_method_names, auth_method);
|
||||
SIG(CHILD_UP_FAILED, "initiating CHILD_SA failed, unable to create IKE_SA");
|
||||
return DESTROY_ME;
|
||||
}
|
||||
status = authenticator->build(authenticator, this->init_response,
|
||||
this->nonce_i, &auth_response);
|
||||
authenticator->destroy(authenticator);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
@@ -968,17 +979,18 @@ static status_t conclude(private_ike_auth_t *this, message_t *response,
|
||||
auth_method_t auth_method;
|
||||
status_t status;
|
||||
|
||||
auth_method = this->policy->get_auth_method(this->policy);
|
||||
authenticator = authenticator_create(this->ike_sa, auth_method);
|
||||
my_id = this->policy->get_my_id(this->policy);
|
||||
|
||||
status = authenticator->verify_auth_data(authenticator,
|
||||
auth_payload,
|
||||
this->init_response,
|
||||
this->nonce_i,
|
||||
my_id,
|
||||
other_id,
|
||||
FALSE);
|
||||
auth_method = auth_payload->get_auth_method(auth_payload);
|
||||
authenticator = authenticator_create(this->ike_sa, auth_method);
|
||||
if (authenticator == NULL)
|
||||
{
|
||||
SIG(IKE_UP_FAILED, "auth method %N not supported, deleting IKE_SA",
|
||||
auth_method_names, auth_method);
|
||||
SIG(CHILD_UP_FAILED, "initiating CHILD_SA failed, unable to create IKE_SA");
|
||||
return DESTROY_ME;
|
||||
}
|
||||
status = authenticator->verify(authenticator, this->init_response,
|
||||
this->nonce_i, auth_payload);
|
||||
authenticator->destroy(authenticator);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
#ifndef IKE_AUTH_H_
|
||||
#define IKE_AUTH_H_
|
||||
|
||||
typedef struct ike_auth_t ike_auth_t;
|
||||
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
|
||||
typedef struct ike_auth_t ike_auth_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction for the second message exchange to authenticate an IKE_SA.
|
||||
*
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
#ifndef IKE_SA_INIT_H_
|
||||
#define IKE_SA_INIT_H_
|
||||
|
||||
typedef struct ike_sa_init_t ike_sa_init_t;
|
||||
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
|
||||
|
||||
typedef struct ike_sa_init_t ike_sa_init_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction for the first message exchange to set up an IKE_SA.
|
||||
*
|
||||
|
||||
@@ -270,7 +270,7 @@ static status_t get_request(private_rekey_ike_sa_t *this, message_t **result)
|
||||
|
||||
/* register us as rekeying to detect multiple rekeying */
|
||||
this->ike_sa->set_state(this->ike_sa, IKE_REKEYING);
|
||||
this->ike_sa->set_rekeying_transaction(this->ike_sa, &this->public);
|
||||
this->ike_sa->set_rekeying_transaction(this->ike_sa, &this->public.transaction);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -623,7 +623,8 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
|
||||
{
|
||||
private_rekey_ike_sa_t *other;
|
||||
|
||||
other = this->ike_sa->get_rekeying_transaction(this->ike_sa);
|
||||
other = (private_rekey_ike_sa_t*)
|
||||
this->ike_sa->get_rekeying_transaction(this->ike_sa);
|
||||
if (other)
|
||||
{
|
||||
/* store our lower nonce in the simultaneus transaction, we
|
||||
@@ -641,7 +642,7 @@ static status_t get_response(private_rekey_ike_sa_t *this, message_t *request,
|
||||
other->nonce_s = chunk_clone(this->nonce_r);
|
||||
}
|
||||
/* overwrite "other" in IKE_SA, allows "other" to access "this" */
|
||||
this->ike_sa->set_rekeying_transaction(this->ike_sa, &this->public);
|
||||
this->ike_sa->set_rekeying_transaction(this->ike_sa, &this->public.transaction);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -768,7 +769,8 @@ static status_t conclude(private_rekey_ike_sa_t *this, message_t *response,
|
||||
* of the SA. If it changed, we are not alone. Then we must compare the nonces.
|
||||
* If no simultaneous rekeying is going on, we just initiate the delete of
|
||||
* the superseded SA. */
|
||||
other_trans = this->ike_sa->get_rekeying_transaction(this->ike_sa);
|
||||
other_trans = (private_rekey_ike_sa_t*)
|
||||
this->ike_sa->get_rekeying_transaction(this->ike_sa);
|
||||
this->ike_sa->set_rekeying_transaction(this->ike_sa, NULL);
|
||||
|
||||
if (this->nonce_s.ptr)
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
#ifndef REKEY_IKE_SA_H
|
||||
#define REKEY_IKE_SA_H
|
||||
|
||||
typedef struct rekey_ike_sa_t rekey_ike_sa_t;
|
||||
|
||||
#include <sa/ike_sa.h>
|
||||
#include <sa/transactions/transaction.h>
|
||||
#include <crypto/diffie_hellman.h>
|
||||
|
||||
|
||||
typedef struct rekey_ike_sa_t rekey_ike_sa_t;
|
||||
|
||||
/**
|
||||
* @brief A transaction to rekey an established IKE_SA
|
||||
*
|
||||
|
||||
@@ -23,15 +23,12 @@
|
||||
#ifndef TRANSACTION_H_
|
||||
#define TRANSACTION_H_
|
||||
|
||||
|
||||
typedef struct transaction_t transaction_t;
|
||||
|
||||
#include <types.h>
|
||||
#include <encoding/message.h>
|
||||
#include <sa/ike_sa.h>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief This interface represents a transaction an established IKE_SA can do.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user