- wrote payload sa_payload
authorJan Hutter <jhutter@hsr.ch>
Tue, 15 Nov 2005 14:59:47 +0000 (14:59 -0000)
committerJan Hutter <jhutter@hsr.ch>
Tue, 15 Nov 2005 14:59:47 +0000 (14:59 -0000)
- wrote additions in generator sa_payload
- wrote test for sa_payload

Source/charon/generator.c
Source/charon/payloads/sa_payload.c
Source/charon/testcases/generator_test.c
Source/charon/testcases/generator_test.h
Source/charon/testcases/testcases.c

index 9fb3047..523af80 100644 (file)
@@ -36,7 +36,7 @@
 #include "payloads/proposal_substructure.h"
 #include "payloads/transform_substructure.h"
 #include "payloads/sa_payload.h"
-
+#include "payloads/ke_payload.h"
 
 extern logger_manager_t *global_logger_manager;
 
@@ -736,6 +736,30 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                status = this->generate_from_chunk(this,rules[i].offset);
                                break;
                        }
+                       case KEY_EXCHANGE_DATA:
+                       {
+                               /* the Key Exchange Data value is generated from chunk */
+                               status = this->generate_from_chunk(this,rules[i].offset);
+                               if (status != SUCCESS)
+                               {
+                                       this->logger->log(this->logger,CONTROL_MORE,"Could no write key exchange data from chunk");     
+                                       return status;
+                               }
+                               
+                               /* before iterative generate the transforms, store the current payload length position */
+                               u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
+                               /* Length of KE_PAYLOAD is calculated */
+                               u_int16_t length_of_ke_payload = KE_PAYLOAD_HEADER_LENGTH + ((chunk_t *)(this->data_struct + rules[i].offset))->len;
+
+                               u_int16_t int16_val = htons(length_of_ke_payload);                      
+                               status = this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
+                               if (status != SUCCESS)
+                               {
+                                       this->logger->log(this->logger,CONTROL_MORE,"Could no write payload length into buffer");                                       
+                                       return status;
+                               }
+                               break;
+                       }                       
                        case PROPOSALS:
                        {
                                /* before iterative generate the transforms, store the current payload length position */
index ab66e60..9d4f954 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * @file sa_payload.h
+ * @file sa_payload.c
  * 
  * @brief Declaration of the class sa_payload_t. 
  * 
@@ -76,7 +76,7 @@ struct private_sa_payload_s {
 };
 
 /**
- * Encoding rules to parse or generate a IKEv2-Header
+ * Encoding rules to parse or generate a IKEv2-SA Payload
  * 
  * The defined offsets are the positions in a object of type 
  * private_sa_payload_t.
index 9602828..a28b8f3 100644 (file)
@@ -35,6 +35,7 @@
 #include "../payloads/transform_substructure.h"
 #include "../payloads/proposal_substructure.h"
 #include "../payloads/sa_payload.h"
+#include "../payloads/ke_payload.h"
 
 /*
  * Described in Header 
@@ -438,6 +439,9 @@ void test_generator_with_proposal_substructure(tester_t *tester)
        global_logger_manager->destroy_logger(global_logger_manager,logger);    
 }
 
+/*
+ * Described in header
+ */ 
 void test_generator_with_sa_payload(tester_t *tester)
 {
        generator_t *generator;
@@ -611,3 +615,61 @@ void test_generator_with_sa_payload(tester_t *tester)
        global_logger_manager->destroy_logger(global_logger_manager,logger);    
        
 }
+
+/*
+ * Described in header
+ */ 
+void test_generator_with_ke_payload(tester_t *tester)
+{
+       generator_t *generator;
+       ke_payload_t *ke_payload;
+       logger_t *logger;
+       status_t status;
+       chunk_t generated_data;
+       chunk_t key_exchange_data;
+       
+       logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with KE Payload");
+       
+       /* create generator */
+       generator = generator_create();
+       tester->assert_true(tester,(generator != NULL), "generator create check");
+       
+       ke_payload = ke_payload_create();
+       
+       
+       key_exchange_data.ptr = "test-text";
+       key_exchange_data.len = strlen(key_exchange_data.ptr);
+       
+       ke_payload->set_key_exchange_data(ke_payload,key_exchange_data);
+       
+       ke_payload->set_dh_group_number(ke_payload,7777);
+       
+       status = generator->generate_payload(generator,(payload_t *)ke_payload);
+       tester->assert_true(tester,(status == SUCCESS),"generate_payload call check");
+       tester->assert_true(tester,(generator->write_to_chunk(generator,&generated_data) == SUCCESS),"write_to_chunk call check");
+       logger->log_chunk(logger,RAW,"generated payload",&generated_data);      
+
+       u_int8_t expected_generation[] = {
+               /* payload header */
+               0x00,0x00,0x00,0x11,
+               0x1E,0x61,0x00,0x00,
+               /* key exchange data */
+               0x74,0x65,0x73,0x74,
+               0x2D,0x74,0x65,0x78,
+               0x74
+       };
+       
+       
+       logger->log_bytes(logger,RAW,"expected payload",expected_generation,sizeof(expected_generation));       
+       
+       tester->assert_true(tester,(memcmp(expected_generation,generated_data.ptr,sizeof(expected_generation)) == 0), "compare generated data");
+
+       allocator_free_chunk(generated_data);   
+       
+       tester->assert_true(tester,(ke_payload->destroy(ke_payload) == SUCCESS), "sa_payload destroy call check");
+       tester->assert_true(tester,(generator->destroy(generator) == SUCCESS), "generator destroy call check");
+               
+       global_logger_manager->destroy_logger(global_logger_manager,logger);    
+       
+}
+
index e1a0f32..6b72994 100644 (file)
@@ -66,5 +66,13 @@ void test_generator_with_proposal_substructure(tester_t *tester);
  */
 void test_generator_with_sa_payload(tester_t *tester);
 
+/**
+ * @brief Test function used to test the generator with KE payload
+ * 
+ *
+ * @param tester associated tester object
+ */
+void test_generator_with_ke_payload(tester_t *tester);
+
 
 #endif /*GENERATOR_TEST_H_*/
index f435128..8f36958 100644 (file)
@@ -121,43 +121,24 @@ test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
  */
 test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
 
-/**
- * Test 1 for generator_t
- */
 test_t generator_test1 = {test_generator_with_header_payload,"Generator: header payload"};
-/**
- * Test 2 for generator_t
- */
 test_t generator_test2 = {test_generator_with_transform_attribute,"Generator: transform attribute"};
-
-/**
- * Parser test for ike header
- * Test 3 for generator_t
- */
 test_t generator_test3 = {test_generator_with_transform_substructure,"Generator: transform substructure"};
-
-/**
- * Test 4 for generator_t
- */
 test_t generator_test4 = {test_generator_with_proposal_substructure,"Generator: proposal substructure"};
-
-/**
- * Test 5 for generator_t
- */
 test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message with SA Payload"};
+test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"};
 
 
 /**
  * Test 2 for generator_t
  */
-
-//test_t parser_test_header = {test_parser_with_header_payload, "Parser: header payload"};
+test_t parser_test_header = {test_parser_with_header_payload, "Parser: header payload"};
 
 
 /**
  * Parser test for ike security association
  */
-//test_t parser_test_sa_payload = {test_parser_with_sa_payload, "Parser: sa payload"};
+test_t parser_test_sa_payload = {test_parser_with_sa_payload, "Parser: sa payload"};
 
 
 /**
@@ -212,11 +193,12 @@ logger_manager_t *global_logger_manager;
        &ike_sa_test,
        &generator_test1,
        &generator_test2,
-//     &parser_test_header,
-       //&parser_test_sa_payload,
+       &parser_test_header,
+       &parser_test_sa_payload,
        &generator_test3,
        &generator_test4,
        &generator_test5,
+       &generator_test6,
        &ike_sa_manager_test,
        &packet_test,
        NULL
@@ -233,8 +215,8 @@ logger_manager_t *global_logger_manager;
                
        tester_t *tester = tester_create(test_output, FALSE);
 
-//     tester->perform_tests(tester,all_tests);
-       tester->perform_test(tester,&generator_test5);   
+       tester->perform_tests(tester,all_tests);
+//     tester->perform_test(tester,&generator_test6);   
 
        
        tester->destroy(tester);