- installing of child sa works
- need correct IP adresses to actually use IPsec
This commit is contained in:
@@ -341,7 +341,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
|
||||
u_int8_t low_val = *(this->out_position) & 0x0F;
|
||||
/* highval is set, low_val is not changed */
|
||||
*(this->out_position) = high_val | low_val;
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => 0x%x", *(this->out_position));
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
|
||||
/* write position is not changed, just bit position is moved */
|
||||
this->current_bit = 4;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
|
||||
/* lowval of current byte in buffer has to be set to the new value*/
|
||||
u_int low_val = *((u_int8_t *)(this->data_struct + offset)) & 0x0F;
|
||||
*(this->out_position) = high_val | low_val;
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => 0x%x", *(this->out_position));
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
|
||||
this->out_position++;
|
||||
this->current_bit = 0;
|
||||
|
||||
@@ -370,7 +370,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
|
||||
{
|
||||
/* 8 bit values are written as they are */
|
||||
*this->out_position = *((u_int8_t *)(this->data_struct + offset));
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => 0x%x", *(this->out_position));
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
|
||||
this->out_position++;
|
||||
break;
|
||||
|
||||
@@ -392,7 +392,7 @@ static void generate_u_int_type (private_generator_t *this,encoding_type_t int_t
|
||||
int16_val = int16_val & 0xFF7F;
|
||||
|
||||
int16_val = int16_val | attribute_format_flag;
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => 0x%x", int16_val);
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => %d", int16_val);
|
||||
/* write bytes to buffer (set bit is overwritten)*/
|
||||
this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
|
||||
this->current_bit = 0;
|
||||
@@ -516,7 +516,7 @@ static void generate_flag (private_generator_t *this,u_int32_t offset)
|
||||
*(this->out_position) = *(this->out_position) | flag;
|
||||
|
||||
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => 0x0%x", *(this->out_position));
|
||||
this->logger->log(this->logger, RAW|LEVEL2, " => %d", *(this->out_position));
|
||||
|
||||
this->current_bit++;
|
||||
if (this->current_bit >= 8)
|
||||
@@ -1017,6 +1017,8 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "generating %s payload finished.",
|
||||
mapping_find(payload_type_m, payload_type));
|
||||
this->logger->log_bytes(this->logger, RAW|LEVEL3, "generated data for this payload",
|
||||
payload_start, this->out_position-payload_start);
|
||||
}
|
||||
|
||||
@@ -289,6 +289,7 @@ static status_t encrypt(private_encryption_payload_t *this)
|
||||
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);
|
||||
@@ -307,6 +308,8 @@ static status_t encrypt(private_encryption_payload_t *this)
|
||||
iv.len = block_size;
|
||||
randomizer->allocate_pseudo_random_bytes(randomizer, iv.len, &iv);
|
||||
randomizer->destroy(randomizer);
|
||||
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before encryption with padding", &to_crypt);
|
||||
|
||||
/* encrypt to_crypt chunk */
|
||||
allocator_free(this->encrypted.ptr);
|
||||
@@ -319,6 +322,8 @@ static status_t encrypt(private_encryption_payload_t *this)
|
||||
allocator_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);
|
||||
@@ -331,6 +336,8 @@ static status_t encrypt(private_encryption_payload_t *this)
|
||||
|
||||
allocator_free(result.ptr);
|
||||
allocator_free(iv.ptr);
|
||||
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data after encryption with IV and (invalid) signature", &this->encrypted);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -345,6 +352,8 @@ static status_t decrypt(private_encryption_payload_t *this)
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -373,12 +382,16 @@ static status_t decrypt(private_encryption_payload_t *this)
|
||||
/* free previus data, if any */
|
||||
allocator_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|LEVEL1, "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);
|
||||
@@ -396,6 +409,7 @@ static status_t decrypt(private_encryption_payload_t *this)
|
||||
|
||||
/* free padding */
|
||||
this->decrypted.ptr = allocator_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));
|
||||
}
|
||||
|
||||
@@ -226,6 +226,7 @@ static void set_next_type(private_proposal_substructure_t *this,payload_type_t t
|
||||
*/
|
||||
static size_t get_length(private_proposal_substructure_t *this)
|
||||
{
|
||||
this->compute_length(this);
|
||||
return this->proposal_length;
|
||||
}
|
||||
|
||||
@@ -384,9 +385,8 @@ static void compute_length (private_proposal_substructure_t *this)
|
||||
iterator->destroy(iterator);
|
||||
|
||||
length += this->spi.len;
|
||||
this->transforms_count= transforms_count;
|
||||
this->proposal_length = length;
|
||||
|
||||
this->transforms_count = transforms_count;
|
||||
this->proposal_length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,8 +411,8 @@ static size_t get_spi_size (private_proposal_substructure_t *this)
|
||||
void add_to_proposal(private_proposal_substructure_t *this, proposal_t *proposal)
|
||||
{
|
||||
iterator_t *iterator = this->transforms->create_iterator(this->transforms, TRUE);
|
||||
u_int32_t spi;
|
||||
|
||||
proposal->set_spi(proposal, this->protocol_id, *((u_int32_t*)this->spi.ptr));
|
||||
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
@@ -430,6 +430,10 @@ void add_to_proposal(private_proposal_substructure_t *this, proposal_t *proposal
|
||||
proposal->add_algorithm(proposal, this->protocol_id, transform_type, transform_id, key_length);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
spi = *((u_int32_t*)this->spi.ptr);
|
||||
|
||||
proposal->set_spi(proposal, this->protocol_id, spi);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -561,14 +565,6 @@ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *
|
||||
algorithm_t *algo;
|
||||
transform_substructure_t *transform;
|
||||
|
||||
/* take over general infos */
|
||||
this->spi_size = proto == IKE ? 8 : 4;
|
||||
this->spi.len = this->spi_size;
|
||||
this->spi.ptr = allocator_alloc(this->spi_size);
|
||||
*((u_int32_t*)this->spi.ptr) = proposal->get_spi(proposal, proto);
|
||||
this->proposal_number = proposal->get_number(proposal);
|
||||
this->protocol_id = proto;
|
||||
|
||||
/* encryption algorithm is only availble in ESP */
|
||||
iterator = proposal->create_algorithm_iterator(proposal, proto, ENCRYPTION_ALGORITHM);
|
||||
while (iterator->has_next(iterator))
|
||||
@@ -623,5 +619,13 @@ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
/* take over general infos */
|
||||
this->spi_size = proto == IKE ? 8 : 4;
|
||||
this->spi.len = this->spi_size;
|
||||
this->spi.ptr = allocator_alloc(this->spi_size);
|
||||
*((u_int32_t*)this->spi.ptr) = proposal->get_spi(proposal, proto);
|
||||
this->proposal_number = proposal->get_number(proposal);
|
||||
this->protocol_id = proto;
|
||||
|
||||
return &(this->public);
|
||||
}
|
||||
|
||||
@@ -343,7 +343,6 @@ static void compute_length (private_transform_substructure_t *this)
|
||||
iterator->destroy(iterator);
|
||||
|
||||
this->transform_length = length;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,20 +475,13 @@ transform_substructure_t *transform_substructure_create_type(transform_type_t tr
|
||||
transform->set_transform_type(transform,transform_type);
|
||||
transform->set_transform_id(transform,transform_id);
|
||||
|
||||
switch (transform_type)
|
||||
/* a keylength attribute is only created for AES encryption */
|
||||
if (transform_type == ENCRYPTION_ALGORITHM &&
|
||||
transform_id == ENCR_AES_CBC)
|
||||
{
|
||||
case ENCRYPTION_ALGORITHM:
|
||||
case PSEUDO_RANDOM_FUNCTION:
|
||||
case INTEGRITY_ALGORITHM:
|
||||
{
|
||||
transform_attribute_t *attribute = transform_attribute_create_key_length(key_length);
|
||||
transform->add_transform_attribute(transform,attribute);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
/* no keylength attribute is created */
|
||||
}
|
||||
}
|
||||
transform_attribute_t *attribute = transform_attribute_create_key_length(key_length);
|
||||
transform->add_transform_attribute(transform,attribute);
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user