- added and tested id_payload_t
authorJan Hutter <jhutter@hsr.ch>
Tue, 29 Nov 2005 09:57:22 +0000 (09:57 -0000)
committerJan Hutter <jhutter@hsr.ch>
Tue, 29 Nov 2005 09:57:22 +0000 (09:57 -0000)
13 files changed:
Source/charon/encoding/generator.c
Source/charon/encoding/parser.c
Source/charon/encoding/payloads/Makefile.payloads
Source/charon/encoding/payloads/encodings.c
Source/charon/encoding/payloads/encodings.h
Source/charon/encoding/payloads/payload.c
Source/charon/testcases/generator_test.c
Source/charon/testcases/generator_test.h
Source/charon/testcases/parser_test.c
Source/charon/testcases/parser_test.h
Source/charon/testcases/testcases.c
Source/charon/utils/iterator.h
Source/charon/utils/logger.h

index cb646fa..c239cf6 100644 (file)
@@ -40,6 +40,7 @@
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/notify_payload.h>
 #include <encoding/payloads/nonce_payload.h>
+#include <encoding/payloads/id_payload.h>
 
 
 typedef struct private_generator_t private_generator_t;
@@ -759,6 +760,19 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
                                this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
                                break;
                        }
+                       case ID_DATA:
+                       {
+                               /* the ID Data value is generated from chunk */
+                               this->generate_from_chunk(this, rules[i].offset);
+                               
+                               u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
+                               /* Length of nonce PAYLOAD is calculated */
+                               u_int16_t length_of_id_payload = ID_PAYLOAD_HEADER_LENGTH + ((chunk_t *)(this->data_struct + rules[i].offset))->len;
+                               u_int16_t int16_val = htons(length_of_id_payload);
+
+                               this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
+                               break;
+                       }
                        case PROPOSALS:
                        {
                                /* before iterative generate the transforms, store the current payload length position */
index 9a125f5..55ad564 100644 (file)
@@ -39,6 +39,7 @@
 #include <encoding/payloads/transform_attribute.h>
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/nonce_payload.h>
+#include <encoding/payloads/id_payload.h>
 #include <encoding/payloads/notify_payload.h>
 #include <encoding/payloads/encryption_payload.h>
 
@@ -804,6 +805,16 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                }               
                                break;                  
                        }
+                       case ID_DATA:
+                       {
+                               size_t data_length = payload_length - ID_PAYLOAD_HEADER_LENGTH;
+                               if (this->parse_chunk(this, rule_number, output + rule->offset, data_length) != SUCCESS) 
+                               {
+                                       pld->destroy(pld);
+                                       return PARSE_ERROR;
+                               }               
+                               break;                  
+                       }
                        case KEY_EXCHANGE_DATA:
                        {
                                size_t keydata_length = payload_length - KE_PAYLOAD_HEADER_LENGTH;
index e32dd5b..0f71d18 100644 (file)
@@ -34,6 +34,10 @@ OBJS+= $(BUILD_DIR)notify_payload.o
 $(BUILD_DIR)notify_payload.o :                 $(PAYLOADS_DIR)notify_payload.c $(PAYLOADS_DIR)notify_payload.h
                                                                                $(CC) $(CFLAGS) -c -o $@ $<
 
+OBJS+= $(BUILD_DIR)id_payload.o
+$(BUILD_DIR)id_payload.o :                             $(PAYLOADS_DIR)id_payload.c $(PAYLOADS_DIR)id_payload.h
+                                                                               $(CC) $(CFLAGS) -c -o $@ $<
+
 OBJS+= $(BUILD_DIR)payload.o
 $(BUILD_DIR)payload.o :                                        $(PAYLOADS_DIR)payload.c $(PAYLOADS_DIR)payload.h
                                                                                $(CC) $(CFLAGS) -c -o $@ $<
index ab8c3f7..5d42542 100644 (file)
@@ -48,5 +48,7 @@ mapping_t encoding_type_m[] = {
        {ATTRIBUTE_LENGTH_OR_VALUE, "ATTRIBUTE_LENGTH_OR_VALUE"},
        {ATTRIBUTE_VALUE, "ATTRIBUTE_VALUE"},
        {NONCE_DATA, "NONCE_DATA"},
+       {ID_DATA, "ID_DATA"},
+       {ENCRYPTED_DATA, "ENCRYPTED_DATA"},
        {MAPPING_END, NULL}
 };
index 309527b..d39453a 100644 (file)
@@ -308,6 +308,16 @@ enum encoding_type_t{
         * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
         */
        NONCE_DATA,
+       
+       /**
+        * Representating a ID Data field.
+        * 
+        * When generating the content of the chunkt pointing to 
+        * is written.
+        * 
+        * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
+        */
+       ID_DATA,
 
        /**
         * Representating an IKE_SPI field in an IKEv2 Header.
@@ -319,6 +329,9 @@ enum encoding_type_t{
         */
        IKE_SPI,
        
+       /**
+        * Representing the encrypted data body of a encryption payload.
+        */
        ENCRYPTED_DATA,
        
 };
index a2333f6..845250d 100644 (file)
@@ -27,6 +27,7 @@
 #include <encoding/payloads/ike_header.h>
 #include <encoding/payloads/sa_payload.h>
 #include <encoding/payloads/nonce_payload.h>
+#include <encoding/payloads/id_payload.h>
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/notify_payload.h>
 
@@ -81,6 +82,10 @@ payload_t *payload_create(payload_type_t type)
                        return (payload_t*)transform_attribute_create();
                case NONCE:
                        return (payload_t*)nonce_payload_create();
+               case ID_INITIATOR:
+                       return (payload_t*)id_payload_create(TRUE);
+               case ID_RESPONDER:
+                       return (payload_t*)id_payload_create(FALSE);
                case KEY_EXCHANGE:
                        return (payload_t*)ke_payload_create();
                case NOTIFY:
index 1dbef6f..636ffb2 100644 (file)
@@ -38,6 +38,7 @@
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/notify_payload.h>
 #include <encoding/payloads/nonce_payload.h>
+#include <encoding/payloads/id_payload.h>
 
 /*
  * Described in Header 
@@ -731,3 +732,57 @@ void test_generator_with_nonce_payload(tester_t *tester)
        
 }
 
+/*
+ * Described in header.
+ */ 
+void test_generator_with_id_payload(tester_t *tester)
+{
+       generator_t *generator;
+       id_payload_t *id_payload;
+       logger_t *logger;
+       chunk_t generated_data;
+       chunk_t id;
+       
+       logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Message with ID Payload");
+       
+       /* create generator */
+       generator = generator_create();
+       tester->assert_true(tester,(generator != NULL), "generator create check");
+       
+       id_payload = id_payload_create(FALSE);
+       
+       
+       id.ptr = "123456789012";
+       id.len = strlen(id.ptr);
+
+       id_payload->set_id_type(id_payload,ID_IPV4_ADDR);
+       id_payload->set_data(id_payload,id);
+       
+       generator->generate_payload(generator,(payload_t *)id_payload);
+       generator->write_to_chunk(generator,&generated_data);
+       logger->log_chunk(logger,RAW,"generated payload",&generated_data);      
+       
+
+       u_int8_t expected_generation[] = {
+               /* payload header */
+               0x00,0x00,0x00,0x14,
+               0x01,0x00,0x00,0x00,
+               /* id data */
+               0x31,0x32,0x33,0x34,
+               0x35,0x36,0x37,0x38,
+               0x39,0x30,0x31,0x32,
+       };
+       
+       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);
+       
+       id_payload->destroy(id_payload);
+       generator->destroy(generator);
+               
+       global_logger_manager->destroy_logger(global_logger_manager,logger);    
+       
+}
+
index 64484ab..02b050f 100644 (file)
@@ -28,7 +28,7 @@
 /**
  * @brief Test function used to test the generator with header payload.
  * 
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -37,7 +37,7 @@ void test_generator_with_header_payload(tester_t *tester);
 /**
  * @brief Test function used to test the generator with transform attribute payload.
  *
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -47,7 +47,7 @@ void test_generator_with_transform_attribute(tester_t *tester);
 /**
  * @brief Test function used to test the generator with transform substructure payload.
  *
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -56,7 +56,7 @@ void test_generator_with_transform_substructure(tester_t *tester);
 /**
  * @brief Test function used to test the generator with proposal substructure payload.
  *
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -65,7 +65,7 @@ void test_generator_with_proposal_substructure(tester_t *tester);
 /**
  * @brief Test function used to test the generator with SA payload.
  * 
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -74,7 +74,7 @@ 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
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -83,7 +83,7 @@ void test_generator_with_ke_payload(tester_t *tester);
 /**
  * @brief Test function used to test the generator with Notify payload.
  *
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
@@ -92,11 +92,20 @@ void test_generator_with_notify_payload(tester_t *tester);
 /**
  * @brief Test function used to test the generator with Nonce payload.
  * 
- * @param tester associated tester object
+ * @param tester associated tester_t object
  * 
  * @ingroup testcases
  */
 void test_generator_with_nonce_payload(tester_t *tester);
 
+/**
+ * @brief Test function used to test the generator with ID payload.
+ * 
+ * @param tester associated tester_t object
+ * 
+ * @ingroup testcases
+ */
+void test_generator_with_id_payload(tester_t *tester);
+
 
 #endif /*GENERATOR_TEST_H_*/
index 70560b2..ae12c57 100644 (file)
@@ -32,6 +32,7 @@
 #include <encoding/payloads/ike_header.h>
 #include <encoding/payloads/sa_payload.h>
 #include <encoding/payloads/nonce_payload.h>
+#include <encoding/payloads/id_payload.h>
 #include <encoding/payloads/ke_payload.h>
 #include <encoding/payloads/notify_payload.h>
 
@@ -224,6 +225,47 @@ void test_parser_with_nonce_payload(tester_t *tester)
 /*
  * Described in Header 
  */
+void test_parser_with_id_payload(tester_t *tester)
+{
+       parser_t *parser;
+       id_payload_t *id_payload;
+       status_t status;
+       chunk_t id_chunk, result;
+       
+       u_int8_t id_bytes[] = {
+               0x00,0x00,0x00,0x14, /* payload header */
+               0x05,0x01,0x02,0x03,
+                       0x04,0x05,0x06,0x07,/* 12 Byte nonce */
+                       0x08,0x09,0x0A,0x2B,
+                       0x0C,0x0D,0x0E,0x0F
+       };
+       
+       id_chunk.ptr = id_bytes;
+       id_chunk.len = sizeof(id_bytes);
+
+       parser = parser_create(id_chunk);
+       tester->assert_true(tester,(parser != NULL), "parser create check");
+       status = parser->parse_payload(parser, ID_INITIATOR, (payload_t**)&id_payload);
+       tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
+       parser->destroy(parser);
+       
+       if (status != SUCCESS)
+       {
+               return; 
+       }
+       result = id_payload->get_data(id_payload);
+       tester->assert_true(tester,(id_payload->get_initiator(id_payload) == TRUE), "is IDi payload");
+       tester->assert_true(tester,(id_payload->get_id_type(id_payload) == ID_IPV6_ADDR), "is ID_IPV6_ADDR ID type");
+       tester->assert_true(tester,(result.len == 12), "parsed data lenght");
+       tester->assert_false(tester,(memcmp(id_bytes + 8, result.ptr, result.len)), "parsed nonce data");
+       id_payload->destroy(id_payload);
+       allocator_free_chunk(&result);
+}
+
+
+/*
+ * Described in Header 
+ */
 void test_parser_with_ke_payload(tester_t *tester)
 {
        parser_t *parser;
index 48f3a1f..a80888f 100644 (file)
@@ -57,6 +57,16 @@ void test_parser_with_nonce_payload(tester_t *tester);
 
 /**
  * @brief Test function used to test the parser_t functionality when 
+ * parsing a ID payload.
+ *
+ * @param tester       associated tester_t object
+ * 
+ * @ingroup testcases
+ */
+void test_parser_with_id_payload(tester_t *tester);
+
+/**
+ * @brief Test function used to test the parser_t functionality when 
  * parsing a ke payload.
  *
  * @param tester       associated tester_t object
index ecbbb91..a672b15 100644 (file)
@@ -136,6 +136,7 @@ test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message wit
 test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"};
 test_t generator_test7 = {test_generator_with_notify_payload,"Generator: Notify Payload"};
 test_t generator_test8 = {test_generator_with_nonce_payload,"Generator: Nonce Payload"};
+test_t generator_test9 = {test_generator_with_id_payload,"Generator: ID Payload"};
 
 
 /**
@@ -164,6 +165,10 @@ test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payloa
  */
 test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"};
 
+/**
+ * Parser test for ike notify payload
+ */
+test_t parser_test6 = {test_parser_with_id_payload, "Parser: ID payload"};
 
 /**
  * Test for packet_t
@@ -274,12 +279,14 @@ logger_manager_t *global_logger_manager;
                &parser_test3,
                &parser_test4,
                &parser_test5,
+               &parser_test6,
                &generator_test3,
                &generator_test4,
                &generator_test5,
                &generator_test6,
                &generator_test7,
                &generator_test8,
+               &generator_test9,
                &ike_sa_manager_test,
                &packet_test,
                &diffie_hellman_test,
@@ -310,7 +317,7 @@ logger_manager_t *global_logger_manager;
 
 
        tester->perform_tests(tester,all_tests);
-//     tester->perform_test(tester,&hmac_signer_test2); 
+       //tester->perform_test(tester,&generator_test9); 
 
 
        
index f644b90..b27f3e7 100644 (file)
@@ -99,7 +99,6 @@ struct iterator_t {
         * with the resetted iterator.
         * 
         * @param this                  calling object
-        * @return                              SUCCESS in any case
         */
        void (*reset) (iterator_t *this);
 
@@ -107,7 +106,6 @@ struct iterator_t {
         * @brief Destroys an iterator.
         * 
         * @param this                  iterator to destroy
-        * @return                              SUCCESS in any case
         * 
         */
        void (*destroy) (iterator_t *this);
index c52211c..7f98b9d 100644 (file)
@@ -159,7 +159,7 @@ struct logger_t {
  * @param logger_name  name for the logger_t object
  * @param log_level            or'ed set of log_levels to assign to the new logger_t object
  * @param log_pid              TRUE if thread id should also be logged
- * @param output               FILE * if log has to go on a file output, NULL for syslog
+ * @param output                       FILE * if log has to go on a file output, NULL for syslog
  * @return                             logger_t object 
  * 
  * @ingroup utils