2005-11-14 10:14:22 +00:00
|
|
|
/*
|
2010-10-28 12:21:44 +00:00
|
|
|
* Copyright (C) 2005-2010 Martin Willi
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005 Jan Hutter
|
2005-11-14 10:14:22 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2006-04-10 08:07:38 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "proposal_substructure.h"
|
|
|
|
|
2005-11-23 09:57:18 +00:00
|
|
|
#include <encoding/payloads/encodings.h>
|
|
|
|
#include <encoding/payloads/transform_substructure.h>
|
2006-10-31 12:27:59 +00:00
|
|
|
#include <library.h>
|
2005-11-23 09:08:45 +00:00
|
|
|
#include <utils/linked_list.h>
|
2006-10-18 11:46:13 +00:00
|
|
|
#include <daemon.h>
|
2005-11-14 10:14:22 +00:00
|
|
|
|
2005-12-06 13:44:22 +00:00
|
|
|
/**
|
2011-11-16 12:46:54 +00:00
|
|
|
* IKEv2 Value for a proposal payload.
|
2005-12-06 13:44:22 +00:00
|
|
|
*/
|
|
|
|
#define PROPOSAL_TYPE_VALUE 2
|
|
|
|
|
2005-11-24 09:17:51 +00:00
|
|
|
typedef struct private_proposal_substructure_t private_proposal_substructure_t;
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Private data of an proposal_substructure_t object.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2005-11-24 09:17:51 +00:00
|
|
|
struct private_proposal_substructure_t {
|
2010-10-28 12:21:44 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Public proposal_substructure_t interface.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
proposal_substructure_t public;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Next payload type.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
u_int8_t next_payload;
|
|
|
|
|
2010-11-24 15:34:16 +00:00
|
|
|
/**
|
|
|
|
* reserved byte
|
|
|
|
*/
|
|
|
|
u_int8_t reserved;
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Length of this payload.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
u_int16_t proposal_length;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Proposal number.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2006-06-07 13:26:23 +00:00
|
|
|
u_int8_t proposal_number;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Protocol ID.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
u_int8_t protocol_id;
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* SPI size of the following SPI.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2009-09-04 13:02:11 +00:00
|
|
|
u_int8_t spi_size;
|
2005-11-14 10:14:22 +00:00
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Number of transforms.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2009-09-04 13:02:11 +00:00
|
|
|
u_int8_t transforms_count;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-09-04 13:02:11 +00:00
|
|
|
/**
|
|
|
|
* SPI is stored as chunk.
|
|
|
|
*/
|
|
|
|
chunk_t spi;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-09-04 13:02:11 +00:00
|
|
|
/**
|
|
|
|
* Transforms are stored in a linked_list_t.
|
|
|
|
*/
|
2011-11-16 12:46:54 +00:00
|
|
|
linked_list_t *transforms;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of this payload, PROPOSAL_SUBSTRUCTURE or PROPOSAL_SUBSTRUCTURE_V1
|
|
|
|
*/
|
|
|
|
payload_type_t type;
|
2005-11-14 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-11-16 12:46:54 +00:00
|
|
|
* Encoding rules for a IKEv1 Proposal substructure.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2011-11-16 12:46:54 +00:00
|
|
|
static encoding_rule_t encodings_v1[] = {
|
|
|
|
/* 1 Byte next payload type, stored in the field next_payload */
|
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, next_payload) },
|
|
|
|
/* 1 Reserved Byte */
|
|
|
|
{ RESERVED_BYTE, offsetof(private_proposal_substructure_t, reserved) },
|
|
|
|
/* Length of the whole proposal substructure payload*/
|
|
|
|
{ PAYLOAD_LENGTH, offsetof(private_proposal_substructure_t, proposal_length) },
|
|
|
|
/* proposal number is a number of 8 bit */
|
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, proposal_number) },
|
|
|
|
/* protocol ID is a number of 8 bit */
|
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, protocol_id) },
|
|
|
|
/* SPI Size has its own type */
|
|
|
|
{ SPI_SIZE, offsetof(private_proposal_substructure_t, spi_size) },
|
|
|
|
/* Number of transforms is a number of 8 bit */
|
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, transforms_count) },
|
|
|
|
/* SPI is a chunk of variable size*/
|
|
|
|
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
2011-11-17 14:44:42 +00:00
|
|
|
/* Transforms are stored in a transform substructure list */
|
|
|
|
{ PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1,
|
|
|
|
offsetof(private_proposal_substructure_t, transforms) },
|
2011-11-16 12:46:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encoding rules for a IKEv2 Proposal substructure.
|
|
|
|
*/
|
|
|
|
static encoding_rule_t encodings_v2[] = {
|
2009-09-04 13:02:11 +00:00
|
|
|
/* 1 Byte next payload type, stored in the field next_payload */
|
2010-10-28 12:21:44 +00:00
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, next_payload) },
|
2010-11-24 15:34:16 +00:00
|
|
|
/* 1 Reserved Byte */
|
|
|
|
{ RESERVED_BYTE, offsetof(private_proposal_substructure_t, reserved) },
|
2005-11-14 12:04:06 +00:00
|
|
|
/* Length of the whole proposal substructure payload*/
|
2010-10-28 12:21:44 +00:00
|
|
|
{ PAYLOAD_LENGTH, offsetof(private_proposal_substructure_t, proposal_length) },
|
2005-11-14 10:14:22 +00:00
|
|
|
/* proposal number is a number of 8 bit */
|
2010-10-28 12:21:44 +00:00
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, proposal_number) },
|
2005-11-14 10:14:22 +00:00
|
|
|
/* protocol ID is a number of 8 bit */
|
2010-10-28 12:21:44 +00:00
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, protocol_id) },
|
2005-11-14 10:14:22 +00:00
|
|
|
/* SPI Size has its own type */
|
2010-10-28 12:21:44 +00:00
|
|
|
{ SPI_SIZE, offsetof(private_proposal_substructure_t, spi_size) },
|
2005-11-14 10:14:22 +00:00
|
|
|
/* Number of transforms is a number of 8 bit */
|
2010-10-28 12:21:44 +00:00
|
|
|
{ U_INT_8, offsetof(private_proposal_substructure_t, transforms_count) },
|
2005-11-14 10:14:22 +00:00
|
|
|
/* SPI is a chunk of variable size*/
|
2010-10-28 12:21:44 +00:00
|
|
|
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
2011-11-17 14:44:42 +00:00
|
|
|
/* Transforms are stored in a transform substructure list */
|
|
|
|
{ PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE,
|
|
|
|
offsetof(private_proposal_substructure_t, transforms) },
|
2005-11-14 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
2005-11-17 12:49:35 +00:00
|
|
|
/*
|
|
|
|
1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
! 0 (last) or 2 ! RESERVED ! Proposal Length !
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
! Proposal # ! Protocol ID ! SPI Size !# of Transforms!
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
~ SPI (variable) ~
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
! !
|
|
|
|
~ <Transforms> ~
|
|
|
|
! !
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
|
|
|
|
2011-11-16 12:46:54 +00:00
|
|
|
/**
|
|
|
|
* Encryption.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_ENCR_DES_CBC = 1,
|
|
|
|
IKEV1_ENCR_IDEA_CBC = 2,
|
|
|
|
IKEV1_ENCR_BLOWFISH_CBC = 3,
|
|
|
|
IKEV1_ENCR_RC5_R16_B64_CBC = 4,
|
|
|
|
IKEV1_ENCR_3DES_CBC = 5,
|
|
|
|
IKEV1_ENCR_CAST_CBC = 6,
|
|
|
|
IKEV1_ENCR_AES_CBC = 7,
|
|
|
|
IKEV1_ENCR_CAMELLIA_CBC = 8,
|
|
|
|
IKEV1_ENCR_LAST = 9,
|
|
|
|
} ikev1_encryption_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IKEv1 hash.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_HASH_MD5 = 1,
|
|
|
|
IKEV1_HASH_SHA1 = 2,
|
|
|
|
IKEV1_HASH_TIGER = 3,
|
|
|
|
IKEV1_HASH_SHA2_256 = 4,
|
|
|
|
IKEV1_HASH_SHA2_384 = 5,
|
|
|
|
IKEV1_HASH_SHA2_512 = 6,
|
|
|
|
} ikev1_hash_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IKEv1 Transform ID IKE.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_TRANSID_KEY_IKE = 1,
|
|
|
|
} ikev1_ike_transid_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IKEv1 Transform ID ESP.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_TRANSID_ESP_DES_IV64 = 1,
|
|
|
|
IKEV1_TRANSID_ESP_DES = 2,
|
|
|
|
IKEV1_TRANSID_ESP_3DES = 3,
|
|
|
|
IKEV1_TRANSID_ESP_RC5 = 4,
|
|
|
|
IKEV1_TRANSID_ESP_IDEA = 5,
|
|
|
|
IKEV1_TRANSID_ESP_CAST = 6,
|
|
|
|
IKEV1_TRANSID_ESP_BLOWFISH = 7,
|
|
|
|
IKEV1_TRANSID_ESP_3IDEA = 8,
|
|
|
|
IKEV1_TRANSID_ESP_DES_IV32 = 9,
|
|
|
|
IKEV1_TRANSID_ESP_RC4 = 10,
|
|
|
|
IKEV1_TRANSID_ESP_NULL = 11,
|
|
|
|
IKEV1_TRANSID_ESP_AES_CBC = 12,
|
|
|
|
} ikev1_esp_transid_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IKEv1 ESP Encapsulation mode.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_ENCAP_TUNNEL = 1,
|
|
|
|
IKEV1_ENCAP_TRANSPORT = 2,
|
|
|
|
IKEV1_ENCAP_UDP_TUNNEL = 3,
|
|
|
|
IKEV1_ENCAP_UDP_TRANSPORT = 4,
|
|
|
|
} ikev1_esp_encap_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IKEv1 Life duration types.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_LIFE_TYPE_SECONDS = 1,
|
|
|
|
IKEV1_LIFE_TYPE_KILOBYTES = 2,
|
|
|
|
} ikev1_life_type_t;
|
|
|
|
|
2011-11-17 09:45:41 +00:00
|
|
|
/**
|
|
|
|
* IKEv1 authenticaiton methods
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
IKEV1_AUTH_PSK = 1,
|
|
|
|
IKEV1_AUTH_DSS_SIG = 2,
|
|
|
|
IKEV1_AUTH_RSA_SIG = 3,
|
|
|
|
IKEV1_AUTH_RSA_ENC = 4,
|
|
|
|
IKEV1_AUTH_RSA_ENC_REV = 5,
|
|
|
|
} ikev1_auth_method_t;
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(payload_t, verify, status_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-17 12:49:35 +00:00
|
|
|
{
|
2005-11-29 12:23:40 +00:00
|
|
|
status_t status = SUCCESS;
|
2010-10-28 12:21:44 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
payload_t *current;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
if (this->next_payload != NO_PAYLOAD && this->next_payload != 2)
|
2005-11-17 12:49:35 +00:00
|
|
|
{
|
|
|
|
/* must be 0 or 2 */
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_ENC, "inconsistent next payload");
|
2005-11-17 12:49:35 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
if (this->transforms_count != this->transforms->get_count(this->transforms))
|
|
|
|
{
|
|
|
|
/* must be the same! */
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_ENC, "transform count invalid");
|
2005-11-17 12:49:35 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
switch (this->protocol_id)
|
|
|
|
{
|
|
|
|
case PROTO_AH:
|
|
|
|
case PROTO_ESP:
|
|
|
|
if (this->spi.len != 4)
|
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_ENC, "invalid SPI length in %N proposal",
|
2006-10-18 11:46:13 +00:00
|
|
|
protocol_id_names, this->protocol_id);
|
2006-07-27 12:18:40 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROTO_IKE:
|
|
|
|
if (this->spi.len != 0 && this->spi.len != 8)
|
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_ENC, "invalid SPI length in IKE proposal");
|
2006-07-27 12:18:40 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2010-10-28 12:21:44 +00:00
|
|
|
break;
|
2005-11-17 12:49:35 +00:00
|
|
|
}
|
2010-10-28 12:21:44 +00:00
|
|
|
enumerator = this->transforms->create_enumerator(this->transforms);
|
|
|
|
while (enumerator->enumerate(enumerator, ¤t))
|
2005-11-29 12:23:40 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
status = current->verify(current);
|
2005-11-29 12:23:40 +00:00
|
|
|
if (status != SUCCESS)
|
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_ENC, "TRANSFORM_SUBSTRUCTURE verification failed");
|
2005-11-29 12:23:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-10-28 12:21:44 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
|
|
|
/* proposal number is checked in SA payload */
|
2005-11-29 12:23:40 +00:00
|
|
|
return status;
|
2005-11-17 12:49:35 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 10:27:55 +00:00
|
|
|
METHOD(payload_t, get_encoding_rules, int,
|
|
|
|
private_proposal_substructure_t *this, encoding_rule_t **rules)
|
2005-11-14 10:14:22 +00:00
|
|
|
{
|
2011-11-16 12:46:54 +00:00
|
|
|
if (this->type == PROPOSAL_SUBSTRUCTURE)
|
|
|
|
{
|
|
|
|
*rules = encodings_v2;
|
2011-11-17 10:27:55 +00:00
|
|
|
return countof(encodings_v2);
|
2011-11-16 12:46:54 +00:00
|
|
|
}
|
2011-11-17 10:27:55 +00:00
|
|
|
*rules = encodings_v1;
|
|
|
|
return countof(encodings_v1);
|
2005-11-14 10:14:22 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 11:27:46 +00:00
|
|
|
METHOD(payload_t, get_header_length, int,
|
|
|
|
private_proposal_substructure_t *this)
|
|
|
|
{
|
|
|
|
return 8 + this->spi_size;
|
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(payload_t, get_type, payload_type_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-14 10:14:22 +00:00
|
|
|
{
|
2011-11-16 12:46:54 +00:00
|
|
|
return this->type;
|
2005-11-14 10:14:22 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(payload_t, get_next_type, payload_type_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-14 10:14:22 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
return this->next_payload;
|
2005-11-14 10:14:22 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(payload_t, set_next_type, void,
|
|
|
|
private_proposal_substructure_t *this, payload_type_t type)
|
2005-11-15 09:14:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-10-18 11:46:13 +00:00
|
|
|
/**
|
|
|
|
* (re-)compute the length of the payload.
|
|
|
|
*/
|
|
|
|
static void compute_length(private_proposal_substructure_t *this)
|
|
|
|
{
|
2010-11-24 13:21:01 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
payload_t *transform;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-11-24 13:21:01 +00:00
|
|
|
this->transforms_count = 0;
|
2011-11-17 11:27:46 +00:00
|
|
|
this->proposal_length = get_header_length(this);
|
2010-11-24 13:21:01 +00:00
|
|
|
enumerator = this->transforms->create_enumerator(this->transforms);
|
|
|
|
while (enumerator->enumerate(enumerator, &transform))
|
2006-10-18 11:46:13 +00:00
|
|
|
{
|
2010-11-24 13:21:01 +00:00
|
|
|
this->proposal_length += transform->get_length(transform);
|
|
|
|
this->transforms_count++;
|
2006-10-18 11:46:13 +00:00
|
|
|
}
|
2010-11-24 13:21:01 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-10-18 11:46:13 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(payload_t, get_length, size_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-14 10:14:22 +00:00
|
|
|
{
|
|
|
|
return this->proposal_length;
|
|
|
|
}
|
|
|
|
|
2005-11-14 12:04:06 +00:00
|
|
|
/**
|
2010-10-28 12:21:44 +00:00
|
|
|
* Add a transform substructure to the proposal
|
2005-11-14 12:04:06 +00:00
|
|
|
*/
|
2010-10-28 12:21:44 +00:00
|
|
|
static void add_transform_substructure(private_proposal_substructure_t *this,
|
|
|
|
transform_substructure_t *transform)
|
2005-11-14 12:04:06 +00:00
|
|
|
{
|
2005-11-14 17:24:18 +00:00
|
|
|
if (this->transforms->get_count(this->transforms) > 0)
|
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
transform_substructure_t *last;
|
2005-11-14 17:24:18 +00:00
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
this->transforms->get_last(this->transforms, (void **)&last);
|
|
|
|
last->set_is_last_transform(last, FALSE);
|
2005-11-14 17:24:18 +00:00
|
|
|
}
|
|
|
|
transform->set_is_last_transform(transform,TRUE);
|
2010-10-28 12:21:44 +00:00
|
|
|
this->transforms->insert_last(this->transforms, transform);
|
2006-10-18 11:46:13 +00:00
|
|
|
compute_length(this);
|
2005-11-14 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, set_is_last_proposal, void,
|
|
|
|
private_proposal_substructure_t *this, bool is_last)
|
2005-12-01 08:48:57 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
this->next_payload = is_last ? 0 : PROPOSAL_TYPE_VALUE;
|
2005-12-01 08:48:57 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, set_proposal_number, void,
|
|
|
|
private_proposal_substructure_t *this,u_int8_t proposal_number)
|
2005-11-14 16:03:44 +00:00
|
|
|
{
|
|
|
|
this->proposal_number = proposal_number;
|
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, get_proposal_number, u_int8_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-14 16:03:44 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
return this->proposal_number;
|
2005-11-14 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, set_protocol_id, void,
|
|
|
|
private_proposal_substructure_t *this,u_int8_t protocol_id)
|
2005-11-14 16:03:44 +00:00
|
|
|
{
|
|
|
|
this->protocol_id = protocol_id;
|
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, get_protocol_id, u_int8_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-14 16:03:44 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
return this->protocol_id;
|
2005-11-14 12:04:06 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, set_spi, void,
|
|
|
|
private_proposal_substructure_t *this, chunk_t spi)
|
2005-11-14 16:03:44 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
free(this->spi.ptr);
|
|
|
|
this->spi = chunk_clone(spi);
|
2005-11-14 16:03:44 +00:00
|
|
|
this->spi_size = spi.len;
|
2006-10-18 11:46:13 +00:00
|
|
|
compute_length(this);
|
2005-11-14 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, get_spi, chunk_t,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-14 16:03:44 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
return this->spi;
|
2005-11-14 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 12:46:54 +00:00
|
|
|
/**
|
|
|
|
* Add a transform to a proposal for IKEv2
|
|
|
|
*/
|
|
|
|
static void add_to_proposal_v2(proposal_t *proposal,
|
|
|
|
transform_substructure_t *transform)
|
|
|
|
{
|
|
|
|
transform_attribute_t *tattr;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
u_int16_t key_length = 0;
|
|
|
|
|
|
|
|
enumerator = transform->create_attribute_enumerator(transform);
|
|
|
|
while (enumerator->enumerate(enumerator, &tattr))
|
|
|
|
{
|
|
|
|
if (tattr->get_attribute_type(tattr) == TATTR_IKEV2_KEY_LENGTH)
|
|
|
|
{
|
|
|
|
key_length = tattr->get_value(tattr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
proposal->add_algorithm(proposal,
|
|
|
|
transform->get_transform_type_or_number(transform),
|
|
|
|
transform->get_transform_id(transform), key_length);
|
|
|
|
}
|
|
|
|
|
2011-11-16 17:24:14 +00:00
|
|
|
/**
|
|
|
|
* Map IKEv1 to IKEv2 algorithms
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
u_int16_t ikev1;
|
|
|
|
u_int16_t ikev2;
|
|
|
|
} algo_map_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encryption algorithm mapping
|
|
|
|
*/
|
|
|
|
static algo_map_t map_encr[] = {
|
|
|
|
{ IKEV1_ENCR_DES_CBC, ENCR_DES },
|
|
|
|
{ IKEV1_ENCR_IDEA_CBC, ENCR_IDEA },
|
|
|
|
{ IKEV1_ENCR_BLOWFISH_CBC, ENCR_BLOWFISH },
|
|
|
|
{ IKEV1_ENCR_3DES_CBC, ENCR_3DES },
|
|
|
|
{ IKEV1_ENCR_CAST_CBC, ENCR_CAST },
|
|
|
|
{ IKEV1_ENCR_AES_CBC, ENCR_AES_CBC },
|
|
|
|
{ IKEV1_ENCR_CAMELLIA_CBC, ENCR_CAMELLIA_CBC },
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Integrity algorithm mapping
|
|
|
|
*/
|
|
|
|
static algo_map_t map_integ[] = {
|
|
|
|
{ IKEV1_HASH_MD5, AUTH_HMAC_MD5_96 },
|
|
|
|
{ IKEV1_HASH_SHA1, AUTH_HMAC_SHA1_96 },
|
|
|
|
{ IKEV1_HASH_SHA2_256, AUTH_HMAC_SHA2_256_128 },
|
|
|
|
{ IKEV1_HASH_SHA2_384, AUTH_HMAC_SHA2_384_192 },
|
|
|
|
{ IKEV1_HASH_SHA2_512, AUTH_HMAC_SHA2_512_256 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PRF algorithm mapping
|
|
|
|
*/
|
|
|
|
static algo_map_t map_prf[] = {
|
|
|
|
{ IKEV1_HASH_MD5, PRF_HMAC_MD5 },
|
|
|
|
{ IKEV1_HASH_SHA1, PRF_HMAC_SHA1 },
|
|
|
|
{ IKEV1_HASH_SHA2_256, PRF_HMAC_SHA2_256 },
|
|
|
|
{ IKEV1_HASH_SHA2_384, PRF_HMAC_SHA2_384 },
|
|
|
|
{ IKEV1_HASH_SHA2_512, PRF_HMAC_SHA2_512 },
|
|
|
|
};
|
|
|
|
|
2011-11-16 12:46:54 +00:00
|
|
|
/**
|
|
|
|
* Get IKEv2 algorithm from IKEv1 identifier
|
|
|
|
*/
|
|
|
|
static u_int16_t get_alg_from_ikev1(transform_type_t type, u_int16_t value)
|
|
|
|
{
|
|
|
|
algo_map_t *map;
|
2011-11-16 17:24:14 +00:00
|
|
|
u_int16_t def;
|
|
|
|
int i, count;
|
2011-11-16 12:46:54 +00:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ENCRYPTION_ALGORITHM:
|
2011-11-16 17:24:14 +00:00
|
|
|
map = map_encr;
|
|
|
|
count = countof(map_encr);
|
2011-11-16 12:46:54 +00:00
|
|
|
def = ENCR_UNDEFINED;
|
|
|
|
break;
|
|
|
|
case INTEGRITY_ALGORITHM:
|
2011-11-16 17:24:14 +00:00
|
|
|
map = map_integ;
|
|
|
|
count = countof(map_integ);
|
2011-11-16 12:46:54 +00:00
|
|
|
def = AUTH_UNDEFINED;
|
|
|
|
break;
|
|
|
|
case PSEUDO_RANDOM_FUNCTION:
|
2011-11-16 17:24:14 +00:00
|
|
|
map = map_prf;
|
|
|
|
count = countof(map_prf);
|
2011-11-16 12:46:54 +00:00
|
|
|
def = PRF_UNDEFINED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (map[i].ikev1 == value)
|
|
|
|
{
|
|
|
|
return map[i].ikev2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2011-11-16 17:24:14 +00:00
|
|
|
/**
|
|
|
|
* Get IKEv1 algorithm from IKEv2 identifier
|
|
|
|
*/
|
|
|
|
static u_int16_t get_ikev1_from_alg(transform_type_t type, u_int16_t value)
|
|
|
|
{
|
|
|
|
algo_map_t *map;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ENCRYPTION_ALGORITHM:
|
|
|
|
map = map_encr;
|
|
|
|
count = countof(map_encr);
|
|
|
|
break;
|
|
|
|
case INTEGRITY_ALGORITHM:
|
|
|
|
map = map_integ;
|
|
|
|
count = countof(map_integ);
|
|
|
|
break;
|
|
|
|
case PSEUDO_RANDOM_FUNCTION:
|
|
|
|
map = map_prf;
|
|
|
|
count = countof(map_prf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (map[i].ikev2 == value)
|
|
|
|
{
|
|
|
|
return map[i].ikev1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:46:54 +00:00
|
|
|
/**
|
|
|
|
* Add an IKE transform to a proposal for IKEv1
|
|
|
|
*/
|
|
|
|
static void add_to_proposal_v1_ike(proposal_t *proposal,
|
|
|
|
transform_substructure_t *transform)
|
|
|
|
{
|
|
|
|
transform_attribute_type_t type;
|
|
|
|
transform_attribute_t *tattr;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
u_int16_t value, key_length = 0;
|
|
|
|
u_int16_t encr = ENCR_UNDEFINED;
|
|
|
|
|
|
|
|
enumerator = transform->create_attribute_enumerator(transform);
|
|
|
|
while (enumerator->enumerate(enumerator, &tattr))
|
|
|
|
{
|
|
|
|
type = tattr->get_attribute_type(tattr);
|
|
|
|
value = tattr->get_value(tattr);
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TATTR_PH1_ENCRYPTION_ALGORITHM:
|
|
|
|
encr = get_alg_from_ikev1(ENCRYPTION_ALGORITHM, value);
|
|
|
|
break;
|
|
|
|
case TATTR_PH1_KEY_LENGTH:
|
|
|
|
key_length = value;
|
|
|
|
break;
|
|
|
|
case TATTR_PH1_HASH_ALGORITHM:
|
|
|
|
proposal->add_algorithm(proposal, INTEGRITY_ALGORITHM,
|
|
|
|
get_alg_from_ikev1(INTEGRITY_ALGORITHM, value), 0);
|
|
|
|
proposal->add_algorithm(proposal, PSEUDO_RANDOM_FUNCTION,
|
|
|
|
get_alg_from_ikev1(PSEUDO_RANDOM_FUNCTION, value), 0);
|
|
|
|
break;
|
|
|
|
case TATTR_PH1_GROUP:
|
|
|
|
proposal->add_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
|
|
|
|
value, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* TODO-IKEv1: lifetimes, authentication and other attributes */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
if (encr != ENCR_UNDEFINED)
|
|
|
|
{
|
|
|
|
proposal->add_algorithm(proposal, ENCRYPTION_ALGORITHM, encr, key_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an ESP transform to a proposal for IKEv1
|
|
|
|
*/
|
|
|
|
static void add_to_proposal_v1_esp(proposal_t *proposal,
|
|
|
|
transform_substructure_t *transform)
|
|
|
|
{
|
2011-11-21 16:40:42 +00:00
|
|
|
transform_attribute_type_t type;
|
|
|
|
transform_attribute_t *tattr;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
u_int16_t value, key_length = 0;
|
|
|
|
|
|
|
|
enumerator = transform->create_attribute_enumerator(transform);
|
|
|
|
while (enumerator->enumerate(enumerator, &tattr))
|
|
|
|
{
|
|
|
|
type = tattr->get_attribute_type(tattr);
|
|
|
|
value = tattr->get_value(tattr);
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TATTR_PH2_KEY_LENGTH:
|
|
|
|
key_length = value;
|
|
|
|
break;
|
|
|
|
case TATTR_PH2_AUTH_ALGORITHM:
|
|
|
|
proposal->add_algorithm(proposal, INTEGRITY_ALGORITHM,
|
|
|
|
get_alg_from_ikev1(INTEGRITY_ALGORITHM, value), 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* TODO-IKEv1: lifetimes other attributes */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
/* TODO-IKEv1: handle ESN attribute */
|
|
|
|
proposal->add_algorithm(proposal, EXTENDED_SEQUENCE_NUMBERS,
|
|
|
|
NO_EXT_SEQ_NUMBERS, 0);
|
|
|
|
|
|
|
|
proposal->add_algorithm(proposal, ENCRYPTION_ALGORITHM,
|
|
|
|
transform->get_transform_id(transform), key_length);
|
2011-11-16 12:46:54 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD(proposal_substructure_t, get_proposal, proposal_t*,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-12-01 08:48:57 +00:00
|
|
|
{
|
2006-10-24 14:20:45 +00:00
|
|
|
transform_substructure_t *transform;
|
2011-11-16 12:46:54 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-06-07 13:26:23 +00:00
|
|
|
proposal_t *proposal;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-10-28 12:40:54 +00:00
|
|
|
proposal = proposal_create(this->protocol_id, this->proposal_number);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
enumerator = this->transforms->create_enumerator(this->transforms);
|
|
|
|
while (enumerator->enumerate(enumerator, &transform))
|
2006-02-08 15:25:34 +00:00
|
|
|
{
|
2011-11-16 12:46:54 +00:00
|
|
|
if (this->type == PROPOSAL_SUBSTRUCTURE)
|
|
|
|
{
|
|
|
|
add_to_proposal_v2(proposal, transform);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (this->protocol_id)
|
|
|
|
{
|
|
|
|
case PROTO_IKE:
|
|
|
|
add_to_proposal_v1_ike(proposal, transform);
|
|
|
|
break;
|
|
|
|
case PROTO_ESP:
|
|
|
|
add_to_proposal_v1_esp(proposal, transform);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* TODO-IKEv1: We currently accept the first set of transforms
|
|
|
|
* in a substructure only. We need to return multiple proposals,
|
|
|
|
* but this messes up proposal numbering, as we don't support
|
|
|
|
* transform numbering. */
|
|
|
|
break;
|
|
|
|
}
|
2006-02-08 15:25:34 +00:00
|
|
|
}
|
2010-10-28 12:21:44 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
switch (this->spi.len)
|
|
|
|
{
|
|
|
|
case 4:
|
2011-11-16 12:46:54 +00:00
|
|
|
proposal->set_spi(proposal, *((u_int32_t*)this->spi.ptr));
|
2006-06-07 13:26:23 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2011-11-16 12:46:54 +00:00
|
|
|
proposal->set_spi(proposal, *((u_int64_t*)this->spi.ptr));
|
2006-06-07 13:26:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-16 12:46:54 +00:00
|
|
|
break;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
return proposal;
|
2006-02-08 15:25:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 09:55:08 +00:00
|
|
|
METHOD(proposal_substructure_t, create_substructure_enumerator, enumerator_t*,
|
|
|
|
private_proposal_substructure_t *this)
|
|
|
|
{
|
|
|
|
return this->transforms->create_enumerator(this->transforms);
|
|
|
|
}
|
|
|
|
|
2010-10-28 12:21:44 +00:00
|
|
|
METHOD2(payload_t, proposal_substructure_t, destroy, void,
|
|
|
|
private_proposal_substructure_t *this)
|
2005-11-21 13:44:16 +00:00
|
|
|
{
|
2006-10-24 08:46:17 +00:00
|
|
|
this->transforms->destroy_offset(this->transforms,
|
2011-11-16 12:46:54 +00:00
|
|
|
offsetof(payload_t, destroy));
|
2006-10-24 08:46:17 +00:00
|
|
|
chunk_free(&this->spi);
|
2006-04-10 08:07:38 +00:00
|
|
|
free(this);
|
2005-11-21 13:44:16 +00:00
|
|
|
}
|
2005-11-14 16:03:44 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/*
|
2005-11-28 18:24:10 +00:00
|
|
|
* Described in header.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2011-11-16 12:46:54 +00:00
|
|
|
proposal_substructure_t *proposal_substructure_create(payload_type_t type)
|
2005-11-14 10:14:22 +00:00
|
|
|
{
|
2010-10-28 12:21:44 +00:00
|
|
|
private_proposal_substructure_t *this;
|
|
|
|
|
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.payload_interface = {
|
|
|
|
.verify = _verify,
|
|
|
|
.get_encoding_rules = _get_encoding_rules,
|
2011-11-17 11:27:46 +00:00
|
|
|
.get_header_length = _get_header_length,
|
2010-10-28 12:21:44 +00:00
|
|
|
.get_length = _get_length,
|
|
|
|
.get_next_type = _get_next_type,
|
|
|
|
.set_next_type = _set_next_type,
|
|
|
|
.get_type = _get_type,
|
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
.set_proposal_number = _set_proposal_number,
|
|
|
|
.get_proposal_number = _get_proposal_number,
|
|
|
|
.set_protocol_id = _set_protocol_id,
|
|
|
|
.get_protocol_id = _get_protocol_id,
|
|
|
|
.set_is_last_proposal = _set_is_last_proposal,
|
|
|
|
.get_proposal = _get_proposal,
|
2010-11-25 09:55:08 +00:00
|
|
|
.create_substructure_enumerator = _create_substructure_enumerator,
|
2010-10-28 12:21:44 +00:00
|
|
|
.set_spi = _set_spi,
|
|
|
|
.get_spi = _get_spi,
|
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
.next_payload = NO_PAYLOAD,
|
|
|
|
.transforms = linked_list_create(),
|
2011-11-16 12:46:54 +00:00
|
|
|
.type = type,
|
2010-10-28 12:21:44 +00:00
|
|
|
);
|
2011-11-17 11:27:46 +00:00
|
|
|
compute_length(this);
|
2010-10-28 12:21:44 +00:00
|
|
|
|
|
|
|
return &this->public;
|
2005-11-14 10:14:22 +00:00
|
|
|
}
|
2006-02-06 14:05:35 +00:00
|
|
|
|
2011-11-16 17:24:14 +00:00
|
|
|
/**
|
|
|
|
* Add an IKEv1 IKE proposal to the substructure
|
2006-02-06 14:05:35 +00:00
|
|
|
*/
|
2011-11-16 17:24:14 +00:00
|
|
|
static void set_from_proposal_v1_ike(private_proposal_substructure_t *this,
|
|
|
|
proposal_t *proposal)
|
2006-02-06 14:05:35 +00:00
|
|
|
{
|
|
|
|
transform_substructure_t *transform;
|
2008-03-26 10:06:45 +00:00
|
|
|
u_int16_t alg, key_size;
|
|
|
|
enumerator_t *enumerator;
|
2011-11-16 12:46:54 +00:00
|
|
|
|
2011-11-16 17:24:14 +00:00
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE_V1,
|
|
|
|
0, IKEV1_TRANSID_KEY_IKE);
|
|
|
|
|
|
|
|
enumerator = proposal->create_enumerator(proposal, ENCRYPTION_ALGORITHM);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
|
|
|
{
|
|
|
|
alg = get_ikev1_from_alg(ENCRYPTION_ALGORITHM, alg);
|
|
|
|
if (alg)
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH1_ENCRYPTION_ALGORITHM, alg));
|
|
|
|
if (key_size)
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH1_KEY_LENGTH, key_size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
/* encode the integrity algorithm as hash and assume use the same PRF */
|
|
|
|
enumerator = proposal->create_enumerator(proposal, INTEGRITY_ALGORITHM);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
2011-11-16 12:46:54 +00:00
|
|
|
{
|
2011-11-16 17:24:14 +00:00
|
|
|
alg = get_ikev1_from_alg(INTEGRITY_ALGORITHM, alg);
|
|
|
|
if (alg)
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH1_HASH_ALGORITHM, alg));
|
|
|
|
}
|
2011-11-16 12:46:54 +00:00
|
|
|
}
|
2011-11-16 17:24:14 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-11-16 17:24:14 +00:00
|
|
|
enumerator = proposal->create_enumerator(proposal, DIFFIE_HELLMAN_GROUP);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH1_GROUP, alg));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
2011-11-18 08:16:54 +00:00
|
|
|
/* TODO-IKEv1: Add lifetime, non-fixed auth-method and other attributes */
|
2011-11-17 09:45:41 +00:00
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
2011-11-18 08:16:54 +00:00
|
|
|
TATTR_PH1_AUTH_METHOD, IKEV1_AUTH_PSK));
|
2011-11-16 17:24:14 +00:00
|
|
|
|
|
|
|
add_transform_substructure(this, transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an IKEv1 ESP proposal to the substructure
|
|
|
|
*/
|
|
|
|
static void set_from_proposal_v1_esp(private_proposal_substructure_t *this,
|
|
|
|
proposal_t *proposal)
|
|
|
|
{
|
2011-11-21 16:40:42 +00:00
|
|
|
transform_substructure_t *transform = NULL;
|
|
|
|
u_int16_t alg, key_size;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
|
|
|
|
enumerator = proposal->create_enumerator(proposal, ENCRYPTION_ALGORITHM);
|
|
|
|
if (enumerator->enumerate(enumerator, &alg, &key_size))
|
|
|
|
{
|
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE_V1,
|
|
|
|
0, alg);
|
|
|
|
if (key_size)
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH2_KEY_LENGTH, key_size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
if (!transform)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
enumerator = proposal->create_enumerator(proposal, INTEGRITY_ALGORITHM);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
|
|
|
{
|
|
|
|
alg = get_ikev1_from_alg(INTEGRITY_ALGORITHM, alg);
|
|
|
|
if (alg)
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH2_AUTH_ALGORITHM, alg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
/* TODO-IKEv1: Add lifetime and other attributes, non-fixes ESN */
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE_V1,
|
|
|
|
TATTR_PH2_EXT_SEQ_NUMBER, NO_EXT_SEQ_NUMBERS));
|
|
|
|
|
|
|
|
add_transform_substructure(this, transform);
|
2011-11-16 17:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an IKEv2 proposal to the substructure
|
|
|
|
*/
|
|
|
|
static void set_from_proposal_v2(private_proposal_substructure_t *this,
|
|
|
|
proposal_t *proposal)
|
|
|
|
{
|
|
|
|
transform_substructure_t *transform;
|
|
|
|
u_int16_t alg, key_size;
|
|
|
|
enumerator_t *enumerator;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-07-20 13:57:53 +00:00
|
|
|
/* encryption algorithm is only available in ESP */
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator = proposal->create_enumerator(proposal, ENCRYPTION_ALGORITHM);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
2006-02-06 14:05:35 +00:00
|
|
|
{
|
2011-11-16 17:24:14 +00:00
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE,
|
|
|
|
ENCRYPTION_ALGORITHM, alg);
|
|
|
|
if (key_size)
|
|
|
|
{
|
|
|
|
transform->add_transform_attribute(transform,
|
|
|
|
transform_attribute_create_value(TRANSFORM_ATTRIBUTE,
|
|
|
|
TATTR_IKEV2_KEY_LENGTH, key_size));
|
|
|
|
}
|
2008-03-26 10:06:45 +00:00
|
|
|
add_transform_substructure(this, transform);
|
2006-02-06 14:05:35 +00:00
|
|
|
}
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-02-06 14:05:35 +00:00
|
|
|
/* integrity algorithms */
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator = proposal->create_enumerator(proposal, INTEGRITY_ALGORITHM);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
2006-02-06 14:05:35 +00:00
|
|
|
{
|
2011-11-16 17:24:14 +00:00
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE,
|
|
|
|
INTEGRITY_ALGORITHM, alg);
|
2008-03-26 10:06:45 +00:00
|
|
|
add_transform_substructure(this, transform);
|
2006-02-06 14:05:35 +00:00
|
|
|
}
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-02-08 15:25:34 +00:00
|
|
|
/* prf algorithms */
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator = proposal->create_enumerator(proposal, PSEUDO_RANDOM_FUNCTION);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, &key_size))
|
2006-02-08 15:25:34 +00:00
|
|
|
{
|
2011-11-16 17:24:14 +00:00
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE,
|
|
|
|
PSEUDO_RANDOM_FUNCTION, alg);
|
2008-03-26 10:06:45 +00:00
|
|
|
add_transform_substructure(this, transform);
|
2006-02-08 15:25:34 +00:00
|
|
|
}
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-02-06 14:05:35 +00:00
|
|
|
/* dh groups */
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator = proposal->create_enumerator(proposal, DIFFIE_HELLMAN_GROUP);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, NULL))
|
2006-02-06 14:05:35 +00:00
|
|
|
{
|
2011-11-16 17:24:14 +00:00
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE,
|
|
|
|
DIFFIE_HELLMAN_GROUP, alg);
|
2008-03-26 10:06:45 +00:00
|
|
|
add_transform_substructure(this, transform);
|
2006-02-06 14:05:35 +00:00
|
|
|
}
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-02-06 14:05:35 +00:00
|
|
|
/* extended sequence numbers */
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator = proposal->create_enumerator(proposal, EXTENDED_SEQUENCE_NUMBERS);
|
|
|
|
while (enumerator->enumerate(enumerator, &alg, NULL))
|
2006-02-06 14:05:35 +00:00
|
|
|
{
|
2011-11-16 17:24:14 +00:00
|
|
|
transform = transform_substructure_create_type(TRANSFORM_SUBSTRUCTURE,
|
|
|
|
EXTENDED_SEQUENCE_NUMBERS, alg);
|
2008-03-26 10:06:45 +00:00
|
|
|
add_transform_substructure(this, transform);
|
2006-02-06 14:05:35 +00:00
|
|
|
}
|
2008-03-26 10:06:45 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2011-11-16 17:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Described in header.
|
|
|
|
*/
|
|
|
|
proposal_substructure_t *proposal_substructure_create_from_proposal(
|
|
|
|
payload_type_t type, proposal_t *proposal)
|
|
|
|
{
|
|
|
|
private_proposal_substructure_t *this;
|
|
|
|
u_int64_t spi64;
|
|
|
|
u_int32_t spi32;
|
|
|
|
|
|
|
|
this = (private_proposal_substructure_t*)proposal_substructure_create(type);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-11-16 17:24:14 +00:00
|
|
|
if (type == PROPOSAL_SUBSTRUCTURE)
|
|
|
|
{
|
|
|
|
set_from_proposal_v2(this, proposal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (proposal->get_protocol(proposal))
|
|
|
|
{
|
|
|
|
case PROTO_IKE:
|
|
|
|
set_from_proposal_v1_ike(this, proposal);
|
|
|
|
break;
|
|
|
|
case PROTO_ESP:
|
|
|
|
set_from_proposal_v1_esp(this, proposal);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 12:18:40 +00:00
|
|
|
/* add SPI, if necessary */
|
|
|
|
switch (proposal->get_protocol(proposal))
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2006-07-27 12:18:40 +00:00
|
|
|
case PROTO_AH:
|
|
|
|
case PROTO_ESP:
|
2011-11-16 17:24:14 +00:00
|
|
|
spi32 = proposal->get_spi(proposal);
|
|
|
|
this->spi = chunk_clone(chunk_from_thing(spi32));
|
|
|
|
this->spi_size = this->spi.len;
|
2006-07-27 12:18:40 +00:00
|
|
|
break;
|
|
|
|
case PROTO_IKE:
|
2011-11-16 17:24:14 +00:00
|
|
|
spi64 = proposal->get_spi(proposal);
|
|
|
|
if (spi64)
|
2006-07-27 12:18:40 +00:00
|
|
|
{ /* IKE only uses SPIS when rekeying, but on initial setup */
|
2011-11-16 17:24:14 +00:00
|
|
|
this->spi = chunk_clone(chunk_from_thing(spi64));
|
|
|
|
this->spi_size = this->spi.len;
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-08-28 08:45:22 +00:00
|
|
|
default:
|
|
|
|
break;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2010-10-28 12:40:54 +00:00
|
|
|
this->proposal_number = proposal->get_number(proposal);
|
2006-06-07 13:26:23 +00:00
|
|
|
this->protocol_id = proposal->get_protocol(proposal);
|
2010-11-15 10:53:20 +00:00
|
|
|
compute_length(this);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
return &this->public;
|
2006-02-06 14:05:35 +00:00
|
|
|
}
|