- support for key exchange payload
authorMartin Willi <martin@strongswan.org>
Tue, 15 Nov 2005 15:44:18 +0000 (15:44 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 15 Nov 2005 15:44:18 +0000 (15:44 -0000)
- tested

Source/charon/parser.c
Source/charon/payloads/payload.c
Source/charon/testcases/parser_test.c
Source/charon/testcases/parser_test.h
Source/charon/testcases/testcases.c

index e65f88f..fc034c5 100644 (file)
@@ -740,6 +740,16 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                }               
                                break;                  
                        }
+                       case KEY_EXCHANGE_DATA:
+                       {
+                               size_t keydata_length = payload_length - 8;
+                               if (this->parse_chunk(this, rule_number, output + rule->offset, keydata_length) != SUCCESS) 
+                               {
+                                       pld->destroy(pld);
+                                       return PARSE_ERROR;
+                               }               
+                               break;                  
+                       }
                        default:
                        {
                                this->logger->log(this->logger, ERROR, "  no rule to parse rule %d %s (%d)", rule_number, mapping_find(encoding_type_t_mappings, rule->type), rule->type);
index 22bb85b..f044138 100644 (file)
@@ -27,6 +27,7 @@
 #include "ike_header.h"
 #include "sa_payload.h"
 #include "nonce_payload.h"
+#include "ke_payload.h"
 
 
 
@@ -79,6 +80,8 @@ payload_t *payload_create(payload_type_t type)
                        return (payload_t*)transform_attribute_create();
                case NONCE:
                        return (payload_t*)nonce_payload_create();
+               case KEY_EXCHANGE:
+                       return (payload_t*)ke_payload_create();
                default:
                        return NULL;
        }
index 3540739..27b5523 100644 (file)
@@ -31,6 +31,7 @@
 #include "../payloads/ike_header.h"
 #include "../payloads/sa_payload.h"
 #include "../payloads/nonce_payload.h"
+#include "../payloads/ke_payload.h"
 
 
 extern logger_manager_t *global_logger_manager;
@@ -192,7 +193,6 @@ void test_parser_with_nonce_payload(tester_t *tester)
        status_t status;
        chunk_t nonce_chunk, result;
        
-       
        u_int8_t nonce_bytes[] = {
                0x00,0x00,0x00,0x14, /* payload header */
                        0x00,0x01,0x02,0x03,  /* 16 Byte nonce */
@@ -204,7 +204,6 @@ void test_parser_with_nonce_payload(tester_t *tester)
        nonce_chunk.ptr = nonce_bytes;
        nonce_chunk.len = sizeof(nonce_bytes);
 
-       
        parser = parser_create(nonce_chunk);
        tester->assert_true(tester,(parser != NULL), "parser create check");
        status = parser->parse_payload(parser, NONCE, (payload_t**)&nonce_payload);
@@ -215,14 +214,47 @@ void test_parser_with_nonce_payload(tester_t *tester)
        {
                return; 
        }
-
        nonce_payload->get_nonce(nonce_payload, &result);
-       
        tester->assert_true(tester,(result.len == 16), "parsed nonce lenght");
        tester->assert_false(tester,(memcmp(nonce_bytes + 4, result.ptr, result.len)), "parsed nonce data");
+       nonce_payload->destroy(nonce_payload);
+}
+
+/*
+ * Described in Header 
+ */
+void test_parser_with_ke_payload(tester_t *tester)
+{
+       parser_t *parser;
+       ke_payload_t *ke_payload;
+       status_t status;
+       chunk_t ke_chunk, result;
        
+       u_int8_t ke_bytes[] = {
+               0x00,0x00,0x00,0x18, /* payload header */
+               0x00,0x03,0x00,0x00, /* dh group 3 */ 
+                       0x01,0x02,0x03,0x03, /* 16 Byte dh data */
+                       0x04,0x05,0x06,0x07,
+                       0x08,0x09,0x0A,0x2B,
+                       0x0C,0x0D,0x0E,0x0F
+       };
        
-       
+       ke_chunk.ptr = ke_bytes;
+       ke_chunk.len = sizeof(ke_bytes);
 
-       nonce_payload->destroy(nonce_payload);
+       parser = parser_create(ke_chunk); 
+       tester->assert_true(tester,(parser != NULL), "parser create check");
+       status = parser->parse_payload(parser, KEY_EXCHANGE, (payload_t**)&ke_payload);
+       tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
+       tester->assert_true(tester,(parser->destroy(parser) == SUCCESS), "parser destroy call check");
+       
+       if (status != SUCCESS)
+       {
+               return; 
+       }
+       tester->assert_true(tester,(ke_payload->get_dh_group_number(ke_payload) == 3), "DH group");
+       result = ke_payload->get_key_exchange_data(ke_payload);
+       tester->assert_true(tester,(result.len == 16), "parsed key lenght");
+       tester->assert_false(tester,(memcmp(ke_bytes + 8, result.ptr, result.len)), "parsed key data");
+       ke_payload->destroy(ke_payload);
 }
index a59896b..6a36f66 100644 (file)
@@ -31,4 +31,6 @@ void test_parser_with_sa_payload(tester_t *tester);
 
 void test_parser_with_nonce_payload(tester_t *tester);
 
+void test_parser_with_ke_payload(tester_t *tester);
+
 #endif /*PARSER_TEST_H_*/
index 106ecee..b99c3e6 100644 (file)
@@ -145,6 +145,11 @@ test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"};
  */
 test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
 
+/**
+ * Parser test for ike nonce payload
+ */
+test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"};
+
 
 /**
  * Test for packet_t
@@ -223,7 +228,7 @@ logger_manager_t *global_logger_manager;
 
 
 //     tester->perform_tests(tester,all_tests);
-       tester->perform_test(tester,&parser_test3);   
+       tester->perform_test(tester,&parser_test4);   
 
        
        tester->destroy(tester);