DELETE payload implemented and tested
authorJan Hutter <jhutter@hsr.ch>
Mon, 5 Dec 2005 13:43:43 +0000 (13:43 -0000)
committerJan Hutter <jhutter@hsr.ch>
Mon, 5 Dec 2005 13:43:43 +0000 (13:43 -0000)
14 files changed:
Source/charon/encoding/generator.c
Source/charon/encoding/parser.c
Source/charon/encoding/payloads/Makefile.payloads
Source/charon/encoding/payloads/delete_payload.c [new file with mode: 0644]
Source/charon/encoding/payloads/delete_payload.h [new file with mode: 0644]
Source/charon/encoding/payloads/encodings.c
Source/charon/encoding/payloads/encodings.h
Source/charon/encoding/payloads/payload.c
Source/charon/encoding/payloads/proposal_substructure.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

index ee34219..a19cd36 100644 (file)
@@ -45,6 +45,7 @@
 #include <encoding/payloads/cert_payload.h>
 #include <encoding/payloads/certreq_payload.h>
 #include <encoding/payloads/ts_payload.h>
+#include <encoding/payloads/delete_payload.h>
 
 
 typedef struct private_generator_t private_generator_t;
@@ -740,6 +741,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
                        case AUTH_DATA:
                        case CERT_DATA:
                        case CERTREQ_DATA:
+                       case SPIS:
                        {
                                u_int32_t payload_length_position_offset;
                                u_int16_t length_of_payload;
@@ -769,6 +771,9 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
                                        case CERTREQ_DATA:
                                                header_length = CERTREQ_PAYLOAD_HEADER_LENGTH;
                                                break;
+                                       case SPIS:
+                                               header_length = DELETE_PAYLOAD_HEADER_LENGTH;
+                                               break;
                                        default:
                                                break;
                                }
index e57bee3..b0aefee 100644 (file)
@@ -46,6 +46,7 @@
 #include <encoding/payloads/cert_payload.h>
 #include <encoding/payloads/certreq_payload.h>
 #include <encoding/payloads/ts_payload.h>
+#include <encoding/payloads/delete_payload.h>
 
 
 typedef struct private_parser_t private_parser_t;
@@ -849,6 +850,16 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                }               
                                break;                  
                        }
+                       case SPIS:
+                       {
+                               size_t data_length = payload_length - DELETE_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 5ba6b53..a85822e 100644 (file)
@@ -49,6 +49,12 @@ $(BUILD_DIR)cert_payload.o :                 $(PAYLOADS_DIR)cert_payload.c $(PAYLOADS_DIR)cert
 OBJS+= $(BUILD_DIR)certreq_payload.o
 $(BUILD_DIR)certreq_payload.o :                        $(PAYLOADS_DIR)certreq_payload.c $(PAYLOADS_DIR)certreq_payload.h
                                                                                $(CC) $(CFLAGS) -c -o $@ $<
+
+OBJS+= $(BUILD_DIR)delete_payload.o
+$(BUILD_DIR)delete_payload.o :                 $(PAYLOADS_DIR)delete_payload.c $(PAYLOADS_DIR)delete_payload.h
+                                                                               $(CC) $(CFLAGS) -c -o $@ $<
+
+
 OBJS+= $(BUILD_DIR)ts_payload.o
 $(BUILD_DIR)ts_payload.o :                             $(PAYLOADS_DIR)ts_payload.c $(PAYLOADS_DIR)ts_payload.h
                                                                                $(CC) $(CFLAGS) -c -o $@ $<
diff --git a/Source/charon/encoding/payloads/delete_payload.c b/Source/charon/encoding/payloads/delete_payload.c
new file mode 100644 (file)
index 0000000..21f064e
--- /dev/null
@@ -0,0 +1,327 @@
+/**
+ * @file delete_payload.c
+ * 
+ * @brief Implementation of delete_payload_t.
+ * 
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "delete_payload.h"
+
+#include <utils/allocator.h>
+
+
+typedef struct private_delete_payload_t private_delete_payload_t;
+
+/**
+ * Private data of an delete_payload_t object.
+ * 
+ */
+struct private_delete_payload_t {
+       /**
+        * Public delete_payload_t interface.
+        */
+       delete_payload_t public;
+       
+       /**
+        * Next payload type.
+        */
+       u_int8_t  next_payload;
+
+       /**
+        * Critical flag.
+        */
+       bool critical;
+       
+       /**
+        * Length of this payload.
+        */
+       u_int16_t payload_length;
+       
+       /**
+        * Protocol ID.
+        */
+       u_int8_t protocol_id;
+
+       /**
+        * SPI Size.
+        */
+       u_int8_t spi_size;
+       
+       /**
+        * Number of SPI's.
+        */
+       u_int16_t spi_count;
+       
+       /**
+        * The contained SPI's.
+        */
+       chunk_t spis;
+};
+
+/**
+ * Encoding rules to parse or generate a DELETE payload
+ * 
+ * The defined offsets are the positions in a object of type 
+ * private_delete_payload_t.
+ * 
+ */
+encoding_rule_t delete_payload_encodings[] = {
+       /* 1 Byte next payload type, stored in the field next_payload */
+       { U_INT_8,                      offsetof(private_delete_payload_t, next_payload)        },
+       /* the critical bit */
+       { FLAG,                         offsetof(private_delete_payload_t, critical)            },
+       /* 7 Bit reserved bits, nowhere stored */
+       { RESERVED_BIT, 0                                                                                                               },
+       { RESERVED_BIT, 0                                                                                                               },
+       { RESERVED_BIT, 0                                                                                                               },
+       { RESERVED_BIT, 0                                                                                                               },
+       { RESERVED_BIT, 0                                                                                                               },
+       { RESERVED_BIT, 0                                                                                                               },
+       { RESERVED_BIT, 0                                                                                                               },
+       /* Length of the whole payload*/
+       { PAYLOAD_LENGTH,       offsetof(private_delete_payload_t, payload_length)},
+       { U_INT_8,                      offsetof(private_delete_payload_t, protocol_id)         },
+       { U_INT_8,                      offsetof(private_delete_payload_t, spi_size)            },
+       { U_INT_16,                     offsetof(private_delete_payload_t, spi_count)           },
+       /* some delete data bytes, length is defined in PAYLOAD_LENGTH */
+       { SPIS,                 offsetof(private_delete_payload_t, spis)                                }
+};
+
+/*
+                           1                   2                   3
+       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+      ! Next Payload  !C!  RESERVED   !         Payload Length        !
+      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+      ! Protocol ID   !   SPI Size    !           # of SPIs           !
+      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+      !                                                               !
+      ~               Security Parameter Index(es) (SPI)              ~
+      !                                                               !
+      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+*/
+
+/**
+ * Implementation of payload_t.verify.
+ */
+static status_t verify(private_delete_payload_t *this)
+{
+       if (this->critical)
+       {
+               /* critical bit is set! */
+               return FAILED;
+       }
+       if ((this->protocol_id == 0) ||
+               (this->protocol_id > 3))
+       {
+               /* reserved IDs */
+               return FAILED;
+       }
+       if (this->spis.len != (this->spi_count * this->spi_size))
+       {
+               return FAILED;
+       }
+       if ((this->protocol_id == IKE) && (this->spis.len != 0))
+       {
+               /* IKE deletion has no spi assigned! */
+               return FAILED;
+       }
+       
+       
+       return SUCCESS;
+}
+
+/**
+ * Implementation of delete_payload_t.get_encoding_rules.
+ */
+static void get_encoding_rules(private_delete_payload_t *this, encoding_rule_t **rules, size_t *rule_count)
+{
+       *rules = delete_payload_encodings;
+       *rule_count = sizeof(delete_payload_encodings) / sizeof(encoding_rule_t);
+}
+
+/**
+ * Implementation of payload_t.get_type.
+ */
+static payload_type_t get_payload_type(private_delete_payload_t *this)
+{
+       return DELETE;
+}
+
+/**
+ * Implementation of payload_t.get_next_type.
+ */
+static payload_type_t get_next_type(private_delete_payload_t *this)
+{
+       return (this->next_payload);
+}
+
+/**
+ * Implementation of payload_t.set_next_type.
+ */
+static void set_next_type(private_delete_payload_t *this,payload_type_t type)
+{
+       this->next_payload = type;
+}
+
+/**
+ * Implementation of payload_t.get_length.
+ */
+static size_t get_length(private_delete_payload_t *this)
+{
+       return this->payload_length;
+}
+
+/**
+ * Implementation of delete_payload_t.set_protocol_id.
+ */
+static void set_protocol_id (private_delete_payload_t *this, protocol_id_t protocol_id)
+{
+       this->protocol_id = protocol_id;
+}
+
+/**
+ * Implementation of delete_payload_t.get_protocol_id.
+ */
+static protocol_id_t get_protocol_id (private_delete_payload_t *this)
+{
+       return (this->protocol_id);
+}
+
+/**
+ * Implementation of delete_payload_t.set_spi_size.
+ */
+static void set_spi_size (private_delete_payload_t *this, u_int8_t spi_size)
+{
+       this->spi_size = spi_size;
+}
+
+/**
+ * Implementation of delete_payload_t.get_spi_size.
+ */
+static u_int8_t get_spi_size (private_delete_payload_t *this)
+{
+       return (this->spi_size);
+}
+
+/**
+ * Implementation of delete_payload_t.set_spi_count.
+ */
+static void set_spi_count (private_delete_payload_t *this, u_int16_t spi_count)
+{
+       this->spi_count = spi_count;
+}
+
+/**
+ * Implementation of delete_payload_t.get_spi_count.
+ */
+static u_int16_t get_spi_count (private_delete_payload_t *this)
+{
+       return (this->spi_count);
+}
+
+
+/**
+ * Implementation of delete_payload_t.set_spis.
+ */
+static void set_spis (private_delete_payload_t *this, chunk_t spis)
+{
+       if (this->spis.ptr != NULL)
+       {
+               allocator_free_chunk(&(this->spis));
+       }
+       this->spis.ptr = allocator_clone_bytes(spis.ptr,spis.len);
+       this->spis.len = spis.len;
+       this->payload_length = DELETE_PAYLOAD_HEADER_LENGTH + this->spis.len;
+}
+
+/**
+ * Implementation of delete_payload_t.get_spis.
+ */
+static chunk_t get_spis (private_delete_payload_t *this)
+{
+       return (this->spis);
+}
+
+/**
+ * Implementation of delete_payload_t.get_spis_clone.
+ */
+static chunk_t get_spis_clone (private_delete_payload_t *this)
+{
+       chunk_t cloned_spis;
+       if (this->spis.ptr == NULL)
+       {
+               return (this->spis);
+       }
+       cloned_spis.ptr = allocator_clone_bytes(this->spis.ptr,this->spis.len);
+       cloned_spis.len = this->spis.len;
+       return cloned_spis;
+}
+
+/**
+ * Implementation of payload_t.destroy and delete_payload_t.destroy.
+ */
+static void destroy(private_delete_payload_t *this)
+{
+       if (this->spis.ptr != NULL)
+       {
+               allocator_free_chunk(&(this->spis));
+       }
+       
+       allocator_free(this);   
+}
+
+/*
+ * Described in header
+ */
+delete_payload_t *delete_payload_create()
+{
+       private_delete_payload_t *this = allocator_alloc_thing(private_delete_payload_t);
+
+       /* interface functions */
+       this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
+       this->public.payload_interface.get_encoding_rules = (void (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules;
+       this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length;
+       this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type;
+       this->public.payload_interface.set_next_type = (void (*) (payload_t *,payload_type_t)) set_next_type;
+       this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_payload_type;
+       this->public.payload_interface.destroy = (void (*) (payload_t *))destroy;
+       
+       /* public functions */
+       this->public.destroy = (void (*) (delete_payload_t *)) destroy;
+       this->public.set_protocol_id = (void (*) (delete_payload_t *,protocol_id_t)) set_protocol_id;
+       this->public.get_protocol_id = (protocol_id_t (*) (delete_payload_t *)) get_protocol_id;
+       this->public.set_spi_size = (void (*) (delete_payload_t *,u_int8_t)) set_spi_size;
+       this->public.get_spi_size = (u_int8_t (*) (delete_payload_t *)) get_spi_size;
+       this->public.set_spi_count = (void (*) (delete_payload_t *,u_int16_t)) set_spi_count;
+       this->public.get_spi_count = (u_int16_t (*) (delete_payload_t *)) get_spi_count;
+       this->public.set_spis = (void (*) (delete_payload_t *,chunk_t)) set_spis;
+       this->public.get_spis_clone = (chunk_t (*) (delete_payload_t *)) get_spis_clone;
+       this->public.get_spis = (chunk_t (*) (delete_payload_t *)) get_spis;
+       
+       /* private variables */
+       this->critical = FALSE;
+       this->next_payload = NO_PAYLOAD;
+       this->payload_length =DELETE_PAYLOAD_HEADER_LENGTH;
+       this->protocol_id = UNDEFINED_PROTOCOL_ID;
+       this->spi_size = 0;
+       this->spi_count = 0;
+       this->spis = CHUNK_INITIALIZER;
+
+       return (&(this->public));
+}
diff --git a/Source/charon/encoding/payloads/delete_payload.h b/Source/charon/encoding/payloads/delete_payload.h
new file mode 100644 (file)
index 0000000..dae90aa
--- /dev/null
@@ -0,0 +1,154 @@
+/**
+ * @file delete_payload.h
+ * 
+ * @brief Interface of delete_payload_t.
+ * 
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef _DELETE_PAYLOAD_H_
+#define _DELETE_PAYLOAD_H_
+
+#include <types.h>
+#include <encoding/payloads/payload.h>
+#include <encoding/payloads/proposal_substructure.h>
+
+/**
+ * Length of a delete payload without the SPI in bytes.
+ * 
+ * @ingroup payloads
+ */
+#define DELETE_PAYLOAD_HEADER_LENGTH 8
+
+
+
+typedef struct delete_payload_t delete_payload_t;
+
+/**
+ * Object representing an IKEv2 DELETE payload.
+ * 
+ * The DELETE payload format is described in draft section 3.11.
+ * 
+ * @ingroup payloads
+ * 
+ */
+struct delete_payload_t {
+       /**
+        * The payload_t interface.
+        */
+       payload_t payload_interface;
+
+       /**
+        * @brief Set the protocol ID.
+        * 
+        *
+        * @param this                  calling delete_payload_t object
+        * @param protocol_id   protocol ID
+        */
+       void (*set_protocol_id) (delete_payload_t *this, protocol_id_t protocol_id);
+       
+       /**
+        * @brief Get the protocol ID.
+        *
+        * @param this                  calling delete_payload_t object
+        * @return                              protocol ID
+        */
+       protocol_id_t (*get_protocol_id) (delete_payload_t *this);
+       
+       /**
+        * @brief Set the SPI size.
+        * 
+        *
+        * @param this                  calling delete_payload_t object
+        * @param spi_size              SPI size
+        */
+       void (*set_spi_size) (delete_payload_t *this, u_int8_t spi_size);
+       
+       /**
+        * @brief Get the SPI size.
+        *
+        * @param this                  calling delete_payload_t object
+        * @return                               SPI size
+        */
+       u_int8_t (*get_spi_size) (delete_payload_t *this);
+       
+       /**
+        * @brief Set the SPI count.
+        * 
+        *
+        * @param this                  calling delete_payload_t object
+        * @param spi_count             SPI count
+        */
+       void (*set_spi_count) (delete_payload_t *this, u_int16_t spi_count);
+       
+       /**
+        * @brief Get the SPI count.
+        *
+        * @param this                  calling delete_payload_t object
+        * @return                              Number of SPI's
+        */
+       u_int16_t (*get_spi_count) (delete_payload_t *this);
+       
+       /**
+        * @brief Set the SPI's.
+        * 
+        * Data are getting cloned.
+        *
+        * @param this                  calling delete_payload_t object
+        * @param data                  SPI's as chunk_t
+        */
+       void (*set_spis) (delete_payload_t *this, chunk_t spis);
+       
+       /**
+        * @brief Get the SPI's.
+        * 
+        * Returned data are a copy of the internal one.
+        *
+        * @param this                  calling delete_payload_t object
+        * @return                              SPI's chunk_t
+        */
+       chunk_t (*get_spis_clone) (delete_payload_t *this);
+       
+       /**
+        * @brief Get the SPI's.
+        * 
+        * Returned data are NOT copied.
+        *
+        * @param this                  calling delete_payload_t object
+        * @return                              SPI's as chunk_t
+        */
+       chunk_t (*get_spis) (delete_payload_t *this);
+       
+       /**
+        * @brief Destroys an delete_payload_t object.
+        *
+        * @param this  delete_payload_t object to destroy
+        */
+       void (*destroy) (delete_payload_t *this);
+};
+
+/**
+ * @brief Creates an empty delete_payload_t object.
+ * 
+ * @return                             created delete_payload_t object
+ * 
+ * @ingroup payloads
+ */
+delete_payload_t *delete_payload_create();
+
+
+#endif //_DELETE_PAYLOAD_H_
index 58887d8..2172671 100644 (file)
@@ -56,5 +56,6 @@ mapping_t encoding_type_m[] = {
        {TRAFFIC_SELECTORS, "TRAFFIC_SELECTORS"},
        {CERT_DATA, "CERT_DATA"},
        {CERTREQ_DATA, "CERTREQ_DATA"},
+       {SPIS, "SPIS"},
        {MAPPING_END, NULL}
 };
index fe76104..79740c3 100644 (file)
@@ -387,6 +387,16 @@ enum encoding_type_t{
         * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
         */
        CERTREQ_DATA,
+       
+       /**
+        * Representating the SPIS field in a DELETE payload.
+        * 
+        * 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.
+        */
+       SPIS,
 
        /**
         * Representating an IKE_SPI field in an IKEv2 Header.
index bf0134c..fda5963 100644 (file)
@@ -35,6 +35,7 @@
 #include <encoding/payloads/certreq_payload.h>
 #include <encoding/payloads/encryption_payload.h>
 #include <encoding/payloads/ts_payload.h>
+#include <encoding/payloads/delete_payload.h>
 
 /*
  * build the mappings for payload_type_t
@@ -104,6 +105,8 @@ payload_t *payload_create(payload_type_t type)
                        return (payload_t*)ke_payload_create();
                case NOTIFY:
                        return (payload_t*)notify_payload_create();
+               case DELETE:
+                       return (payload_t*)delete_payload_create();
                case ENCRYPTED:
                        return (payload_t*)encryption_payload_create();
                default:
index e207e77..43ebb43 100644 (file)
@@ -167,7 +167,7 @@ static status_t verify(private_proposal_substructure_t *this)
                return FAILED;
        }
 
-       if (this->protocol_id > 4)
+       if ((this->protocol_id == 0) || (this->protocol_id >= 4))
        {
                /* reserved are not supported */
                return FAILED;
index bb40b00..75075f2 100644 (file)
@@ -43,6 +43,7 @@
 #include <encoding/payloads/cert_payload.h>
 #include <encoding/payloads/certreq_payload.h>
 #include <encoding/payloads/ts_payload.h>
+#include <encoding/payloads/delete_payload.h>
 
 /*
  * Described in Header 
@@ -1201,7 +1202,7 @@ void test_generator_with_certreq_payload(tester_t *tester)
        chunk_t generated_data;
        chunk_t certreq;
        
-       logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with CERT Payload");
+       logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with CERTREQ Payload");
        
        /* create generator */
        generator = generator_create();
@@ -1241,3 +1242,57 @@ void test_generator_with_certreq_payload(tester_t *tester)
                
        charon->logger_manager->destroy_logger(charon->logger_manager,logger);  
 }
+
+/*
+ * Described in header.
+ */ 
+void test_generator_with_delete_payload(tester_t *tester)
+{
+       generator_t *generator;
+       delete_payload_t *delete_payload;
+       logger_t *logger;
+       chunk_t generated_data;
+       chunk_t spis;
+       
+       logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"Message with DELETE Payload");
+       
+       /* create generator */
+       generator = generator_create();
+       tester->assert_true(tester,(generator != NULL), "generator create check");
+       
+       delete_payload = delete_payload_create();
+       
+       
+       spis.ptr = "123456789012";
+       spis.len = strlen(spis.ptr);
+
+       delete_payload->set_protocol_id(delete_payload,AH);
+       delete_payload->set_spi_count(delete_payload,3);
+       delete_payload->set_spi_size(delete_payload,4);
+       delete_payload->set_spis(delete_payload,spis);
+       
+       generator->generate_payload(generator,(payload_t *)delete_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,
+               0x02,0x04,0x00,0x03,
+               /* delete 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);
+       
+       delete_payload->destroy(delete_payload);
+       generator->destroy(generator);
+               
+       charon->logger_manager->destroy_logger(charon->logger_manager,logger);  
+}
index 4ea7258..2f7828b 100644 (file)
@@ -134,7 +134,6 @@ void test_generator_with_ts_payload(tester_t *tester);
  */
 void test_generator_with_cert_payload(tester_t *tester);
 
-
 /**
  * @brief Test function used to test the generator with CERTREQ payload.
  * 
@@ -144,5 +143,14 @@ void test_generator_with_cert_payload(tester_t *tester);
  */
 void test_generator_with_certreq_payload(tester_t *tester);
 
+/**
+ * @brief Test function used to test the generator with DELETE payload.
+ * 
+ * @param tester associated tester_t object
+ * 
+ * @ingroup testcases
+ */
+void test_generator_with_delete_payload(tester_t *tester);
+
 
 #endif /*GENERATOR_TEST_H_*/
index 2de5806..5bf92fa 100644 (file)
@@ -39,6 +39,7 @@
 #include <encoding/payloads/cert_payload.h>
 #include <encoding/payloads/certreq_payload.h>
 #include <encoding/payloads/ts_payload.h>
+#include <encoding/payloads/delete_payload.h>
 
 
 /*
@@ -772,3 +773,45 @@ void test_parser_with_certreq_payload(tester_t *tester)
        allocator_free_chunk(&result);
 }
 
+/*
+ * Described in Header 
+ */
+void test_parser_with_delete_payload(tester_t *tester)
+{
+       parser_t *parser;
+       delete_payload_t *delete_payload;
+       status_t status;
+       chunk_t delete_chunk, result;
+       
+       u_int8_t delete_bytes[] = {
+               0x00,0x00,0x00,0x14, /* payload header */
+               0x03,0x03,0x00,0x04,
+                       0x04,0x05,0x06,0x07,/* 12 Byte data */
+                       0x08,0x09,0x0A,0x2B,
+                       0x0C,0x0D,0x0E,0x0F
+       };
+       
+       delete_chunk.ptr = delete_bytes;
+       delete_chunk.len = sizeof(delete_bytes);
+
+       parser = parser_create(delete_chunk);
+       tester->assert_true(tester,(parser != NULL), "parser create check");
+       status = parser->parse_payload(parser, DELETE, (payload_t**)&delete_payload);
+       tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
+       parser->destroy(parser);
+       
+       if (status != SUCCESS)
+       {
+               return; 
+       }
+       result = delete_payload->get_spis(delete_payload);
+       tester->assert_true(tester,(delete_payload->get_protocol_id(delete_payload) == ESP), "is ESP protocol");
+       tester->assert_true(tester,(delete_payload->get_spi_size(delete_payload) == 3), "SPI size check");
+       tester->assert_true(tester,(delete_payload->get_spi_count(delete_payload) == 4), "SPI count check");
+       tester->assert_true(tester,(result.len == 12), "parsed data lenght");
+       tester->assert_false(tester,(memcmp(delete_bytes + 8, result.ptr, result.len)), "parsed data");
+       tester->assert_true(tester,(((payload_t *)delete_payload)->verify((payload_t *)delete_payload) == SUCCESS), "verify check");
+       
+       delete_payload->destroy(delete_payload);
+}
+
index f0a79b8..0de8005 100644 (file)
@@ -125,4 +125,14 @@ void test_parser_with_cert_payload(tester_t *tester);
  */
 void test_parser_with_certreq_payload(tester_t *tester);
 
+/**
+ * @brief Test function used to test the parser_t functionality when 
+ * parsing a CERTREQ payload.
+ *
+ * @param tester       associated tester_t object
+ * 
+ * @ingroup testcases
+ */
+void test_parser_with_delete_payload(tester_t *tester);
+
 #endif /*PARSER_TEST_H_*/
index 011195a..3226126 100644 (file)
@@ -91,6 +91,7 @@ test_t generator_test10 = {test_generator_with_auth_payload,"Generator: AUTH Pay
 test_t generator_test11 = {test_generator_with_ts_payload,"Generator: TS Payload"};
 test_t generator_test12 = {test_generator_with_cert_payload,"Generator: CERT Payload"};
 test_t generator_test13 = {test_generator_with_certreq_payload,"Generator: CERTREQ Payload"};
+test_t generator_test14 = {test_generator_with_delete_payload,"Generator: DELETE Payload"};
 test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"};
 test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"};
 test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
@@ -101,6 +102,7 @@ test_t parser_test7 = {test_parser_with_auth_payload, "Parser: AUTH payload"};
 test_t parser_test8 = {test_parser_with_ts_payload, "Parser: TS payload"};
 test_t parser_test9 = {test_parser_with_cert_payload, "Parser: CERT payload"};
 test_t parser_test10 = {test_parser_with_certreq_payload, "Parser: CERTREQ payload"};
+test_t parser_test11 = {test_parser_with_delete_payload, "Parser: DELETE payload"};
 test_t packet_test = {test_packet,"Packet"};
 test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"};
 test_t sha1_hasher_test = {test_sha1_hasher,"SHA1 hasher"};
@@ -192,6 +194,7 @@ int main()
                &parser_test8,
                &parser_test9,
                &parser_test10,
+               &parser_test11,
                &generator_test3,
                &generator_test4,
                &generator_test5,
@@ -203,6 +206,7 @@ int main()
                &generator_test11,
                &generator_test12,
                &generator_test13,
+               &generator_test14,
                &ike_sa_manager_test,
                &packet_test,
                &diffie_hellman_test,
@@ -233,8 +237,8 @@ int main()
        tester_t *tester = tester_create(test_output, FALSE);
        
 
-       tester->perform_tests(tester,all_tests);
-//     tester->perform_test(tester,&generator_test13); 
+//     tester->perform_tests(tester,all_tests);
+       tester->perform_test(tester,&parser_test11); 
        
        
        tester->destroy(tester);