introduced new logging subsystem using bus:
passive listeners can register on the bus active listeners wait for signals actively multiplexing allows multiple listeners to receive debug signals a lot more...
This commit is contained in:
@@ -26,10 +26,7 @@
|
||||
#include "cert_payload.h"
|
||||
|
||||
|
||||
/**
|
||||
* String mappings for cert_encoding_t.
|
||||
*/
|
||||
static const char *const cert_encoding_name[] = {
|
||||
ENUM(cert_encoding_names, CERT_NONE, CERT_X509_HASH_AND_URL_BUNDLE,
|
||||
"CERT_NONE",
|
||||
"CERT_PKCS7_WRAPPED_X509",
|
||||
"CERT_PGP",
|
||||
@@ -43,11 +40,8 @@ static const char *const cert_encoding_name[] = {
|
||||
"CERT_X509_ATTRIBUTE",
|
||||
"CERT_RAW_RSA_KEY",
|
||||
"CERT_X509_HASH_AND_URL",
|
||||
"CERT_X509_HASH_AND_URL_BUNDLE"
|
||||
};
|
||||
|
||||
enum_names cert_encoding_names =
|
||||
{ CERT_NONE, CERT_X509_HASH_AND_URL_BUNDLE, cert_encoding_name, NULL };
|
||||
"CERT_X509_HASH_AND_URL_BUNDLE",
|
||||
);
|
||||
|
||||
typedef struct private_cert_payload_t private_cert_payload_t;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ enum cert_encoding_t {
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern enum_names cert_encoding_names;
|
||||
extern enum_name_t *cert_encoding_names;
|
||||
|
||||
typedef struct cert_payload_t cert_payload_t;
|
||||
|
||||
|
||||
@@ -58,27 +58,23 @@ struct private_configuration_attribute_t {
|
||||
chunk_t attribute_value;
|
||||
};
|
||||
|
||||
/**
|
||||
* String mappings for configuration_attribute_type_t.
|
||||
*/
|
||||
mapping_t configuration_attribute_type_m[] = {
|
||||
{INTERNAL_IP4_ADDRESS, "INTERNAL_IP4_ADDRESS"},
|
||||
{INTERNAL_IP4_NETMASK, "INTERNAL_IP4_NETMASK"},
|
||||
{INTERNAL_IP4_DNS, "INTERNAL_IP4_DNS"},
|
||||
{INTERNAL_IP4_NBNS, "INTERNAL_IP4_NBNS"},
|
||||
{INTERNAL_ADDRESS_EXPIRY, "INTERNAL_ADDRESS_EXPIRY"},
|
||||
{INTERNAL_IP4_DHCP, "INTERNAL_IP4_DHCP"},
|
||||
{APPLICATION_VERSION, "APPLICATION_VERSION"},
|
||||
{INTERNAL_IP6_ADDRESS, "INTERNAL_IP6_ADDRESS"},
|
||||
{INTERNAL_IP6_DNS, "INTERNAL_IP6_DNS"},
|
||||
{INTERNAL_IP6_NBNS, "INTERNAL_IP6_NBNS"},
|
||||
{INTERNAL_IP6_DHCP, "INTERNAL_IP6_DHCP"},
|
||||
{INTERNAL_IP4_SUBNET, "INTERNAL_IP4_SUBNET"},
|
||||
{SUPPORTED_ATTRIBUTES, "SUPPORTED_ATTRIBUTES"},
|
||||
{INTERNAL_IP6_SUBNET, "INTERNAL_IP6_SUBNET"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
|
||||
ENUM_BEGIN(configuration_attribute_type_name, INTERNAL_IP4_ADDRESS, INTERNAL_IP6_ADDRESS,
|
||||
"INTERNAL_IP4_ADDRESS",
|
||||
"INTERNAL_IP4_NETMASK",
|
||||
"INTERNAL_IP4_DNS",
|
||||
"INTERNAL_IP4_NBNS",
|
||||
"INTERNAL_ADDRESS_EXPIRY",
|
||||
"INTERNAL_IP4_DHCP",
|
||||
"APPLICATION_VERSION",
|
||||
"INTERNAL_IP6_ADDRESS");
|
||||
ENUM_NEXT(configuration_attribute_type_name, INTERNAL_IP6_DNS, INTERNAL_IP6_SUBNET, INTERNAL_IP6_ADDRESS,
|
||||
"INTERNAL_IP6_DNS",
|
||||
"INTERNAL_IP6_NBNS",
|
||||
"INTERNAL_IP6_DHCP",
|
||||
"INTERNAL_IP4_SUBNET",
|
||||
"SUPPORTED_ATTRIBUTES",
|
||||
"INTERNAL_IP6_SUBNET");
|
||||
ENUM_END(configuration_attribute_type_name, INTERNAL_IP6_SUBNET);
|
||||
|
||||
/**
|
||||
* Encoding rules to parse or generate a configuration attribute.
|
||||
|
||||
@@ -62,11 +62,11 @@ enum configuration_attribute_type_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* String mappings for configuration_attribute_type_t.
|
||||
* enum names for configuration_attribute_type_t.
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern mapping_t configuration_attribute_type_m[];
|
||||
extern enum_name_t *configuration_attribute_type_names;
|
||||
|
||||
typedef struct configuration_attribute_t configuration_attribute_t;
|
||||
|
||||
|
||||
@@ -28,18 +28,12 @@
|
||||
#include <encoding/payloads/encodings.h>
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
|
||||
/**
|
||||
* String mappings for config_type_t.
|
||||
*/
|
||||
mapping_t config_type_m[] = {
|
||||
{CFG_REQUEST, "CFG_REQUEST"},
|
||||
{CFG_REPLY, "CFG_REPLY"},
|
||||
{CFG_SET, "CFG_SET"},
|
||||
{CFG_ACK, "CFG_ACK"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
|
||||
ENUM(config_type_names, CFG_REQUEST, CFG_ACK,
|
||||
"CFG_REQUEST",
|
||||
"CFG_REPLY",
|
||||
"CFG_SET",
|
||||
"CFG_ACK",
|
||||
);
|
||||
|
||||
typedef struct private_cp_payload_t private_cp_payload_t;
|
||||
|
||||
@@ -77,13 +71,6 @@ struct private_cp_payload_t {
|
||||
* Config Type.
|
||||
*/
|
||||
u_int8_t config_type;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_cp_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_cp_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -189,12 +176,31 @@ static void set_next_type(private_cp_payload_t *this,payload_type_t type)
|
||||
this->next_payload = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* recompute the length of the payload.
|
||||
*/
|
||||
static void compute_length(private_cp_payload_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t length = CP_PAYLOAD_HEADER_LENGTH;
|
||||
iterator = this->attributes->create_iterator(this->attributes,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t *current_attribute;
|
||||
iterator->current(iterator,(void **) ¤t_attribute);
|
||||
length += current_attribute->get_length(current_attribute);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_cp_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
@@ -212,7 +218,7 @@ static iterator_t *create_configuration_attribute_iterator (private_cp_payload_t
|
||||
static void add_configuration_attribute (private_cp_payload_t *this,configuration_attribute_t *attribute)
|
||||
{
|
||||
this->attributes->insert_last(this->attributes,(void *) attribute);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,25 +237,6 @@ static config_type_t get_config_type (private_cp_payload_t *this)
|
||||
return this->config_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_cp_payload_t.compute_length.
|
||||
*/
|
||||
static void compute_length (private_cp_payload_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t length = CP_PAYLOAD_HEADER_LENGTH;
|
||||
iterator = this->attributes->create_iterator(this->attributes,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t *current_attribute;
|
||||
iterator->current(iterator,(void **) ¤t_attribute);
|
||||
length += current_attribute->get_length(current_attribute);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.destroy and cp_payload_t.destroy.
|
||||
*/
|
||||
@@ -292,10 +279,6 @@ cp_payload_t *cp_payload_create()
|
||||
this->public.get_config_type = (config_type_t (*) (cp_payload_t *)) get_config_type;
|
||||
this->public.destroy = (void (*) (cp_payload_t *)) destroy;
|
||||
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* set default values of the fields */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
|
||||
@@ -52,11 +52,11 @@ enum config_type_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* string mappings for config_type_t.
|
||||
*
|
||||
* enum name for config_type_t.
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern mapping_t config_type_m[];
|
||||
extern enum_name_t *config_type_names;
|
||||
|
||||
|
||||
typedef struct cp_payload_t cp_payload_t;
|
||||
|
||||
@@ -24,46 +24,44 @@
|
||||
|
||||
#include "encodings.h"
|
||||
|
||||
|
||||
mapping_t encoding_type_m[] = {
|
||||
{U_INT_4, "U_INT_4"},
|
||||
{U_INT_8, "U_INT_8"},
|
||||
{U_INT_16, "U_INT_16"},
|
||||
{U_INT_32, "U_INT_32"},
|
||||
{U_INT_64, "U_INT_64"},
|
||||
{IKE_SPI, "IKE_SPI"},
|
||||
{RESERVED_BIT, "RESERVED_BIT"},
|
||||
{RESERVED_BYTE, "RESERVED_BYTE"},
|
||||
{FLAG, "FLAG"},
|
||||
{PAYLOAD_LENGTH, "PAYLOAD_LENGTH"},
|
||||
{HEADER_LENGTH, "HEADER_LENGTH"},
|
||||
{SPI_SIZE, "SPI_SIZE"},
|
||||
{SPI, "SPI"},
|
||||
{KEY_EXCHANGE_DATA, "KEY_EXCHANGE_DATA"},
|
||||
{NOTIFICATION_DATA, "NOTIFICATION_DATA"},
|
||||
{PROPOSALS, "PROPOSALS"},
|
||||
{TRANSFORMS, "TRANSFORMS"},
|
||||
{TRANSFORM_ATTRIBUTES, "TRANSFORM_ATTRIBUTES"},
|
||||
{ATTRIBUTE_FORMAT, "ATTRIBUTE_FORMAT"},
|
||||
{ATTRIBUTE_TYPE, "ATTRIBUTE_TYPE"},
|
||||
{ATTRIBUTE_LENGTH_OR_VALUE, "ATTRIBUTE_LENGTH_OR_VALUE"},
|
||||
{ATTRIBUTE_VALUE, "ATTRIBUTE_VALUE"},
|
||||
{NONCE_DATA, "NONCE_DATA"},
|
||||
{ID_DATA, "ID_DATA"},
|
||||
{AUTH_DATA, "AUTH_DATA"},
|
||||
{ENCRYPTED_DATA, "ENCRYPTED_DATA"},
|
||||
{TS_TYPE, "TS_TYPE"},
|
||||
{ADDRESS, "ADDRESS"},
|
||||
{TRAFFIC_SELECTORS, "TRAFFIC_SELECTORS"},
|
||||
{CERT_DATA, "CERT_DATA"},
|
||||
{CERTREQ_DATA, "CERTREQ_DATA"},
|
||||
{SPIS, "SPIS"},
|
||||
{VID_DATA, "VID_DATA"},
|
||||
{VID_DATA, "VID_DATA"},
|
||||
{CONFIGURATION_ATTRIBUTES, "CONFIGURATION_ATTRIBUTES"},
|
||||
{CONFIGURATION_ATTRIBUTE_LENGTH, "CONFIGURATION_ATTRIBUTE_LENGTH"},
|
||||
{CONFIGURATION_ATTRIBUTE_VALUE, "CONFIGURATION_ATTRIBUTE_VALUE"},
|
||||
{EAP_MESSAGE, "EAP_MESSAGE"},
|
||||
{UNKNOWN_DATA,"UNKNOWN_DATA"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
ENUM(encoding_type_names, U_INT_4, UNKNOWN_DATA,
|
||||
"U_INT_4",
|
||||
"U_INT_8",
|
||||
"U_INT_16",
|
||||
"U_INT_32",
|
||||
"U_INT_64",
|
||||
"IKE_SPI",
|
||||
"RESERVED_BIT",
|
||||
"RESERVED_BYTE",
|
||||
"FLAG",
|
||||
"PAYLOAD_LENGTH",
|
||||
"HEADER_LENGTH",
|
||||
"SPI_SIZE",
|
||||
"SPI",
|
||||
"KEY_EXCHANGE_DATA",
|
||||
"NOTIFICATION_DATA",
|
||||
"PROPOSALS",
|
||||
"TRANSFORMS",
|
||||
"TRANSFORM_ATTRIBUTES",
|
||||
"ATTRIBUTE_FORMAT",
|
||||
"ATTRIBUTE_TYPE",
|
||||
"ATTRIBUTE_LENGTH_OR_VALUE",
|
||||
"ATTRIBUTE_VALUE",
|
||||
"NONCE_DATA",
|
||||
"ID_DATA",
|
||||
"AUTH_DATA",
|
||||
"ENCRYPTED_DATA",
|
||||
"TS_TYPE",
|
||||
"ADDRESS",
|
||||
"TRAFFIC_SELECTORS",
|
||||
"CERT_DATA",
|
||||
"CERTREQ_DATA",
|
||||
"SPIS",
|
||||
"VID_DATA",
|
||||
"VID_DATA",
|
||||
"CONFIGURATION_ATTRIBUTES",
|
||||
"CONFIGURATION_ATTRIBUTE_LENGTH",
|
||||
"CONFIGURATION_ATTRIBUTE_VALUE",
|
||||
"EAP_MESSAGE",
|
||||
"UNKNOWN_DATA",
|
||||
);
|
||||
|
||||
@@ -499,11 +499,11 @@ enum encoding_type_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* mappings to map encoding_type_t's to strings
|
||||
* enum name for encoding_type_t
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern mapping_t encoding_type_m[];
|
||||
extern enum_name_t *encoding_type_names;
|
||||
|
||||
|
||||
typedef struct encoding_rule_t encoding_rule_t;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <daemon.h>
|
||||
#include <encoding/payloads/encodings.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/logger.h>
|
||||
#include <encoding/generator.h>
|
||||
#include <encoding/parser.h>
|
||||
#include <utils/iterator.h>
|
||||
@@ -37,8 +36,6 @@
|
||||
#include <crypto/signers/signer.h>
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct private_encryption_payload_t private_encryption_payload_t;
|
||||
|
||||
/**
|
||||
@@ -95,32 +92,6 @@ struct private_encryption_payload_t {
|
||||
* Contained payloads of this encrpytion_payload.
|
||||
*/
|
||||
linked_list_t *payloads;
|
||||
|
||||
/**
|
||||
* logger for this payload, uses MESSAGE context
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_encryption_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_encryption_payload_t *this);
|
||||
|
||||
/**
|
||||
* @brief Generate payloads (unencrypted) in chunk decrypted.
|
||||
*
|
||||
* @param this calling private_encryption_payload_t object
|
||||
*/
|
||||
void (*generate) (private_encryption_payload_t *this);
|
||||
|
||||
/**
|
||||
* @brief Parse payloads from a (unencrypted) chunk.
|
||||
*
|
||||
* @param this calling private_encryption_payload_t object
|
||||
*/
|
||||
status_t (*parse) (private_encryption_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -212,389 +183,7 @@ static void set_next_type(private_encryption_payload_t *this, payload_type_t typ
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_encryption_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.create_payload_iterator.
|
||||
*/
|
||||
static iterator_t *create_payload_iterator (private_encryption_payload_t *this, bool forward)
|
||||
{
|
||||
return (this->payloads->create_iterator(this->payloads, forward));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.add_payload.
|
||||
*/
|
||||
static void add_payload(private_encryption_payload_t *this, payload_t *payload)
|
||||
{
|
||||
payload_t *last_payload;
|
||||
if (this->payloads->get_count(this->payloads) > 0)
|
||||
{
|
||||
this->payloads->get_last(this->payloads,(void **) &last_payload);
|
||||
last_payload->set_next_type(last_payload, payload->get_type(payload));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->next_payload = payload->get_type(payload);
|
||||
}
|
||||
payload->set_next_type(payload, NO_PAYLOAD);
|
||||
this->payloads->insert_last(this->payloads, (void*)payload);
|
||||
this->compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.remove_first_payload.
|
||||
*/
|
||||
static status_t remove_first_payload(private_encryption_payload_t *this, payload_t **payload)
|
||||
{
|
||||
return this->payloads->remove_first(this->payloads, (void**)payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.get_payload_count.
|
||||
*/
|
||||
static size_t get_payload_count(private_encryption_payload_t *this)
|
||||
{
|
||||
return this->payloads->get_count(this->payloads);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.encrypt.
|
||||
*/
|
||||
static status_t encrypt(private_encryption_payload_t *this)
|
||||
{
|
||||
chunk_t iv, padding, to_crypt, result;
|
||||
randomizer_t *randomizer;
|
||||
status_t status;
|
||||
size_t block_size;
|
||||
|
||||
if (this->signer == NULL || this->crypter == NULL)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not encrypt, signer/crypter not set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
|
||||
/* for random data in iv and padding */
|
||||
randomizer = randomizer_create();
|
||||
|
||||
|
||||
/* build payload chunk */
|
||||
this->generate(this);
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "encrypting payloads");
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data to encrypt", this->decrypted);
|
||||
|
||||
/* build padding */
|
||||
block_size = this->crypter->get_block_size(this->crypter);
|
||||
padding.len = block_size - ((this->decrypted.len + 1) % block_size);
|
||||
status = randomizer->allocate_pseudo_random_bytes(randomizer, padding.len, &padding);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
randomizer->destroy(randomizer);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* concatenate payload data, padding, padding len */
|
||||
to_crypt.len = this->decrypted.len + padding.len + 1;
|
||||
to_crypt.ptr = malloc(to_crypt.len);
|
||||
|
||||
memcpy(to_crypt.ptr, this->decrypted.ptr, this->decrypted.len);
|
||||
memcpy(to_crypt.ptr + this->decrypted.len, padding.ptr, padding.len);
|
||||
*(to_crypt.ptr + to_crypt.len - 1) = padding.len;
|
||||
|
||||
/* build iv */
|
||||
iv.len = block_size;
|
||||
status = randomizer->allocate_pseudo_random_bytes(randomizer, iv.len, &iv);
|
||||
randomizer->destroy(randomizer);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
chunk_free(&to_crypt);
|
||||
chunk_free(&padding);
|
||||
return status;
|
||||
}
|
||||
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before encryption with padding", to_crypt);
|
||||
|
||||
/* encrypt to_crypt chunk */
|
||||
free(this->encrypted.ptr);
|
||||
status = this->crypter->encrypt(this->crypter, to_crypt, iv, &result);
|
||||
free(padding.ptr);
|
||||
free(to_crypt.ptr);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR|LEVEL1, "encryption failed");
|
||||
free(iv.ptr);
|
||||
return status;
|
||||
}
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after encryption", result);
|
||||
|
||||
|
||||
/* build encrypted result with iv and signature */
|
||||
this->encrypted.len = iv.len + result.len + this->signer->get_block_size(this->signer);
|
||||
free(this->encrypted.ptr);
|
||||
this->encrypted.ptr = malloc(this->encrypted.len);
|
||||
|
||||
/* fill in result, signature is left out */
|
||||
memcpy(this->encrypted.ptr, iv.ptr, iv.len);
|
||||
memcpy(this->encrypted.ptr + iv.len, result.ptr, result.len);
|
||||
|
||||
free(result.ptr);
|
||||
free(iv.ptr);
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after encryption with IV and (invalid) signature", this->encrypted);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.encrypt.
|
||||
*/
|
||||
static status_t decrypt(private_encryption_payload_t *this)
|
||||
{
|
||||
chunk_t iv, concatenated;
|
||||
u_int8_t padding_length;
|
||||
status_t status;
|
||||
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "decrypting encryption payload");
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before decryption with IV and (invalid) signature", this->encrypted);
|
||||
|
||||
|
||||
if (this->signer == NULL || this->crypter == NULL)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not decrypt, no crypter/signer set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
|
||||
/* get IV */
|
||||
iv.len = this->crypter->get_block_size(this->crypter);
|
||||
|
||||
iv.ptr = this->encrypted.ptr;
|
||||
|
||||
/* point concatenated to data + padding + padding_length*/
|
||||
concatenated.ptr = this->encrypted.ptr + iv.len;
|
||||
concatenated.len = this->encrypted.len - iv.len - this->signer->get_block_size(this->signer);
|
||||
|
||||
/* check the size of input:
|
||||
* concatenated must be at least on block_size of crypter
|
||||
*/
|
||||
if (concatenated.len < iv.len)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not decrypt, invalid input");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/* free previus data, if any */
|
||||
free(this->decrypted.ptr);
|
||||
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before decryption", concatenated);
|
||||
|
||||
status = this->crypter->decrypt(this->crypter, concatenated, iv, &(this->decrypted));
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not decrypt, decryption failed");
|
||||
return FAILED;
|
||||
}
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after decryption with padding", this->decrypted);
|
||||
|
||||
|
||||
/* get padding length, sits just bevore signature */
|
||||
padding_length = *(this->decrypted.ptr + this->decrypted.len - 1);
|
||||
/* add one byte to the padding length, since the padding_length field is not included */
|
||||
padding_length++;
|
||||
this->decrypted.len -= padding_length;
|
||||
|
||||
/* check size again */
|
||||
if (padding_length > concatenated.len || this->decrypted.len < 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "decryption failed, invalid padding length found. Invalid key?");
|
||||
/* decryption failed :-/ */
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/* free padding */
|
||||
this->decrypted.ptr = realloc(this->decrypted.ptr, this->decrypted.len);
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after decryption without padding", this->decrypted);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "decryption successful, trying to parse content");
|
||||
return (this->parse(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.set_transforms.
|
||||
*/
|
||||
static void set_transforms(private_encryption_payload_t *this, crypter_t* crypter, signer_t* signer)
|
||||
{
|
||||
this->signer = signer;
|
||||
this->crypter = crypter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.build_signature.
|
||||
*/
|
||||
static status_t build_signature(private_encryption_payload_t *this, chunk_t data)
|
||||
{
|
||||
chunk_t data_without_sig = data;
|
||||
chunk_t sig;
|
||||
|
||||
if (this->signer == NULL)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "unable to build signature, no signer set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
|
||||
sig.len = this->signer->get_block_size(this->signer);
|
||||
data_without_sig.len -= sig.len;
|
||||
sig.ptr = data.ptr + data_without_sig.len;
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "building signature");
|
||||
this->signer->get_signature(this->signer, data_without_sig, sig.ptr);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.verify_signature.
|
||||
*/
|
||||
static status_t verify_signature(private_encryption_payload_t *this, chunk_t data)
|
||||
{
|
||||
chunk_t sig, data_without_sig;
|
||||
bool valid;
|
||||
|
||||
if (this->signer == NULL)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "unable to verify signature, no signer set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
/* find signature in data chunk */
|
||||
sig.len = this->signer->get_block_size(this->signer);
|
||||
if (data.len <= sig.len)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR|LEVEL1, "unable to verify signature, invalid input");
|
||||
return FAILED;
|
||||
}
|
||||
sig.ptr = data.ptr + data.len - sig.len;
|
||||
|
||||
/* verify it */
|
||||
data_without_sig.len = data.len - sig.len;
|
||||
data_without_sig.ptr = data.ptr;
|
||||
valid = this->signer->verify_signature(this->signer, data_without_sig, sig);
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR|LEVEL1, "signature verification failed");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "signature verification successful");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_encryption_payload_t.generate.
|
||||
*/
|
||||
static void generate(private_encryption_payload_t *this)
|
||||
{
|
||||
payload_t *current_payload, *next_payload;
|
||||
generator_t *generator;
|
||||
iterator_t *iterator;
|
||||
|
||||
/* recalculate length before generating */
|
||||
this->compute_length(this);
|
||||
|
||||
/* create iterator */
|
||||
iterator = this->payloads->create_iterator(this->payloads, TRUE);
|
||||
|
||||
/* get first payload */
|
||||
if (iterator->has_next(iterator))
|
||||
{
|
||||
iterator->current(iterator, (void**)¤t_payload);
|
||||
this->next_payload = current_payload->get_type(current_payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no paylads? */
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "generating contained payloads, but no available");
|
||||
free(this->decrypted.ptr);
|
||||
this->decrypted = CHUNK_INITIALIZER;
|
||||
iterator->destroy(iterator);
|
||||
return;
|
||||
}
|
||||
|
||||
generator = generator_create();
|
||||
|
||||
/* build all payload, except last */
|
||||
while(iterator->has_next(iterator))
|
||||
{
|
||||
iterator->current(iterator, (void**)&next_payload);
|
||||
current_payload->set_next_type(current_payload, next_payload->get_type(next_payload));
|
||||
generator->generate_payload(generator, current_payload);
|
||||
current_payload = next_payload;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
/* build last payload */
|
||||
current_payload->set_next_type(current_payload, NO_PAYLOAD);
|
||||
generator->generate_payload(generator, current_payload);
|
||||
|
||||
/* free already generated data */
|
||||
free(this->decrypted.ptr);
|
||||
|
||||
generator->write_to_chunk(generator, &(this->decrypted));
|
||||
generator->destroy(generator);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "successfully generated content in encrpytion payload");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_encryption_payload_t.parse.
|
||||
*/
|
||||
static status_t parse(private_encryption_payload_t *this)
|
||||
{
|
||||
parser_t *parser;
|
||||
status_t status;
|
||||
payload_type_t current_payload_type;
|
||||
|
||||
/* build a parser on the decrypted data */
|
||||
parser = parser_create(this->decrypted);
|
||||
|
||||
current_payload_type = this->next_payload;
|
||||
/* parse all payloads */
|
||||
while (current_payload_type != NO_PAYLOAD)
|
||||
{
|
||||
payload_t *current_payload;
|
||||
|
||||
status = parser->parse_payload(parser, current_payload_type, (payload_t**)¤t_payload);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
parser->destroy(parser);
|
||||
return PARSE_ERROR;
|
||||
}
|
||||
|
||||
status = current_payload->verify(current_payload);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "%s verification failed",
|
||||
mapping_find(payload_type_m,current_payload->get_type(current_payload)));
|
||||
current_payload->destroy(current_payload);
|
||||
parser->destroy(parser);
|
||||
return VERIFY_ERROR;
|
||||
}
|
||||
|
||||
/* get next payload type */
|
||||
current_payload_type = current_payload->get_next_type(current_payload);
|
||||
|
||||
this->payloads->insert_last(this->payloads,current_payload);
|
||||
}
|
||||
parser->destroy(parser);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "succesfully parsed content of encryption payload");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_encryption_payload_t.compute_length.
|
||||
* (re-)compute the lenght of the whole payload
|
||||
*/
|
||||
static void compute_length(private_encryption_payload_t *this)
|
||||
{
|
||||
@@ -627,6 +216,384 @@ static void compute_length(private_encryption_payload_t *this)
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_encryption_payload_t *this)
|
||||
{
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.create_payload_iterator.
|
||||
*/
|
||||
static iterator_t *create_payload_iterator (private_encryption_payload_t *this, bool forward)
|
||||
{
|
||||
return (this->payloads->create_iterator(this->payloads, forward));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.add_payload.
|
||||
*/
|
||||
static void add_payload(private_encryption_payload_t *this, payload_t *payload)
|
||||
{
|
||||
payload_t *last_payload;
|
||||
if (this->payloads->get_count(this->payloads) > 0)
|
||||
{
|
||||
this->payloads->get_last(this->payloads,(void **) &last_payload);
|
||||
last_payload->set_next_type(last_payload, payload->get_type(payload));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->next_payload = payload->get_type(payload);
|
||||
}
|
||||
payload->set_next_type(payload, NO_PAYLOAD);
|
||||
this->payloads->insert_last(this->payloads, (void*)payload);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.remove_first_payload.
|
||||
*/
|
||||
static status_t remove_first_payload(private_encryption_payload_t *this, payload_t **payload)
|
||||
{
|
||||
return this->payloads->remove_first(this->payloads, (void**)payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.get_payload_count.
|
||||
*/
|
||||
static size_t get_payload_count(private_encryption_payload_t *this)
|
||||
{
|
||||
return this->payloads->get_count(this->payloads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate payload before encryption.
|
||||
*/
|
||||
static void generate(private_encryption_payload_t *this)
|
||||
{
|
||||
payload_t *current_payload, *next_payload;
|
||||
generator_t *generator;
|
||||
iterator_t *iterator;
|
||||
|
||||
/* recalculate length before generating */
|
||||
compute_length(this);
|
||||
|
||||
/* create iterator */
|
||||
iterator = this->payloads->create_iterator(this->payloads, TRUE);
|
||||
|
||||
/* get first payload */
|
||||
if (iterator->has_next(iterator))
|
||||
{
|
||||
iterator->current(iterator, (void**)¤t_payload);
|
||||
this->next_payload = current_payload->get_type(current_payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no paylads? */
|
||||
DBG2(SIG_DBG_ENC, "generating contained payloads, but none available");
|
||||
free(this->decrypted.ptr);
|
||||
this->decrypted = CHUNK_INITIALIZER;
|
||||
iterator->destroy(iterator);
|
||||
return;
|
||||
}
|
||||
|
||||
generator = generator_create();
|
||||
|
||||
/* build all payload, except last */
|
||||
while(iterator->has_next(iterator))
|
||||
{
|
||||
iterator->current(iterator, (void**)&next_payload);
|
||||
current_payload->set_next_type(current_payload, next_payload->get_type(next_payload));
|
||||
generator->generate_payload(generator, current_payload);
|
||||
current_payload = next_payload;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
/* build last payload */
|
||||
current_payload->set_next_type(current_payload, NO_PAYLOAD);
|
||||
generator->generate_payload(generator, current_payload);
|
||||
|
||||
/* free already generated data */
|
||||
free(this->decrypted.ptr);
|
||||
|
||||
generator->write_to_chunk(generator, &(this->decrypted));
|
||||
generator->destroy(generator);
|
||||
DBG2(SIG_DBG_ENC, "successfully generated content in encryption payload");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.encrypt.
|
||||
*/
|
||||
static status_t encrypt(private_encryption_payload_t *this)
|
||||
{
|
||||
chunk_t iv, padding, to_crypt, result;
|
||||
randomizer_t *randomizer;
|
||||
status_t status;
|
||||
size_t block_size;
|
||||
|
||||
if (this->signer == NULL || this->crypter == NULL)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "could not encrypt, signer/crypter not set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
|
||||
/* for random data in iv and padding */
|
||||
randomizer = randomizer_create();
|
||||
|
||||
/* build payload chunk */
|
||||
generate(this);
|
||||
|
||||
DBG2(SIG_DBG_ENC, "encrypting payloads");
|
||||
DBG3(SIG_DBG_ENC, "data to encrypt %B", &this->decrypted);
|
||||
|
||||
/* build padding */
|
||||
block_size = this->crypter->get_block_size(this->crypter);
|
||||
padding.len = block_size - ((this->decrypted.len + 1) % block_size);
|
||||
status = randomizer->allocate_pseudo_random_bytes(randomizer, padding.len, &padding);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
randomizer->destroy(randomizer);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* concatenate payload data, padding, padding len */
|
||||
to_crypt.len = this->decrypted.len + padding.len + 1;
|
||||
to_crypt.ptr = malloc(to_crypt.len);
|
||||
|
||||
memcpy(to_crypt.ptr, this->decrypted.ptr, this->decrypted.len);
|
||||
memcpy(to_crypt.ptr + this->decrypted.len, padding.ptr, padding.len);
|
||||
*(to_crypt.ptr + to_crypt.len - 1) = padding.len;
|
||||
|
||||
/* build iv */
|
||||
iv.len = block_size;
|
||||
status = randomizer->allocate_pseudo_random_bytes(randomizer, iv.len, &iv);
|
||||
randomizer->destroy(randomizer);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
chunk_free(&to_crypt);
|
||||
chunk_free(&padding);
|
||||
return status;
|
||||
}
|
||||
|
||||
DBG3(SIG_DBG_ENC, "data before encryption with padding %B", &to_crypt);
|
||||
|
||||
/* encrypt to_crypt chunk */
|
||||
free(this->encrypted.ptr);
|
||||
status = this->crypter->encrypt(this->crypter, to_crypt, iv, &result);
|
||||
free(padding.ptr);
|
||||
free(to_crypt.ptr);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG2(SIG_DBG_ENC, "encryption failed");
|
||||
free(iv.ptr);
|
||||
return status;
|
||||
}
|
||||
DBG3(SIG_DBG_ENC, "data after encryption %B", &result);
|
||||
|
||||
/* build encrypted result with iv and signature */
|
||||
this->encrypted.len = iv.len + result.len + this->signer->get_block_size(this->signer);
|
||||
free(this->encrypted.ptr);
|
||||
this->encrypted.ptr = malloc(this->encrypted.len);
|
||||
|
||||
/* fill in result, signature is left out */
|
||||
memcpy(this->encrypted.ptr, iv.ptr, iv.len);
|
||||
memcpy(this->encrypted.ptr + iv.len, result.ptr, result.len);
|
||||
|
||||
free(result.ptr);
|
||||
free(iv.ptr);
|
||||
DBG3(SIG_DBG_ENC, "data after encryption with IV and (invalid) signature %B",
|
||||
&this->encrypted);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the payloads after decryption.
|
||||
*/
|
||||
static status_t parse(private_encryption_payload_t *this)
|
||||
{
|
||||
parser_t *parser;
|
||||
status_t status;
|
||||
payload_type_t current_payload_type;
|
||||
|
||||
/* build a parser on the decrypted data */
|
||||
parser = parser_create(this->decrypted);
|
||||
|
||||
current_payload_type = this->next_payload;
|
||||
/* parse all payloads */
|
||||
while (current_payload_type != NO_PAYLOAD)
|
||||
{
|
||||
payload_t *current_payload;
|
||||
|
||||
status = parser->parse_payload(parser, current_payload_type, (payload_t**)¤t_payload);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
parser->destroy(parser);
|
||||
return PARSE_ERROR;
|
||||
}
|
||||
|
||||
status = current_payload->verify(current_payload);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "%N verification failed",
|
||||
payload_type_names, current_payload->get_type(current_payload));
|
||||
current_payload->destroy(current_payload);
|
||||
parser->destroy(parser);
|
||||
return VERIFY_ERROR;
|
||||
}
|
||||
|
||||
/* get next payload type */
|
||||
current_payload_type = current_payload->get_next_type(current_payload);
|
||||
|
||||
this->payloads->insert_last(this->payloads,current_payload);
|
||||
}
|
||||
parser->destroy(parser);
|
||||
DBG2(SIG_DBG_ENC, "succesfully parsed content of encryption payload");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.encrypt.
|
||||
*/
|
||||
static status_t decrypt(private_encryption_payload_t *this)
|
||||
{
|
||||
chunk_t iv, concatenated;
|
||||
u_int8_t padding_length;
|
||||
status_t status;
|
||||
|
||||
DBG2(SIG_DBG_ENC, "decrypting encryption payload");
|
||||
DBG3(SIG_DBG_ENC, "data before decryption with IV and (invalid) signature %B",
|
||||
&this->encrypted);
|
||||
|
||||
if (this->signer == NULL || this->crypter == NULL)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "could not decrypt, no crypter/signer set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
|
||||
/* get IV */
|
||||
iv.len = this->crypter->get_block_size(this->crypter);
|
||||
|
||||
iv.ptr = this->encrypted.ptr;
|
||||
|
||||
/* point concatenated to data + padding + padding_length*/
|
||||
concatenated.ptr = this->encrypted.ptr + iv.len;
|
||||
concatenated.len = this->encrypted.len - iv.len - this->signer->get_block_size(this->signer);
|
||||
|
||||
/* check the size of input:
|
||||
* concatenated must be at least on block_size of crypter
|
||||
*/
|
||||
if (concatenated.len < iv.len)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "could not decrypt, invalid input");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/* free previus data, if any */
|
||||
free(this->decrypted.ptr);
|
||||
|
||||
DBG3(SIG_DBG_ENC, "data before decryption %B", &concatenated);
|
||||
|
||||
status = this->crypter->decrypt(this->crypter, concatenated, iv, &(this->decrypted));
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "could not decrypt, decryption failed");
|
||||
return FAILED;
|
||||
}
|
||||
DBG3(SIG_DBG_ENC, "data after decryption with padding %B", &this->decrypted);
|
||||
|
||||
|
||||
/* get padding length, sits just bevore signature */
|
||||
padding_length = *(this->decrypted.ptr + this->decrypted.len - 1);
|
||||
/* add one byte to the padding length, since the padding_length field is not included */
|
||||
padding_length++;
|
||||
this->decrypted.len -= padding_length;
|
||||
|
||||
/* check size again */
|
||||
if (padding_length > concatenated.len || this->decrypted.len < 0)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "decryption failed, invalid padding length found. Invalid key?");
|
||||
/* decryption failed :-/ */
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/* free padding */
|
||||
this->decrypted.ptr = realloc(this->decrypted.ptr, this->decrypted.len);
|
||||
DBG3(SIG_DBG_ENC, "data after decryption without padding %B", &this->decrypted);
|
||||
DBG2(SIG_DBG_ENC, "decryption successful, trying to parse content");
|
||||
return parse(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.set_transforms.
|
||||
*/
|
||||
static void set_transforms(private_encryption_payload_t *this, crypter_t* crypter, signer_t* signer)
|
||||
{
|
||||
this->signer = signer;
|
||||
this->crypter = crypter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.build_signature.
|
||||
*/
|
||||
static status_t build_signature(private_encryption_payload_t *this, chunk_t data)
|
||||
{
|
||||
chunk_t data_without_sig = data;
|
||||
chunk_t sig;
|
||||
|
||||
if (this->signer == NULL)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "unable to build signature, no signer set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
|
||||
sig.len = this->signer->get_block_size(this->signer);
|
||||
data_without_sig.len -= sig.len;
|
||||
sig.ptr = data.ptr + data_without_sig.len;
|
||||
DBG2(SIG_DBG_ENC, "building signature");
|
||||
this->signer->get_signature(this->signer, data_without_sig, sig.ptr);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of encryption_payload_t.verify_signature.
|
||||
*/
|
||||
static status_t verify_signature(private_encryption_payload_t *this, chunk_t data)
|
||||
{
|
||||
chunk_t sig, data_without_sig;
|
||||
bool valid;
|
||||
|
||||
if (this->signer == NULL)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "unable to verify signature, no signer set");
|
||||
return INVALID_STATE;
|
||||
}
|
||||
/* find signature in data chunk */
|
||||
sig.len = this->signer->get_block_size(this->signer);
|
||||
if (data.len <= sig.len)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "unable to verify signature, invalid input");
|
||||
return FAILED;
|
||||
}
|
||||
sig.ptr = data.ptr + data.len - sig.len;
|
||||
|
||||
/* verify it */
|
||||
data_without_sig.len = data.len - sig.len;
|
||||
data_without_sig.ptr = data.ptr;
|
||||
valid = this->signer->verify_signature(this->signer, data_without_sig, sig);
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
DBG1(SIG_DBG_ENC, "signature verification failed");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
DBG2(SIG_DBG_ENC, "signature verification successful");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.destroy.
|
||||
@@ -675,12 +642,6 @@ encryption_payload_t *encryption_payload_create()
|
||||
this->public.verify_signature = (status_t (*) (encryption_payload_t*, chunk_t)) verify_signature;
|
||||
this->public.destroy = (void (*) (encryption_payload_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
this->generate = generate;
|
||||
this->parse = parse;
|
||||
this->logger = logger_manager->get_logger(logger_manager, ENCRYPTION_PAYLOAD);
|
||||
|
||||
/* set default values of the fields */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
|
||||
@@ -100,19 +100,16 @@ struct private_ike_header_t {
|
||||
* Length of the whole IKEv2-Message (header and all payloads).
|
||||
*/
|
||||
u_int32_t length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mappings used to get strings for exchange_type_t.
|
||||
*/
|
||||
mapping_t exchange_type_m[] = {
|
||||
{EXCHANGE_TYPE_UNDEFINED, "EXCHANGE_TYPE_UNDEFINED"},
|
||||
{IKE_SA_INIT, "IKE_SA_INIT"},
|
||||
{IKE_AUTH, "IKE_AUTH"},
|
||||
{CREATE_CHILD_SA, "CREATE_CHILD_SA"},
|
||||
{INFORMATIONAL, "INFORMATIONAL"}
|
||||
};
|
||||
|
||||
ENUM_BEGIN(exchange_type_names, EXCHANGE_TYPE_UNDEFINED, EXCHANGE_TYPE_UNDEFINED,
|
||||
"EXCHANGE_TYPE_UNDEFINED");
|
||||
ENUM_NEXT(exchange_type_names, IKE_SA_INIT, INFORMATIONAL, EXCHANGE_TYPE_UNDEFINED,
|
||||
"IKE_SA_INIT",
|
||||
"IKE_AUTH",
|
||||
"CREATE_CHILD_SA",
|
||||
"INFORMATIONAL");
|
||||
ENUM_END(exchange_type_names, INFORMATIONAL);
|
||||
|
||||
/**
|
||||
* Encoding rules to parse or generate a IKEv2-Header.
|
||||
|
||||
@@ -93,11 +93,11 @@ enum exchange_type_t{
|
||||
};
|
||||
|
||||
/**
|
||||
* string mappings for exchange_type_t
|
||||
* enum name for exchange_type_t
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern mapping_t exchange_type_m[];
|
||||
extern enum_name_t *exchange_type_names;
|
||||
|
||||
|
||||
typedef struct ike_header_t ike_header_t;
|
||||
|
||||
@@ -64,13 +64,6 @@ struct private_ke_payload_t {
|
||||
* Key Exchange Data of this KE payload.
|
||||
*/
|
||||
chunk_t key_exchange_data;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_ke_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_ke_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -172,18 +165,9 @@ static void set_next_type(private_ke_payload_t *this,payload_type_t type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
* recompute the length of the payload.
|
||||
*/
|
||||
static size_t get_length(private_ke_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_ke_payload_t.compute_length.
|
||||
*/
|
||||
static void compute_length (private_ke_payload_t *this)
|
||||
static void compute_length(private_ke_payload_t *this)
|
||||
{
|
||||
size_t length = KE_PAYLOAD_HEADER_LENGTH;
|
||||
if (this->key_exchange_data.ptr != NULL)
|
||||
@@ -193,6 +177,14 @@ static void compute_length (private_ke_payload_t *this)
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_ke_payload_t *this)
|
||||
{
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ke_payload_t.get_key_exchange_data.
|
||||
@@ -218,7 +210,7 @@ static void set_key_exchange_data(private_ke_payload_t *this, chunk_t key_exchan
|
||||
}
|
||||
|
||||
this->key_exchange_data = chunk_clone(key_exchange_data);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,9 +252,6 @@ ke_payload_t *ke_payload_create()
|
||||
this->public.set_dh_group_number =(void (*) (ke_payload_t *,diffie_hellman_group_t)) set_dh_group_number;
|
||||
this->public.destroy = (void (*) (ke_payload_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* set default values of the fields */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
@@ -282,7 +271,7 @@ ke_payload_t *ke_payload_create_from_diffie_hellman(diffie_hellman_t *dh)
|
||||
|
||||
dh->get_my_public_value(dh, &this->key_exchange_data);
|
||||
this->dh_group_number = dh->get_dh_group(dh);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -60,13 +60,6 @@ struct private_nonce_payload_t {
|
||||
* The contained nonce value.
|
||||
*/
|
||||
chunk_t nonce;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_nonce_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_nonce_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -176,22 +169,22 @@ static void set_next_type(private_nonce_payload_t *this,payload_type_t type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_nonce_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_id_payload_t.compute_length.
|
||||
* recompute the length of the payload.
|
||||
*/
|
||||
static void compute_length(private_nonce_payload_t *this)
|
||||
{
|
||||
this->payload_length = NONCE_PAYLOAD_HEADER_LENGTH + this->nonce.len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_nonce_payload_t *this)
|
||||
{
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.destroy and nonce_payload_t.destroy.
|
||||
*/
|
||||
@@ -226,9 +219,6 @@ nonce_payload_t *nonce_payload_create()
|
||||
this->public.set_nonce = (void (*) (nonce_payload_t *,chunk_t)) set_nonce;
|
||||
this->public.get_nonce = (chunk_t (*) (nonce_payload_t *)) get_nonce;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* private variables */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
|
||||
@@ -28,50 +28,54 @@
|
||||
|
||||
#include <daemon.h>
|
||||
#include <encoding/payloads/encodings.h>
|
||||
#include <crypto/hashers/hasher.h>
|
||||
|
||||
#define SHA1_HASH_SIZE 20
|
||||
|
||||
/**
|
||||
* String mappings for notify_type_t.
|
||||
*/
|
||||
mapping_t notify_type_m[] = {
|
||||
{UNSUPPORTED_CRITICAL_PAYLOAD, "UNSUPPORTED_CRITICAL_PAYLOAD"},
|
||||
{INVALID_IKE_SPI, "INVALID_IKE_SPI"},
|
||||
{INVALID_MAJOR_VERSION, "INVALID_MAJOR_VERSION"},
|
||||
{INVALID_SYNTAX, "INVALID_SYNTAX"},
|
||||
{INVALID_MESSAGE_ID, "INVALID_MESSAGE_ID"},
|
||||
{INVALID_SPI, "INVALID_SPI"},
|
||||
{NO_PROPOSAL_CHOSEN, "NO_PROPOSAL_CHOSEN"},
|
||||
{INVALID_KE_PAYLOAD, "INVALID_KE_PAYLOAD"},
|
||||
{AUTHENTICATION_FAILED, "AUTHENTICATION_FAILED"},
|
||||
{SINGLE_PAIR_REQUIRED, "SINGLE_PAIR_REQUIRED"},
|
||||
{NO_ADDITIONAL_SAS, "NO_ADDITIONAL_SAS"},
|
||||
{INTERNAL_ADDRESS_FAILURE, "INTERNAL_ADDRESS_FAILURE"},
|
||||
{FAILED_CP_REQUIRED, "FAILED_CP_REQUIRED"},
|
||||
{TS_UNACCEPTABLE, "TS_UNACCEPTABLE"},
|
||||
{INVALID_SELECTORS, "INVALID_SELECTORS"},
|
||||
{INITIAL_CONTACT, "INITIAL_CONTACT"},
|
||||
{SET_WINDOW_SIZE, "SET_WINDOW_SIZE"},
|
||||
{ADDITIONAL_TS_POSSIBLE, "ADDITIONAL_TS_POSSIBLE"},
|
||||
{IPCOMP_SUPPORTED, "IPCOMP_SUPPORTED"},
|
||||
{NAT_DETECTION_SOURCE_IP, "NAT_DETECTION_SOURCE_IP"},
|
||||
{NAT_DETECTION_DESTINATION_IP, "NAT_DETECTION_DESTINATION_IP"},
|
||||
{COOKIE, "COOKIE"},
|
||||
{USE_TRANSPORT_MODE, "USE_TRANSPORT_MODE"},
|
||||
{HTTP_CERT_LOOKUP_SUPPORTED, "HTTP_CERT_LOOKUP_SUPPORTED"},
|
||||
{REKEY_SA, "REKEY_SA"},
|
||||
{ESP_TFC_PADDING_NOT_SUPPORTED, "ESP_TFC_PADDING_NOT_SUPPORTED"},
|
||||
{NON_FIRST_FRAGMENTS_ALSO, "NON_FIRST_FRAGMENTS_ALSO"},
|
||||
{MOBIKE_SUPPORTED, "MOBIKE_SUPPORTED"},
|
||||
{ADDITIONAL_IP4_ADDRESS, "ADDITIONAL_IP4_ADDRESS"},
|
||||
{ADDITIONAL_IP6_ADDRESS, "ADDITIONAL_IP6_ADDRESS"},
|
||||
{NO_ADDITIONAL_ADDRESSES, "NO_ADDITIONAL_ADDRESSES"},
|
||||
{UPDATE_SA_ADDRESSES, "UPDATE_SA_ADDRESSES"},
|
||||
{COOKIE2, "COOKIE2"},
|
||||
{NO_NATS_ALLOWED, "NO_NATS_ALLOWED"},
|
||||
{AUTH_LIFETIME, "AUTH_LIFETIME"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
ENUM_BEGIN(notify_type_names, UNSUPPORTED_CRITICAL_PAYLOAD, UNSUPPORTED_CRITICAL_PAYLOAD,
|
||||
"UNSUPPORTED_CRITICAL_PAYLOAD");
|
||||
ENUM_NEXT(notify_type_names, INVALID_IKE_SPI, INVALID_MAJOR_VERSION, UNSUPPORTED_CRITICAL_PAYLOAD,
|
||||
"INVALID_IKE_SPI",
|
||||
"INVALID_MAJOR_VERSION");
|
||||
ENUM_NEXT(notify_type_names, INVALID_SYNTAX, INVALID_SYNTAX, INVALID_MAJOR_VERSION,
|
||||
"INVALID_SYNTAX");
|
||||
ENUM_NEXT(notify_type_names, INVALID_MESSAGE_ID, INVALID_MESSAGE_ID, INVALID_SYNTAX,
|
||||
"INVALID_MESSAGE_ID");
|
||||
ENUM_NEXT(notify_type_names, INVALID_SPI, INVALID_SPI, INVALID_MESSAGE_ID,
|
||||
"INVALID_SPI");
|
||||
ENUM_NEXT(notify_type_names, NO_PROPOSAL_CHOSEN, NO_PROPOSAL_CHOSEN, INVALID_SPI,
|
||||
"NO_PROPOSAL_CHOSEN");
|
||||
ENUM_NEXT(notify_type_names, INVALID_KE_PAYLOAD, INVALID_KE_PAYLOAD, NO_PROPOSAL_CHOSEN,
|
||||
"INVALID_KE_PAYLOAD");
|
||||
ENUM_NEXT(notify_type_names, AUTHENTICATION_FAILED, AUTHENTICATION_FAILED, INVALID_KE_PAYLOAD,
|
||||
"AUTHENTICATION_FAILED");
|
||||
ENUM_NEXT(notify_type_names, SINGLE_PAIR_REQUIRED, INVALID_SELECTORS, AUTHENTICATION_FAILED,
|
||||
"SINGLE_PAIR_REQUIRED",
|
||||
"NO_ADDITIONAL_SAS",
|
||||
"INTERNAL_ADDRESS_FAILURE",
|
||||
"FAILED_CP_REQUIRED",
|
||||
"TS_UNACCEPTABLE",
|
||||
"INVALID_SELECTORS");
|
||||
ENUM_NEXT(notify_type_names, INITIAL_CONTACT, AUTH_LIFETIME, INVALID_SELECTORS,
|
||||
"INITIAL_CONTACT",
|
||||
"SET_WINDOW_SIZE",
|
||||
"ADDITIONAL_TS_POSSIBLE",
|
||||
"IPCOMP_SUPPORTED",
|
||||
"NAT_DETECTION_SOURCE_IP",
|
||||
"NAT_DETECTION_DESTINATION_IP",
|
||||
"COOKIE",
|
||||
"USE_TRANSPORT_MODE",
|
||||
"HTTP_CERT_LOOKUP_SUPPORTED",
|
||||
"REKEY_SA",
|
||||
"ESP_TFC_PADDING_NOT_SUPPORTED",
|
||||
"NON_FIRST_FRAGMENTS_ALSO",
|
||||
"MOBIKE_SUPPORTED",
|
||||
"ADDITIONAL_IP4_ADDRESS",
|
||||
"ADDITIONAL_IP6_ADDRESS",
|
||||
"NO_ADDITIONAL_ADDRESSES",
|
||||
"UPDATE_SA_ADDRESSES",
|
||||
"COOKIE2",
|
||||
"NO_NATS_ALLOWED",
|
||||
"AUTH_LIFETIME");
|
||||
ENUM_END(notify_type_names, AUTH_LIFETIME);
|
||||
|
||||
typedef struct private_notify_payload_t private_notify_payload_t;
|
||||
|
||||
@@ -124,18 +128,6 @@ struct private_notify_payload_t {
|
||||
* Notification data.
|
||||
*/
|
||||
chunk_t notification_data;
|
||||
|
||||
/**
|
||||
* Assigned logger
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_ke_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_notify_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -204,13 +196,13 @@ static status_t verify(private_notify_payload_t *this)
|
||||
case PROTO_ESP:
|
||||
if (this->spi.len != 4)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "Invalid SPI size for %s",
|
||||
mapping_find(protocol_id_m, this->protocol_id));
|
||||
DBG1(SIG_DBG_ENC, "Invalid SPI size for %N",
|
||||
protocol_id_names, this->protocol_id);
|
||||
return FAILED;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this->logger->log(this->logger, ERROR, "Unknown protocol (%d)", this->protocol_id);
|
||||
DBG1(SIG_DBG_ENC, "Unknown protocol (%d)", this->protocol_id);
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -237,7 +229,7 @@ static status_t verify(private_notify_payload_t *this)
|
||||
case MODP_8192_BIT:
|
||||
break;
|
||||
default:
|
||||
this->logger->log(this->logger, ERROR, "Bad DH group (%d)", dh_group);
|
||||
DBG1(SIG_DBG_ENC, "Bad DH group (%d)", dh_group);
|
||||
return FAILED;
|
||||
}
|
||||
break;
|
||||
@@ -245,10 +237,10 @@ static status_t verify(private_notify_payload_t *this)
|
||||
case NAT_DETECTION_SOURCE_IP:
|
||||
case NAT_DETECTION_DESTINATION_IP:
|
||||
{
|
||||
if (this->notification_data.len != SHA1_HASH_SIZE)
|
||||
if (this->notification_data.len != HASH_SIZE_SHA1)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "invalid %s notify length",
|
||||
mapping_find(notify_type_m, this->notify_type));
|
||||
DBG1(SIG_DBG_ENC, "invalid %N notify length",
|
||||
notify_type_names, this->notify_type);
|
||||
return FAILED;
|
||||
}
|
||||
break;
|
||||
@@ -259,8 +251,8 @@ static status_t verify(private_notify_payload_t *this)
|
||||
{
|
||||
if (this->notification_data.len != 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "invalid %s notify",
|
||||
mapping_find(notify_type_m, this->notify_type));
|
||||
DBG1(SIG_DBG_ENC, "invalid %N notify",
|
||||
notify_type_names, this->notify_type);
|
||||
return FAILED;
|
||||
}
|
||||
break;
|
||||
@@ -306,16 +298,7 @@ static void set_next_type(private_notify_payload_t *this,payload_type_t type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_notify_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_notify_payload_t.compute_length.
|
||||
* recompute the payloads length.
|
||||
*/
|
||||
static void compute_length (private_notify_payload_t *this)
|
||||
{
|
||||
@@ -331,6 +314,15 @@ static void compute_length (private_notify_payload_t *this)
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_notify_payload_t *this)
|
||||
{
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of notify_payload_t.get_protocol_id.
|
||||
*/
|
||||
@@ -395,7 +387,7 @@ static void set_spi(private_notify_payload_t *this, u_int32_t spi)
|
||||
break;
|
||||
}
|
||||
this->spi_size = this->spi.len;
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,7 +405,7 @@ static status_t set_notification_data(private_notify_payload_t *this, chunk_t no
|
||||
{
|
||||
chunk_free(&this->notification_data);
|
||||
this->notification_data = chunk_clone(notification_data);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -455,9 +447,6 @@ notify_payload_t *notify_payload_create()
|
||||
this->public.set_notification_data = (void (*) (notify_payload_t *,chunk_t)) set_notification_data;
|
||||
this->public.destroy = (void (*) (notify_payload_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* set default values of the fields */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
@@ -469,8 +458,7 @@ notify_payload_t *notify_payload_create()
|
||||
this->spi_size = 0;
|
||||
this->notification_data.ptr = NULL;
|
||||
this->notification_data.len = 0;
|
||||
this->logger = logger_manager->get_logger(logger_manager, PAYLOAD);
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,12 +90,12 @@ enum notify_type_t {
|
||||
AUTH_LIFETIME = 16403,
|
||||
};
|
||||
|
||||
/**
|
||||
* String mappings for notify_type_t.
|
||||
*
|
||||
/**
|
||||
* enum name for notify_type_t.
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern mapping_t notify_type_m[];
|
||||
extern enum_name_t *notify_type_names;
|
||||
|
||||
|
||||
typedef struct notify_payload_t notify_payload_t;
|
||||
|
||||
@@ -43,67 +43,65 @@
|
||||
#include <encoding/payloads/eap_payload.h>
|
||||
#include <encoding/payloads/unknown_payload.h>
|
||||
|
||||
/*
|
||||
* build the mappings for payload_type_t
|
||||
*/
|
||||
mapping_t payload_type_m[] = {
|
||||
{NO_PAYLOAD, "NO_PAYLOAD"},
|
||||
{SECURITY_ASSOCIATION, "SECURITY_ASSOCIATION"},
|
||||
{KEY_EXCHANGE, "KEY_EXCHANGE"},
|
||||
{ID_INITIATOR, "ID_INITIATOR"},
|
||||
{ID_RESPONDER, "ID_RESPONDER"},
|
||||
{CERTIFICATE, "CERTIFICATE"},
|
||||
{CERTIFICATE_REQUEST, "CERTIFICATE_REQUEST"},
|
||||
{AUTHENTICATION, "AUTHENTICATION"},
|
||||
{NONCE, "NONCE"},
|
||||
{NOTIFY, "NOTIFY"},
|
||||
{DELETE, "DELETE"},
|
||||
{VENDOR_ID, "VENDOR_ID"},
|
||||
{TRAFFIC_SELECTOR_INITIATOR, "TRAFFIC_SELECTOR_INITIATOR"},
|
||||
{TRAFFIC_SELECTOR_RESPONDER, "TRAFFIC_SELECTOR_RESPONDER"},
|
||||
{ENCRYPTED, "ENCRYPTED"},
|
||||
{CONFIGURATION, "CONFIGURATION"},
|
||||
{EXTENSIBLE_AUTHENTICATION, "EXTENSIBLE_AUTHENTICATION"},
|
||||
{HEADER, "HEADER"},
|
||||
{PROPOSAL_SUBSTRUCTURE, "PROPOSAL_SUBSTRUCTURE"},
|
||||
{TRANSFORM_SUBSTRUCTURE, "TRANSFORM_SUBSTRUCTURE"},
|
||||
{TRANSFORM_ATTRIBUTE, "TRANSFORM_ATTRIBUTE"},
|
||||
{TRAFFIC_SELECTOR_SUBSTRUCTURE, "TRAFFIC_SELECTOR_SUBSTRUCTURE"},
|
||||
{CONFIGURATION_ATTRIBUTE,"CONFIGURATION_ATTRIBUTE"},
|
||||
{UNKNOWN_PAYLOAD,"UNKNOWN_PAYLOAD"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* build the short mappings for payload_type_t
|
||||
*/
|
||||
mapping_t payload_type_short_m[] = {
|
||||
{NO_PAYLOAD, "--"},
|
||||
{SECURITY_ASSOCIATION, "SA"},
|
||||
{KEY_EXCHANGE, "KE"},
|
||||
{ID_INITIATOR, "IDi"},
|
||||
{ID_RESPONDER, "IDr"},
|
||||
{CERTIFICATE, "CERT"},
|
||||
{CERTIFICATE_REQUEST, "CERTREQ"},
|
||||
{AUTHENTICATION, "AUTH"},
|
||||
{NONCE, "No"},
|
||||
{NOTIFY, "N"},
|
||||
{DELETE, "D"},
|
||||
{VENDOR_ID, "V"},
|
||||
{TRAFFIC_SELECTOR_INITIATOR, "TSi"},
|
||||
{TRAFFIC_SELECTOR_RESPONDER, "TSr"},
|
||||
{ENCRYPTED, "E"},
|
||||
{CONFIGURATION, "CP"},
|
||||
{EXTENSIBLE_AUTHENTICATION, "EAP"},
|
||||
{HEADER, "HDR"},
|
||||
{PROPOSAL_SUBSTRUCTURE, "PROP"},
|
||||
{TRANSFORM_SUBSTRUCTURE, "TRANS"},
|
||||
{TRANSFORM_ATTRIBUTE, "TRANSATTR"},
|
||||
{TRAFFIC_SELECTOR_SUBSTRUCTURE, "TSSUB"},
|
||||
{CONFIGURATION_ATTRIBUTE, "CPATTR"},
|
||||
{UNKNOWN_PAYLOAD, "??"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
ENUM_BEGIN(payload_type_names, NO_PAYLOAD, NO_PAYLOAD,
|
||||
"NO_PAYLOAD");
|
||||
ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
|
||||
"SECURITY_ASSOCIATION",
|
||||
"KEY_EXCHANGE",
|
||||
"ID_INITIATOR",
|
||||
"ID_RESPONDER",
|
||||
"CERTIFICATE",
|
||||
"CERTIFICATE_REQUEST",
|
||||
"AUTHENTICATION",
|
||||
"NONCE",
|
||||
"NOTIFY",
|
||||
"DELETE",
|
||||
"VENDOR_ID",
|
||||
"TRAFFIC_SELECTOR_INITIATOR",
|
||||
"TRAFFIC_SELECTOR_RESPONDER",
|
||||
"ENCRYPTED",
|
||||
"CONFIGURATION",
|
||||
"EXTENSIBLE_AUTHENTICATION");
|
||||
ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
|
||||
"HEADER",
|
||||
"PROPOSAL_SUBSTRUCTURE",
|
||||
"TRANSFORM_SUBSTRUCTURE",
|
||||
"TRANSFORM_ATTRIBUTE",
|
||||
"TRAFFIC_SELECTOR_SUBSTRUCTURE",
|
||||
"CONFIGURATION_ATTRIBUTE",
|
||||
"UNKNOWN_PAYLOAD");
|
||||
ENUM_END(payload_type_names, UNKNOWN_PAYLOAD);
|
||||
|
||||
/* short forms of payload names */
|
||||
ENUM_BEGIN(payload_type_short_names, NO_PAYLOAD, NO_PAYLOAD,
|
||||
"--");
|
||||
ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
|
||||
"SA",
|
||||
"KE",
|
||||
"IDi",
|
||||
"IDr",
|
||||
"CERT",
|
||||
"CERTREQ",
|
||||
"AUTH",
|
||||
"No",
|
||||
"N",
|
||||
"D",
|
||||
"V",
|
||||
"TSi",
|
||||
"TSr",
|
||||
"E",
|
||||
"CP",
|
||||
"EAP");
|
||||
ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
|
||||
"HDR",
|
||||
"PROP",
|
||||
"TRANS",
|
||||
"TRANSATTR",
|
||||
"TSSUB",
|
||||
"CPATTR",
|
||||
"??");
|
||||
ENUM_END(payload_type_short_names, UNKNOWN_PAYLOAD);
|
||||
|
||||
/*
|
||||
* see header
|
||||
|
||||
@@ -185,14 +185,14 @@ enum payload_type_t{
|
||||
|
||||
|
||||
/**
|
||||
* String mappings for payload_type_t.
|
||||
* enum names for payload_type_t.
|
||||
*/
|
||||
extern mapping_t payload_type_m[];
|
||||
extern enum_name_t *payload_type_names;
|
||||
|
||||
/**
|
||||
* Special string mappings for payload_type_t in a short form.
|
||||
* enum names for payload_type_t in a short form.
|
||||
*/
|
||||
extern mapping_t payload_type_short_m[];
|
||||
extern enum_name_t *payload_type_short_names;
|
||||
|
||||
|
||||
typedef struct payload_t payload_t;
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <encoding/payloads/transform_substructure.h>
|
||||
#include <types.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/logger_manager.h>
|
||||
#include <daemon.h>
|
||||
|
||||
|
||||
/**
|
||||
@@ -89,18 +89,6 @@ struct private_proposal_substructure_t {
|
||||
* Transforms are stored in a linked_list_t.
|
||||
*/
|
||||
linked_list_t * transforms;
|
||||
|
||||
/**
|
||||
* assigned logger
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this substructure.
|
||||
*
|
||||
* @param this calling private_proposal_substructure_t object
|
||||
*/
|
||||
void (*compute_length) (private_proposal_substructure_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -158,13 +146,13 @@ static status_t verify(private_proposal_substructure_t *this)
|
||||
if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 2))
|
||||
{
|
||||
/* must be 0 or 2 */
|
||||
this->logger->log(this->logger, ERROR, "inconsistent next payload");
|
||||
DBG1(SIG_DBG_ENC, "inconsistent next payload");
|
||||
return FAILED;
|
||||
}
|
||||
if (this->transforms_count != this->transforms->get_count(this->transforms))
|
||||
{
|
||||
/* must be the same! */
|
||||
this->logger->log(this->logger, ERROR, "transform count invalid");
|
||||
DBG1(SIG_DBG_ENC, "transform count invalid");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -174,29 +162,26 @@ static status_t verify(private_proposal_substructure_t *this)
|
||||
case PROTO_ESP:
|
||||
if (this->spi.len != 4)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR,
|
||||
"invalid SPI length in %s proposal",
|
||||
mapping_find(protocol_id_m, this->protocol_id));
|
||||
DBG1(SIG_DBG_ENC, "invalid SPI length in %N proposal",
|
||||
protocol_id_names, this->protocol_id);
|
||||
return FAILED;
|
||||
}
|
||||
break;
|
||||
case PROTO_IKE:
|
||||
if (this->spi.len != 0 && this->spi.len != 8)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR,
|
||||
"invalid SPI length in IKE proposal");
|
||||
DBG1(SIG_DBG_ENC, "invalid SPI length in IKE proposal");
|
||||
return FAILED;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this->logger->log(this->logger, ERROR,
|
||||
"invalid proposal protocol (%d)", this->protocol_id);
|
||||
DBG1(SIG_DBG_ENC, "invalid proposal protocol (%d)", this->protocol_id);
|
||||
return FAILED;
|
||||
}
|
||||
if ((this->protocol_id == 0) || (this->protocol_id >= 4))
|
||||
{
|
||||
/* reserved are not supported */
|
||||
this->logger->log(this->logger, ERROR, "invalid protocol");
|
||||
DBG1(SIG_DBG_ENC, "invalid protocol");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -209,7 +194,7 @@ static status_t verify(private_proposal_substructure_t *this)
|
||||
status = current_transform->verify(current_transform);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "TRANSFORM_SUBSTRUCTURE verification failed");
|
||||
DBG1(SIG_DBG_ENC, "TRANSFORM_SUBSTRUCTURE verification failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -251,12 +236,35 @@ static void set_next_type(private_proposal_substructure_t *this,payload_type_t t
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* (re-)compute the length of the payload.
|
||||
*/
|
||||
static void compute_length(private_proposal_substructure_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t transforms_count = 0;
|
||||
size_t length = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH;
|
||||
iterator = this->transforms->create_iterator(this->transforms,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t * current_transform;
|
||||
iterator->current(iterator,(void **) ¤t_transform);
|
||||
length += current_transform->get_length(current_transform);
|
||||
transforms_count++;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
length += this->spi.len;
|
||||
this->transforms_count = transforms_count;
|
||||
this->proposal_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_proposal_substructure_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
return this->proposal_length;
|
||||
}
|
||||
|
||||
@@ -285,7 +293,7 @@ static void add_transform_substructure (private_proposal_substructure_t *this,tr
|
||||
transform->set_is_last_transform(transform,TRUE);
|
||||
|
||||
this->transforms->insert_last(this->transforms,(void *) transform);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,13 +347,13 @@ static void set_spi(private_proposal_substructure_t *this, chunk_t spi)
|
||||
free(this->spi.ptr);
|
||||
this->spi.ptr = NULL;
|
||||
this->spi.len = 0;
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
this->spi.ptr = clalloc(spi.ptr,spi.len);
|
||||
this->spi.len = spi.len;
|
||||
this->spi_size = spi.len;
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,29 +368,6 @@ static chunk_t get_spi(private_proposal_substructure_t *this)
|
||||
return spi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_proposal_substructure_t.compute_length.
|
||||
*/
|
||||
static void compute_length(private_proposal_substructure_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t transforms_count = 0;
|
||||
size_t length = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH;
|
||||
iterator = this->transforms->create_iterator(this->transforms,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t * current_transform;
|
||||
iterator->current(iterator,(void **) ¤t_transform);
|
||||
length += current_transform->get_length(current_transform);
|
||||
transforms_count++;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
length += this->spi.len;
|
||||
this->transforms_count = transforms_count;
|
||||
this->proposal_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of proposal_substructure_t.get_transform_count.
|
||||
*/
|
||||
@@ -544,9 +529,6 @@ proposal_substructure_t *proposal_substructure_create()
|
||||
this->public.clone = (proposal_substructure_t * (*) (proposal_substructure_t *)) clone_;
|
||||
this->public.destroy = (void (*) (proposal_substructure_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* set default values of the fields */
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
this->proposal_length = 0;
|
||||
@@ -556,7 +538,6 @@ proposal_substructure_t *proposal_substructure_create()
|
||||
this->spi_size = 0;
|
||||
this->spi.ptr = NULL;
|
||||
this->spi.len = 0;
|
||||
this->logger = logger_manager->get_logger(logger_manager, PAYLOAD);
|
||||
|
||||
this->transforms = linked_list_create();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <encoding/payloads/encodings.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/logger_manager.h>
|
||||
#include <daemon.h>
|
||||
|
||||
|
||||
typedef struct private_sa_payload_t private_sa_payload_t;
|
||||
@@ -61,18 +61,6 @@ struct private_sa_payload_t {
|
||||
* Proposals in this payload are stored in a linked_list_t.
|
||||
*/
|
||||
linked_list_t * proposals;
|
||||
|
||||
/**
|
||||
* Logger for error handling
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_sa_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_sa_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -136,15 +124,15 @@ static status_t verify(private_sa_payload_t *this)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "first proposal is not proposal #1");
|
||||
DBG1(SIG_DBG_ENC, "first proposal is not proposal #1");
|
||||
status = FAILED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (current_number != (expected_number + 1))
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "proposal number is %d, excepted %d or %d",
|
||||
current_number, expected_number, expected_number + 1);
|
||||
DBG1(SIG_DBG_ENC, "proposal number is %d, excepted %d or %d",
|
||||
current_number, expected_number, expected_number + 1);
|
||||
status = FAILED;
|
||||
break;
|
||||
}
|
||||
@@ -152,7 +140,7 @@ static status_t verify(private_sa_payload_t *this)
|
||||
else if (current_number < expected_number)
|
||||
{
|
||||
/* must not be smaller then proceeding one */
|
||||
this->logger->log(this->logger, ERROR, "proposal number smaller than that of previous proposal");
|
||||
DBG1(SIG_DBG_ENC, "proposal number smaller than that of previous proposal");
|
||||
status = FAILED;
|
||||
break;
|
||||
}
|
||||
@@ -160,7 +148,7 @@ static status_t verify(private_sa_payload_t *this)
|
||||
status = current_proposal->payload_interface.verify(&(current_proposal->payload_interface));
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "PROPOSAL_SUBSTRUCTURE verification failed");
|
||||
DBG1(SIG_DBG_ENC, "PROPOSAL_SUBSTRUCTURE verification failed");
|
||||
break;
|
||||
}
|
||||
first = FALSE;
|
||||
@@ -224,12 +212,31 @@ static void set_next_type(private_sa_payload_t *this,payload_type_t type)
|
||||
this->next_payload = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* recompute length of the payload.
|
||||
*/
|
||||
static void compute_length (private_sa_payload_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t length = SA_PAYLOAD_HEADER_LENGTH;
|
||||
iterator = this->proposals->create_iterator(this->proposals,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t *current_proposal;
|
||||
iterator->current(iterator,(void **) ¤t_proposal);
|
||||
length += current_proposal->get_length(current_proposal);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_sa_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
@@ -259,7 +266,7 @@ static void add_proposal_substructure(private_sa_payload_t *this,proposal_substr
|
||||
proposal->set_is_last_proposal(proposal, TRUE);
|
||||
proposal->set_proposal_number(proposal, proposal_count + 1);
|
||||
this->proposals->insert_last(this->proposals,(void *) proposal);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,25 +328,6 @@ static linked_list_t *get_proposals(private_sa_payload_t *this)
|
||||
return proposal_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_sa_payload_t.compute_length.
|
||||
*/
|
||||
static void compute_length (private_sa_payload_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t length = SA_PAYLOAD_HEADER_LENGTH;
|
||||
iterator = this->proposals->create_iterator(this->proposals,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t *current_proposal;
|
||||
iterator->current(iterator,(void **) ¤t_proposal);
|
||||
length += current_proposal->get_length(current_proposal);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->payload_length = length;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
@@ -363,15 +351,10 @@ sa_payload_t *sa_payload_create()
|
||||
this->public.get_proposals = (linked_list_t* (*) (sa_payload_t *)) get_proposals;
|
||||
this->public.destroy = (void (*) (sa_payload_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* set default values of the fields */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
this->payload_length = SA_PAYLOAD_HEADER_LENGTH;
|
||||
this->logger = logger_manager->get_logger(logger_manager, PARSER);
|
||||
|
||||
this->proposals = linked_list_create();
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -26,15 +26,6 @@
|
||||
#include <encoding/payloads/encodings.h>
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
/**
|
||||
* String mappings for ts_type_t.
|
||||
*/
|
||||
mapping_t ts_type_m[] = {
|
||||
{TS_IPV4_ADDR_RANGE, "TS_IPV4_ADDR_RANGE"},
|
||||
{TS_IPV6_ADDR_RANGE, "TS_IPV6_ADDR_RANGE"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
|
||||
|
||||
typedef struct private_traffic_selector_substructure_t private_traffic_selector_substructure_t;
|
||||
|
||||
|
||||
@@ -65,14 +65,12 @@ struct private_transform_attribute_t {
|
||||
chunk_t attribute_value;
|
||||
};
|
||||
|
||||
/**
|
||||
* String mappings for transform_attribute_type_t.
|
||||
*/
|
||||
mapping_t transform_attribute_type_m[] = {
|
||||
{ATTRIBUTE_UNDEFINED, "ATTRIBUTE_UNDEFINED"},
|
||||
{KEY_LENGTH, "KEY_LENGTH"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
|
||||
ENUM_BEGIN(transform_attribute_type_name, ATTRIBUTE_UNDEFINED, ATTRIBUTE_UNDEFINED,
|
||||
"ATTRIBUTE_UNDEFINED");
|
||||
ENUM_NEXT(transform_attribute_type_name, KEY_LENGTH, KEY_LENGTH, ATTRIBUTE_UNDEFINED,
|
||||
"KEY_LENGTH");
|
||||
ENUM_END(transform_attribute_type_name, KEY_LENGTH);
|
||||
|
||||
/**
|
||||
* Encoding rules to parse or generate a Transform attribute.
|
||||
|
||||
@@ -41,11 +41,11 @@ enum transform_attribute_type_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* String mappings for transform_attribute_type_t.
|
||||
* enum name for transform_attribute_type_t.
|
||||
*
|
||||
* @ingroup payloads
|
||||
*/
|
||||
extern mapping_t transform_attribute_type_m[];
|
||||
extern enum_name_t *transform_attribute_type_names;
|
||||
|
||||
typedef struct transform_attribute_t transform_attribute_t;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <encoding/payloads/encodings.h>
|
||||
#include <types.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/logger_manager.h>
|
||||
#include <daemon.h>
|
||||
|
||||
|
||||
typedef struct private_transform_substructure_t private_transform_substructure_t;
|
||||
@@ -70,18 +70,6 @@ struct private_transform_substructure_t {
|
||||
* Transforms Attributes are stored in a linked_list_t.
|
||||
*/
|
||||
linked_list_t *attributes;
|
||||
|
||||
/**
|
||||
* assigned logger
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this substructure.
|
||||
*
|
||||
* @param this calling private_transform_substructure_t object
|
||||
*/
|
||||
void (*compute_length) (private_transform_substructure_t *this);
|
||||
};
|
||||
|
||||
|
||||
@@ -136,7 +124,7 @@ static status_t verify(private_transform_substructure_t *this)
|
||||
if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 3))
|
||||
{
|
||||
/* must be 0 or 3 */
|
||||
this->logger->log(this->logger, ERROR, "inconsistent next payload");
|
||||
DBG1(SIG_DBG_ENC, "inconsistent next payload");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
@@ -152,8 +140,7 @@ static status_t verify(private_transform_substructure_t *this)
|
||||
break;
|
||||
default:
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "invalid transform type: %d",
|
||||
this->transform_type);
|
||||
DBG1(SIG_DBG_ENC, "invalid transform type: %d", this->transform_type);
|
||||
return FAILED;
|
||||
}
|
||||
}
|
||||
@@ -167,8 +154,7 @@ static status_t verify(private_transform_substructure_t *this)
|
||||
status = current_attributes->verify(current_attributes);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR,
|
||||
"TRANSFORM_ATTRIBUTE verification failed");
|
||||
DBG1(SIG_DBG_ENC, "TRANSFORM_ATTRIBUTE verification failed");
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
@@ -202,13 +188,31 @@ static payload_type_t get_next_type(private_transform_substructure_t *this)
|
||||
return (this->next_payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* recompute the length of the payload.
|
||||
*/
|
||||
static void compute_length (private_transform_substructure_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
|
||||
iterator = this->attributes->create_iterator(this->attributes,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t * current_attribute;
|
||||
iterator->current(iterator,(void **) ¤t_attribute);
|
||||
length += current_attribute->get_length(current_attribute);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->transform_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_transform_substructure_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
|
||||
compute_length(this);
|
||||
return this->transform_length;
|
||||
}
|
||||
|
||||
@@ -226,7 +230,7 @@ static iterator_t *create_transform_attribute_iterator (private_transform_substr
|
||||
static void add_transform_attribute (private_transform_substructure_t *this,transform_attribute_t *attribute)
|
||||
{
|
||||
this->attributes->insert_last(this->attributes,(void *) attribute);
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,25 +288,6 @@ static u_int16_t get_transform_id (private_transform_substructure_t *this)
|
||||
return this->transform_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_transform_substructure_t.compute_length.
|
||||
*/
|
||||
static void compute_length (private_transform_substructure_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
|
||||
iterator = this->attributes->create_iterator(this->attributes,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t * current_attribute;
|
||||
iterator->current(iterator,(void **) ¤t_attribute);
|
||||
length += current_attribute->get_length(current_attribute);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->transform_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of transform_substructure_t.clone.
|
||||
*/
|
||||
@@ -410,16 +395,12 @@ transform_substructure_t *transform_substructure_create()
|
||||
this->public.clone = (transform_substructure_t* (*) (transform_substructure_t *)) clone_;
|
||||
this->public.destroy = (void (*) (transform_substructure_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* set default values of the fields */
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
this->transform_length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
|
||||
this->transform_id = 0;
|
||||
this->transform_type = 0;
|
||||
this->attributes = linked_list_create();
|
||||
this->logger = logger_manager->get_logger(logger_manager, PAYLOAD);
|
||||
|
||||
return (&(this->public));
|
||||
}
|
||||
|
||||
@@ -69,13 +69,6 @@ struct private_ts_payload_t {
|
||||
* Contains the traffic selectors of type traffic_selector_substructure_t.
|
||||
*/
|
||||
linked_list_t *traffic_selectors;
|
||||
|
||||
/**
|
||||
* @brief Computes the length of this payload.
|
||||
*
|
||||
* @param this calling private_ts_payload_t object
|
||||
*/
|
||||
void (*compute_length) (private_ts_payload_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -195,12 +188,35 @@ static void set_next_type(private_ts_payload_t *this,payload_type_t type)
|
||||
this->next_payload = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* recompute the length of the payload.
|
||||
*/
|
||||
static void compute_length (private_ts_payload_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t ts_count = 0;
|
||||
size_t length = TS_PAYLOAD_HEADER_LENGTH;
|
||||
iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t * current_traffic_selector;
|
||||
iterator->current(iterator,(void **) ¤t_traffic_selector);
|
||||
length += current_traffic_selector->get_length(current_traffic_selector);
|
||||
ts_count++;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->number_of_traffic_selectors= ts_count;
|
||||
this->payload_length = length;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.get_length.
|
||||
*/
|
||||
static size_t get_length(private_ts_payload_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
compute_length(this);
|
||||
return this->payload_length;
|
||||
}
|
||||
|
||||
@@ -259,30 +275,6 @@ static linked_list_t *get_traffic_selectors(private_ts_payload_t *this)
|
||||
return ts_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_ts_payload_t.compute_length.
|
||||
*/
|
||||
static void compute_length (private_ts_payload_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
size_t ts_count = 0;
|
||||
size_t length = TS_PAYLOAD_HEADER_LENGTH;
|
||||
iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
payload_t * current_traffic_selector;
|
||||
iterator->current(iterator,(void **) ¤t_traffic_selector);
|
||||
length += current_traffic_selector->get_length(current_traffic_selector);
|
||||
ts_count++;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->number_of_traffic_selectors= ts_count;
|
||||
this->payload_length = length;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of payload_t.destroy and ts_payload_t.destroy.
|
||||
*/
|
||||
@@ -326,9 +318,6 @@ ts_payload_t *ts_payload_create(bool is_initiator)
|
||||
this->public.create_traffic_selector_substructure_iterator = (iterator_t* (*) (ts_payload_t *,bool)) create_traffic_selector_substructure_iterator;
|
||||
this->public.get_traffic_selectors = (linked_list_t *(*) (ts_payload_t *)) get_traffic_selectors;
|
||||
|
||||
/* private functions */
|
||||
this->compute_length = compute_length;
|
||||
|
||||
/* private variables */
|
||||
this->critical = FALSE;
|
||||
this->next_payload = NO_PAYLOAD;
|
||||
|
||||
Reference in New Issue
Block a user