../svn-commit.tmp

This commit is contained in:
Martin Willi
2006-04-05 12:10:50 +00:00
parent 3dbbbf3e16
commit 6862128151
171 changed files with 674 additions and 1355 deletions
-220
View File
@@ -1,220 +0,0 @@
# Doxyfile 1.4.1-KDevelop
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = "charon - IKEv2 for strongSwan"
PROJECT_NUMBER = 1.0
OUTPUT_DIRECTORY = doc/api
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = YES
INHERIT_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 1
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = NO
EXTRACT_LOCAL_METHODS = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = NO
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST = YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = NO
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = ./
FILE_PATTERNS = *.h
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = NO
REFERENCES_RELATION = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = .
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = YES
ENUM_VALUES_PER_LINE = 1
GENERATE_TREEVIEW = YES
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = YES
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = LEAK_DETECTIVE
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO
-100
View File
@@ -1,100 +0,0 @@
# 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.
#
FREESWANSRCDIR=../..
# include strongswan Makefile, if charon sits in its tree
ifeq ($(shell ls $(FREESWANSRCDIR)/Makefile.inc 2>&1), ../../Makefile.inc)
include ${FREESWANSRCDIR}/Makefile.inc
endif
BUILD_DIR= ./bin/
BINNAMECHARON= $(BUILD_DIR)charon
BINNAMESTROKE= $(BUILD_DIR)stroke
BINNAMETEST= $(BUILD_DIR)run_tests
MAIN_DIR= ./
LDFLAGS= -lgmp -lpthread
CFLAGS+= -I. -O3#-Wall -g -DLEAK_DETECTIVE
# objects is extended by each included Makefile
OBJS=
all : build_dir $(BINNAMECHARON) $(BINNAMESTROKE)
programs : all
test : build_dir $(BINNAMETEST)
$(BINNAMETEST)
apidoc :
doxygen Doxyfile
include $(MAIN_DIR)network/Makefile.network
include $(MAIN_DIR)config/Makefile.config
include $(MAIN_DIR)encoding/Makefile.encoding
include $(MAIN_DIR)queues/Makefile.queues
include $(MAIN_DIR)sa/Makefile.sa
include $(MAIN_DIR)threads/Makefile.threads
include $(MAIN_DIR)transforms/Makefile.transforms
include $(MAIN_DIR)utils/Makefile.utils
include $(MAIN_DIR)asn1/Makefile.asn1
build_dir:
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)daemon.o : daemon.c daemon.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+=$(BUILD_DIR)types.o
$(BUILD_DIR)types.o : types.c types.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+=$(BUILD_DIR)definitions.o
$(BUILD_DIR)definitions.o : definitions.c definitions.h
$(CC) $(CFLAGS) -c -o $@ $<
$(BINNAMECHARON) : $(OBJS) $(BUILD_DIR)daemon.o
$(CC) $(LDFLAGS) $(OBJS) $(BUILD_DIR)daemon.o -o $@
$(BINNAMESTROKE) : stroke.c
$(CC) $(LDFLAGS) $(CFLAGS) stroke.c -o $@
TEST_OBJS = $(OBJS)
include $(MAIN_DIR)testcases/Makefile.testcases
$(BUILD_DIR)run_tests : build_dir $(TEST_OBJS)
$(CC) $(LDFLAGS) $(TEST_OBJS) -o $@
install : $(BINNAMECHARON)
$(INSTALL) $(INSTBINFLAGS) $(BINNAMECHARON) $(BINNAMESTROKE) $(LIBEXECDIR)
install_file_list:
@echo $(LIBEXECDIR)/charon
@echo $(LIBEXECDIR)/stroke
clean :
rm -fR $(BUILD_DIR); rm -Rf doc/api
cleanall: clean
distclean: clean
mostlyclean: clean
realclean: clean
@@ -1,4 +1,4 @@
# Copyright (C) 2005 Jan Hutter, Martin Willi
# Copyright (C) 2006 Martin Willi
# Hochschule fuer Technik Rapperswil
#
# This program is free software; you can redistribute it and/or modify it
@@ -11,13 +11,15 @@
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
CHARON_DIR= $(MAIN_DIR)charon/
PRFS_DIR= $(TRANSFORMS_DIR)prfs/
$(BUILD_DIR)daemon.o : $(CHARON_DIR)daemon.c $(CHARON_DIR)daemon.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)prf.o
$(BUILD_DIR)prf.o : $(PRFS_DIR)prf.c $(PRFS_DIR)prf.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)hmac_prf.o
$(BUILD_DIR)hmac_prf.o : $(PRFS_DIR)hmac_prf.c $(PRFS_DIR)hmac_prf.h
$(CC) $(CFLAGS) -c -o $@ $<
include $(CHARON_DIR)network/Makefile.network
include $(CHARON_DIR)config/Makefile.config
include $(CHARON_DIR)encoding/Makefile.encoding
include $(CHARON_DIR)queues/Makefile.queues
include $(CHARON_DIR)sa/Makefile.sa
include $(CHARON_DIR)threads/Makefile.threads
-24
View File
@@ -1,24 +0,0 @@
# 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.
#
ASN1_DIR= $(MAIN_DIR)asn1/
OBJS+= $(BUILD_DIR)asn1.o
$(BUILD_DIR)asn1.o : $(ASN1_DIR)asn1.c $(ASN1_DIR)asn1.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)der_decoder.o
$(BUILD_DIR)der_decoder.o : $(ASN1_DIR)der_decoder.c $(ASN1_DIR)der_decoder.h
$(CC) $(CFLAGS) -c -o $@ $<
-74
View File
@@ -1,74 +0,0 @@
/**
* @file asn1.c
*
* @brief String mappings for asn1.h
*
*/
/*
* Copyright (C) 2006 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 "asn1.h"
mapping_t asn1_type_m[] = {
{ASN1_END, "ASN1_END"},
{ASN1_BOOLEAN, "ASN1_BOOLEAN"},
{ASN1_INTEGER, "ASN1_INTEGER"},
{ASN1_BITSTRING, "ASN1_BITSTRING"},
{ASN1_OCTETSTRING, "ASN1_OCTETSTRING"},
{ASN1_NULL, "ASN1_NULL"},
{ASN1_OID, "ASN1_OID"},
{ASN1_ENUMERATED, "ASN1_ENUMERATED"},
{ASN1_UTF8STRING, "ASN1_UTF8STRING"},
{ASN1_NUMERICSTRING, "ASN1_NUMERICSTRING"},
{ASN1_PRINTABLESTRING, "ASN1_PRINTABLESTRING"},
{ASN1_T61STRING, "ASN1_T61STRING"},
{ASN1_VIDEOTEXSTRING, "ASN1_VIDEOTEXSTRING"},
{ASN1_IA5STRING, "ASN1_IA5STRING"},
{ASN1_UTCTIME, "ASN1_UTCTIME"},
{ASN1_GENERALIZEDTIME, "ASN1_GENERALIZEDTIME"},
{ASN1_GRAPHICSTRING, "ASN1_GRAPHICSTRING"},
{ASN1_VISIBLESTRING, "ASN1_VISIBLESTRING"},
{ASN1_GENERALSTRING, "ASN1_GENERALSTRING"},
{ASN1_UNIVERSALSTRING, "ASN1_UNIVERSALSTRING"},
{ASN1_BMPSTRING, "ASN1_BMPSTRING"},
{ASN1_CONSTRUCTED, "ASN1_CONSTRUCTED"},
{ASN1_SEQUENCE, "ASN1_SEQUENCE"},
{ASN1_SET, "ASN1_SET"},
{ASN1_TAG_E_0, "ASN1_TAG_E_0"},
{ASN1_TAG_E_1, "ASN1_TAG_E_1"},
{ASN1_TAG_E_2, "ASN1_TAG_E_2"},
{ASN1_TAG_E_3, "ASN1_TAG_E_3"},
{ASN1_TAG_E_4, "ASN1_TAG_E_4"},
{ASN1_TAG_E_5, "ASN1_TAG_E_5"},
{ASN1_TAG_E_6, "ASN1_TAG_E_6"},
{ASN1_TAG_E_7, "ASN1_TAG_E_7"},
{ASN1_TAG_I_0, "ASN1_TAG_I_0"},
{ASN1_TAG_I_1, "ASN1_TAG_I_1"},
{ASN1_TAG_I_2, "ASN1_TAG_I_2"},
{ASN1_TAG_I_3, "ASN1_TAG_I_3"},
{ASN1_TAG_I_4, "ASN1_TAG_I_4"},
{ASN1_TAG_I_5, "ASN1_TAG_I_5"},
{ASN1_TAG_I_6, "ASN1_TAG_I_6"},
{ASN1_TAG_I_7, "ASN1_TAG_I_7"},
{ASN1_CHOICE, "ASN1_CHOICE"},
};
mapping_t asn1_flag_m[] = {
{ASN1_OPTIONAL, "ASN1_OPTIONAL"},
{ASN1_DEFAULT, "ASN1_DEFAULT"},
{ASN1_MPZ, "ASN1_MPZ"},
{ASN1_OF, "ASN1_OF"},
};
-172
View File
@@ -1,172 +0,0 @@
/**
* @file asn1.h
*
* @brief Definition of asn1_rule_t and other ASN1 stuff.
*
*/
/*
* Copyright (C) 2006 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 ASN1_H_
#define ASN1_H_
#include <types.h>
typedef enum asn1_type_t asn1_type_t;
/**
* @brief Real and some special ASN1 types.
*
* @ingroup asn1
*/
enum asn1_type_t {
/**
* End of a sequence, set, choice
*/
ASN1_END = 0x00,
ASN1_BOOLEAN = 0x01,
ASN1_INTEGER = 0x02,
ASN1_BITSTRING = 0x03,
ASN1_OCTETSTRING = 0x04,
ASN1_NULL = 0x05,
ASN1_OID = 0x06,
ASN1_ENUMERATED = 0x0A,
ASN1_UTF8STRING = 0x0C,
ASN1_NUMERICSTRING = 0x12,
ASN1_PRINTABLESTRING = 0x13,
ASN1_T61STRING = 0x14,
ASN1_VIDEOTEXSTRING = 0x15,
ASN1_IA5STRING = 0x16,
ASN1_UTCTIME = 0x17,
ASN1_GENERALIZEDTIME = 0x18,
ASN1_GRAPHICSTRING = 0x19,
ASN1_VISIBLESTRING = 0x1A,
ASN1_GENERALSTRING = 0x1B,
ASN1_UNIVERSALSTRING = 0x1C,
ASN1_BMPSTRING = 0x1E,
ASN1_CONSTRUCTED = 0x20,
ASN1_SEQUENCE = 0x30,
ASN1_SET = 0x31,
/**
* EXCPLICIT tags
*/
ASN1_TAG_E_0 = 0xA0,
ASN1_TAG_E_1 = 0xA1,
ASN1_TAG_E_2 = 0xA2,
ASN1_TAG_E_3 = 0xA3,
ASN1_TAG_E_4 = 0xA4,
ASN1_TAG_E_5 = 0xA5,
ASN1_TAG_E_6 = 0xA6,
ASN1_TAG_E_7 = 0xA7,
/**
* IMPLICIT tags
*/
ASN1_TAG_I_0 = 0x80,
ASN1_TAG_I_1 = 0x81,
ASN1_TAG_I_2 = 0x82,
ASN1_TAG_I_3 = 0x83,
ASN1_TAG_I_4 = 0x84,
ASN1_TAG_I_5 = 0x85,
ASN1_TAG_I_6 = 0x86,
ASN1_TAG_I_7 = 0x87,
/**
* Begin of a choice
*/
ASN1_CHOICE = 0xFE,
/**
* ANY type
*/
ASN1_ANY = 0xFF,
};
/**
* String mappings for asn1_type_t
*/
extern mapping_t asn1_type_m[];
typedef enum asn1_flag_t asn1_flag_t;
/**
* @brief Flags used to build ASN1 rules.
*
* @ingroup asn1
*/
enum asn1_flag_t {
/**
* Field is optional
*/
ASN1_OPTIONAL = 0x01,
/**
* Field has a default value and is therefore optional
*/
ASN1_DEFAULT = 0x02,
/**
* Convert this INTEGER to an mpz_t
*/
ASN1_MPZ = 0x04,
/**
* SEQUENCE or SET OF
*/
ASN1_OF = 0x08,
/**
* Parse this Sequence in a RAW chunk too.
* Used for crypto calculations...
*/
ASN1_RAW = 0x10,
};
/**
* String mappings for asn1_flag_t
*/
extern mapping_t asn1_flag_m[];
typedef struct asn1_rule_t asn1_rule_t;
/**
* @brief Single rule of a complet ruleset.
*
* This rule containing a type, flags and additional
* data allow modellation of complex ASN1 structures and
* allow their en- and decoding...
*
* @ingroup asn1
*/
struct asn1_rule_t {
/**
* ASN1 type
*/
asn1_type_t type;
/**
* implicit or explicit tag, if any
*/
asn1_flag_t flags;
/**
* offset of data in structure
*/
u_int data_offset;
/**
* offset to a boolean, which says if optional
* data is available at data_offset. Used if
* flags & ASN1_OPTIONAL.
* default value, used if flags & ASN1_DEFAULT
*/
u_int additional;
};
#endif /* ASN1_H_ */
-501
View File
@@ -1,501 +0,0 @@
/**
* @file der_decoder.c
*
* @brief Implementation of der_decoder_t.
*/
/*
* Copyright (C) 2000-2004 Andreas Steffen
* Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* Some parts taken over from pluto/asn1.c
*
* 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 <gmp.h>
#include "der_decoder.h"
#include <utils/allocator.h>
#include <daemon.h>
typedef struct private_der_decoder_t private_der_decoder_t;
/**
* Private data of a der_decoder_t object.
*/
struct private_der_decoder_t {
/**
* Public interface for this signer.
*/
der_decoder_t public;
/**
* Rule which was just processed
*/
asn1_rule_t *rule;
/**
* First rule of the whole ruleset
*/
asn1_rule_t *first_rule;
/**
* Output data struct
*/
void *output;
/**
* Complex things like this need a logger ;-)
*/
logger_t *logger;
};
status_t read_hdr(private_der_decoder_t *this, chunk_t *data);
/**
* Read a sequence from data, parse its contents recursivly
*/
status_t read_sequence(private_der_decoder_t *this, chunk_t data)
{
status_t status;
asn1_rule_t *next_rule;
while(TRUE)
{
next_rule = this->rule + 1;
if (next_rule->type == ASN1_END)
{
this->rule++;
break;
}
status = read_hdr(this, &data);
if (status != SUCCESS)
{
return status;
}
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Sequence end");
return SUCCESS;
}
/**
* Read choice of data, parse if one of the choosable types arise
*/
status_t read_choice(private_der_decoder_t *this, chunk_t *data)
{
status_t status = PARSE_ERROR;
asn1_rule_t *next_rule;
bool found = FALSE;
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "Choice data", *data);
while(TRUE)
{
next_rule = this->rule + 1;
if (next_rule->type == ASN1_END)
{
this->rule++;
return status;
}
if (!found && *(data->ptr) == next_rule->type)
{
found = TRUE;
status = read_hdr(this, data);
}
else
{
this->rule++;
}
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Choice end");
return status;
}
/**
* Read a utc or generalized time
*/
status_t read_time(private_der_decoder_t *this, chunk_t data)
{
struct tm t;
time_t tz_offset;
u_char *eot = NULL;
const char* format;
time_t *result = (time_t*)((u_int8_t*)this->output + this->rule->data_offset);
/* TODO: Test it */
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "TIME", data);
if ((eot = memchr(data.ptr, 'Z', data.len)) != NULL)
{
/* Zulu time with a zero time zone offset */
tz_offset = 0;
}
else if ((eot = memchr(data.ptr, '+', data.len)) != NULL)
{
int tz_hour, tz_min;
sscanf(eot+1, "%2d%2d", &tz_hour, &tz_min);
/* positive time zone offset */
tz_offset = 3600*tz_hour + 60*tz_min;
}
else if ((eot = memchr(data.ptr, '-', data.len)) != NULL)
{
int tz_hour, tz_min;
sscanf(eot+1, "%2d%2d", &tz_hour, &tz_min);
/* negative time zone offset */
tz_offset = -3600*tz_hour - 60*tz_min;
}
else
{
/* error in time format */
return PARSE_ERROR;
}
if (this->rule->type == ASN1_UTCTIME)
{
format = "%2d%2d%2d%2d%2d";
}
else
{
format = "%4d%2d%2d%2d%2d";
}
sscanf(data.ptr, format, &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min);
/* is there a seconds field? */
if ((eot - data.ptr) == ((this->rule->type == ASN1_UTCTIME)?12:14))
{
sscanf(eot-2, "%2d", &t.tm_sec);
}
else
{
t.tm_sec = 0;
}
/* representation of year */
if (t.tm_year >= 1900)
{
t.tm_year -= 1900;
}
else if (t.tm_year >= 100)
{
return PARSE_ERROR;
}
else if (t.tm_year < 50)
{
t.tm_year += 100;
}
/* representation of month 0..11*/
t.tm_mon--;
/* set daylight saving time to off */
t.tm_isdst = 0;
/* compensate timezone */
*result = mktime(&t) - timezone - tz_offset;
return SUCCESS;
}
/**
* Read an integer as u_int or as mpz_t
*/
status_t read_int(private_der_decoder_t *this, chunk_t data)
{
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_INTEGER", data);
if (this->rule->flags & ASN1_MPZ)
{
mpz_t *mpz = (mpz_t*)((u_int8_t*)this->output + this->rule->data_offset);
mpz_import(*mpz, data.len, 1, 1, 1, 0, data.ptr);
}
else
{
u_int *integ = (u_int*)((u_int8_t*)this->output + this->rule->data_offset);
*integ = 0;
while (data.len-- > 0)
{
*integ = 256 * (*integ) + *data.ptr++;
}
}
return SUCCESS;
}
/**
* Read boolean value
*/
status_t read_bool(private_der_decoder_t *this, chunk_t data)
{
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_BOOLEAN", data);
bool *boolean = (u_int*)((u_int8_t*)this->output + this->rule->data_offset);
*boolean = *data.ptr;
return SUCCESS;
}
/**
* Read an OID
*/
status_t read_oid(private_der_decoder_t *this, chunk_t data)
{
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_OID", data);
/* TODO: OID parsing stuff */
return SUCCESS;
}
/**
* Read a bitstring
*/
status_t read_bitstring(private_der_decoder_t *this, chunk_t data)
{
/* TODO: cleanly determine amount of unused bits */
/* skip "unused-bits-in-following-byte"-byte */
data.ptr += 1;
data.len -= 1;
if (data.len < 1)
{
return FAILED;
}
chunk_t *chunk = (chunk_t*)((u_int8_t*)this->output + this->rule->data_offset);
*chunk = allocator_clone_chunk(data);
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_BITSTRING", data);
return SUCCESS;
}
/**
* Read any type which appears in a chunk
*/
status_t read_any(private_der_decoder_t *this, chunk_t data)
{
chunk_t *chunk = (chunk_t*)((u_int8_t*)this->output + this->rule->data_offset);
*chunk = allocator_clone_chunk(data);
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_ANY", data);
return SUCCESS;
}
/**
* Read the length field of a type
*/
u_int32_t read_length(chunk_t *data)
{
u_int8_t n;
size_t len;
if (data->len < 1)
{
return -1;
}
/* read first octet of length field */
n = *data->ptr;
data->ptr++; data->len--;
if ((n & 0x80) == 0)
{
/* single length octet */
return n;
}
/* composite length, determine number of length octets */
n &= 0x7f;
if (n > data->len)
{
/* length longer than available bytes */
return -1;
}
if (n > sizeof(len))
{
/* larger than size_t can hold */
return -1;
}
len = 0;
while (n-- > 0)
{
len = 256 * len + *data->ptr;
data->ptr++; data->len--;
}
return len;
}
/**
* Read the next field
*/
status_t read_hdr(private_der_decoder_t *this, chunk_t *data)
{
chunk_t inner;
/* TODO: Redo this that an average mid-european can understand it */
beginning:
/* advance to the next rule */
this->rule++;
this->logger->log(this->logger, CONTROL|LEVEL2, "reading rule %d %s",
this->rule - this->first_rule,
mapping_find(asn1_type_m, this->rule->type));
switch (this->rule->type)
{
case ASN1_END:
/* ignore, handled outside */
return SUCCESS;
case ASN1_CHOICE:
/* CHOICE has no type/length */
break;
default:
/* anything else has type/length */
if (data->len == 0)
{
goto beginning;
}
this->logger->log_chunk(this->logger, CONTROL|LEVEL3, "reading from:", *data);
/* read type, advance in data */
if (this->rule->type != ASN1_ANY && *(data->ptr) != this->rule->type)
{
if (this->rule->flags & ASN1_OPTIONAL)
{
goto beginning;
}
if (this->rule->flags & ASN1_DEFAULT)
{
goto beginning;
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Bad byte found: %x, %x expected",
*data->ptr, this->rule->type);
return PARSE_ERROR;
}
data->ptr++;
data->len--;
/* read length, advance in data */
inner.len = read_length(data);
if (inner.len == -1)
{
this->logger->log(this->logger, CONTROL|LEVEL2, "Error reading length");
return PARSE_ERROR;
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Length is %d", inner.len);
inner.ptr = data->ptr;
/* advance in data, at the size of the inner */
data->ptr += inner.len;
data->len -= inner.len;
}
/* process inner */
while (TRUE)
{
switch (this->rule->type)
{
case ASN1_INTEGER:
return read_int(this, inner);
case ASN1_BOOLEAN:
return read_bool(this, inner);
case ASN1_SEQUENCE:
case ASN1_SET:
return read_sequence(this, inner);
case ASN1_TAG_E_0:
case ASN1_TAG_E_1:
case ASN1_TAG_E_2:
case ASN1_TAG_E_3:
case ASN1_TAG_E_4:
case ASN1_TAG_E_5:
case ASN1_TAG_E_6:
case ASN1_TAG_E_7:
return read_hdr(this, &inner);
case ASN1_TAG_I_0:
case ASN1_TAG_I_1:
case ASN1_TAG_I_2:
case ASN1_TAG_I_3:
case ASN1_TAG_I_4:
case ASN1_TAG_I_5:
case ASN1_TAG_I_6:
case ASN1_TAG_I_7:
this->rule++;
continue;
case ASN1_OID:
return read_oid(this, inner);
case ASN1_CHOICE:
return read_choice(this, data);
case ASN1_NULL:
return SUCCESS;
case ASN1_ANY:
return read_any(this, inner);
case ASN1_UTCTIME:
return read_time(this, inner);
case ASN1_GENERALIZEDTIME:
return read_time(this, inner);
case ASN1_BITSTRING:
return read_bitstring(this, inner);
case ASN1_OCTETSTRING:
return read_any(this, inner);
default:
return NOT_SUPPORTED;
}
}
}
/**
* Implements der_decoder_t.decode
*/
status_t decode(private_der_decoder_t *this, chunk_t input, void *output)
{
this->rule = this->first_rule - 1;
this->output = output;
/* start parsing recursivly */
return read_hdr(this, &input);
}
/**
* Implementation of der_decoder.destroy.
*/
static void destroy(private_der_decoder_t *this)
{
allocator_free(this);
}
/*
* Described in header.
*/
der_decoder_t *der_decoder_create(asn1_rule_t *rules)
{
private_der_decoder_t *this = allocator_alloc_thing(private_der_decoder_t);
/* public functions */
this->public.decode = (status_t (*) (der_decoder_t*,chunk_t,void*))decode;
this->public.destroy = (void (*) (der_decoder_t*))destroy;
this->first_rule = rules;
this->logger = charon->logger_manager->get_logger(charon->logger_manager, DER_DECODER);
return &(this->public);
}
-79
View File
@@ -1,79 +0,0 @@
/**
* @file der_decoder.h
*
* @brief Interface of der_decoder_t.
*
*/
/*
* Copyright (C) 2006 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 DER_DECODER_H_
#define DER_DECODER_H_
#include <types.h>
#include <asn1/asn1.h>
typedef struct der_decoder_t der_decoder_t;
/**
* @brief Decode ASN1 DER encoded chunks.
*
* @b Constructors:
* - der_decoder_create()
*
* @todo A lot.
*
* @ingroup asn1
*/
struct der_decoder_t {
/**
* @brief Decode a chunk of bytes to a data structure
*
* @param der_decoder calling object
* @param input chunk of data to decode
* @param output data structure where decoded data is written
* @return
* - PARSE_ERROR
* - FAILED
* - NOT_SUPPORTED
* - or SUCCESS sometimes
*/
status_t (*decode) (der_decoder_t *this, chunk_t input, void *output);
/**
* @brief Destroys a der_decoder object.
*
* @param der_decoder calling object
*/
void (*destroy) (der_decoder_t *this);
};
/**
* @brief Create a der_decoder instance.
*
* The instance needs ASN1 rules to know how to decode
* data...
*
* @param rules set of ASN1 coding rules
* @return der_decoder_t object
*
* @ingroup ans1
*/
der_decoder_t * der_decoder_create(asn1_rule_t* rules);
#endif /* DER_DECODER_H_ */
-218
View File
@@ -1,218 +0,0 @@
/**
* @file der_encoder.c
*
* @brief Implementation of der_encoder_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 <gmp.h>
#include "der_encoder.h"
#include <utils/allocator.h>
#include <daemon.h>
typedef struct private_der_encoder_t private_der_encoder_t;
/**
* Private data of a der_encoder_t object.
*/
struct private_der_encoder_t {
/**
* Public interface for this signer.
*/
der_encoder_t public;
asn1_rule_t *rule;
asn1_rule_t *first_rule;
void *output;
logger_t *logger;
};
status_t read_hdr(private_der_encoder_t *this, chunk_t *data);
status_t read_sequence(private_der_encoder_t *this, chunk_t data)
{
while (this->rule->type != ASN1_END)
{
read_hdr(this, &data);
}
return SUCCESS;
}
status_t read_int(private_der_encoder_t *this, chunk_t data)
{
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_INTEGER", data);
u_int *integ = (u_int*)((u_int8_t*)this->output + this->rule->data_offset);
*integ = 0;
while (data.len-- > 0)
{
*integ = 256 * (*integ) + *data.ptr++;
}
return SUCCESS;
}
status_t read_mpz(private_der_encoder_t *this, chunk_t data)
{
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "ASN1_INTEGER as mpz", data);
mpz_t *mpz = (mpz_t*)((u_int8_t*)this->output + this->rule->data_offset);
mpz_import(*mpz, data.len, 1, 1, 1, 0, data.ptr);
return SUCCESS;
}
u_int32_t read_length(chunk_t *data)
{
u_int8_t n;
size_t len;
/* read first octet of length field */
n = *data->ptr++;
if ((n & 0x80) == 0)
{
/* single length octet */
return n;
}
/* composite length, determine number of length octets */
n &= 0x7f;
if (n > data->len)
{
/* length longer than available bytes */
return -1;
}
if (n > sizeof(len))
{
/* larger than size_t can hold */
return -1;
}
len = 0;
while (n-- > 0)
{
len = 256 * len + *data->ptr++;
}
return len;
}
status_t read_hdr(private_der_encoder_t *this, chunk_t *data)
{
chunk_t inner;
/* advance to the next rule */
this->rule++;
if (this->rule->type == ASN1_END)
{
return SUCCESS;
}
this->logger->log(this->logger, CONTROL|LEVEL2, "reading header of rule %s",
mapping_find(asn1_type_m, this->rule->type));
this->logger->log_chunk(this->logger, CONTROL|LEVEL2, "reading from:", *data);
/* read type, advance in data */
if (*(data->ptr) != this->rule->type)
{
this->logger->log(this->logger, CONTROL|LEVEL2, "Bad byte found (%x)", *data->ptr);
return PARSE_ERROR;
}
data->ptr++;
data->len--;
/* read length, advance in data */
inner.len = read_length(data);
if (inner.len == -1)
{
this->logger->log(this->logger, CONTROL|LEVEL2, "Error reading length");
return PARSE_ERROR;
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Length is %d",
inner.len);
inner.ptr = data->ptr;
/* advance in data */
data->ptr += inner.len;
data->len -= inner.len;
/* process inner */
switch (this->rule->type)
{
case ASN1_INTEGER:
if (this->rule->flags & ASN1_MPZ)
{
read_mpz(this, inner);
}
else
{
read_int(this, inner);
}
break;
case ASN1_SEQUENCE:
read_sequence(this, inner);
break;
default:
break;
}
return SUCCESS;
}
status_t decode(private_der_encoder_t *this, chunk_t input, void *output)
{
this->rule = this->first_rule - 1;
this->output = output;
return read_hdr(this, &input);
}
/**
* Implementation of der_encoder.destroy.
*/
static void destroy(private_der_encoder_t *this)
{
allocator_free(this);
}
/*
* Described in header.
*/
der_encoder_t *der_encoder_create(asn1_rule_t *rules)
{
private_der_encoder_t *this = allocator_alloc_thing(private_der_encoder_t);
/* public functions */
this->public.decode = (status_t (*) (der_encoder_t*,chunk_t,void*))decode;
this->public.destroy = (void (*) (der_encoder_t*))destroy;
this->first_rule = rules;
this->logger = charon->logger_manager->get_logger(charon->logger_manager, DER_DECODER);
return &(this->public);
}
-60
View File
@@ -1,60 +0,0 @@
/**
* @file der_encoder.h
*
* @brief Interface of der_encoder_t.
*
*/
/*
* Copyright (C) 2006 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 DER_ENCODER_H_
#define DER_ENCODER_H_
#include <types.h>
typedef struct der_encoder_t der_encoder_t;
/**
* @brief Decode der_encoded bytes to usable structures.
*
* @b Constructors:
* - der_encoder_create()
*
* @ingroup asn1
*/
struct der_encoder_t {
status_t encode(der_encoder_t *this, void *input, chunk_t output);
/**
* @brief Destroys a der_encoder object.
*
* @param der_encoder calling object
*/
void (*destroy) (der_encoder_t *this);
};
/**
* @brief Create a der_encoder instance.
*
* @return der_encoder_t object
*
* @ingroup ans1
*/
der_encoder_t * der_encoder_create(asn1_rule_t *rules);
#endif /* DER_ENCODER_H_ */
-867
View File
@@ -1,867 +0,0 @@
diff -Naur strongswan-2.6.3/Makefile.inc strongswan-2.6.3-charon/Makefile.inc
--- strongswan-2.6.3/Makefile.inc 2006-01-25 18:23:15.000000000 +0100
+++ strongswan-2.6.3-charon/Makefile.inc 2006-03-21 09:26:23.000000000 +0100
@@ -284,6 +284,9 @@
# include PKCS11-based smartcard support
USE_SMARTCARD?=false
+# support IKEv2 via charon
+USE_IKEV2?=true
+
# Default PKCS11 library
# Uncomment this line if using OpenSC <= 0.9.6
PKCS11_DEFAULT_LIB=\"/usr/lib/pkcs11/opensc-pkcs11.so\"
diff -Naur strongswan-2.6.3/programs/Makefile strongswan-2.6.3-charon/programs/Makefile
--- strongswan-2.6.3/programs/Makefile 2006-01-01 16:14:08.000000000 +0100
+++ strongswan-2.6.3-charon/programs/Makefile 2006-03-21 09:26:23.000000000 +0100
@@ -32,6 +32,10 @@
SUBDIRS+=showpolicy
endif
+ifeq ($(USE_IKEV2),true)
+SUBDIRS+=charon
+endif
+
def:
@echo "Please read doc/intro.html or INSTALL before running make"
@false
diff -Naur strongswan-2.6.3/programs/ipsec/ipsec.in strongswan-2.6.3-charon/programs/ipsec/ipsec.in
--- strongswan-2.6.3/programs/ipsec/ipsec.in 2006-03-09 21:09:33.000000000 +0100
+++ strongswan-2.6.3-charon/programs/ipsec/ipsec.in 2006-03-21 09:49:10.000000000 +0100
@@ -123,6 +123,10 @@
down)
shift
$IPSEC_EXECDIR/whack --name "$1" --terminate
+ if test -e $IPSEC_EXECDIR/stroke
+ then
+ $IPSEC_EXECDIR/stroke --name "$1" --terminate
+ fi
exit 0
;;
listalgs|listpubkeys|listcerts|listcacerts|\
@@ -134,11 +138,19 @@
op="$1"
shift
$IPSEC_EXECDIR/whack "$@" "--$op"
+ if test -e $IPSEC_EXECDIR/stroke
+ then
+ $IPSEC_EXECDIR/stroke "$@" "--$op"
+ fi
exit 0
;;
ready)
shift
$IPSEC_EXECDIR/whack --listen
+ if test -e $IPSEC_EXECDIR/stroke
+ then
+ $IPSEC_EXECDIR/stroke --listen
+ fi
exit 0
;;
reload)
@@ -180,8 +192,16 @@
if test $# -eq 0
then
$IPSEC_EXECDIR/whack "--$op"
+ if test -e $IPSEC_EXECDIR/stroke
+ then
+ $IPSEC_EXECDIR/stroke "--$op"
+ fi
else
$IPSEC_EXECDIR/whack --name "$1" "--$op"
+ if test -e $IPSEC_EXECDIR/stroke
+ then
+ $IPSEC_EXECDIR/stroke --name "$1" "--$op"
+ fi
fi
exit 0
;;
diff -Naur strongswan-2.6.3/programs/pluto/Makefile strongswan-2.6.3-charon/programs/pluto/Makefile
--- strongswan-2.6.3/programs/pluto/Makefile 2006-01-25 18:22:19.000000000 +0100
+++ strongswan-2.6.3-charon/programs/pluto/Makefile 2006-03-21 10:00:41.000000000 +0100
@@ -170,6 +170,11 @@
LIBSPLUTO+= -ldl
endif
+# enable IKEv2 support
+ifeq ($(USE_IKEV2),true)
+ DEFINES+= -DIKEV2
+endif
+
# This compile option activates the leak detective
ifeq ($(USE_LEAK_DETECTIVE),true)
DEFINES+= -DLEAK_DETECTIVE
diff -Naur strongswan-2.6.3/programs/pluto/demux.c strongswan-2.6.3-charon/programs/pluto/demux.c
--- strongswan-2.6.3/programs/pluto/demux.c 2005-02-18 22:08:59.000000000 +0100
+++ strongswan-2.6.3-charon/programs/pluto/demux.c 2006-03-21 09:26:24.000000000 +0100
@@ -1229,6 +1229,15 @@
if (md->packet_pbs.roof - md->packet_pbs.cur >= (ptrdiff_t)isakmp_hdr_desc.size)
{
struct isakmp_hdr *hdr = (struct isakmp_hdr *)md->packet_pbs.cur;
+#ifdef IKEV2
+ if ((hdr->isa_version >> ISA_MAJ_SHIFT) == 0x2 &&
+ (hdr->isa_version & ISA_MIN_MASK) == 0x0)
+ {
+ /* IKEv2 is handled from charon, ignore */
+ return;
+ }
+ else
+#endif /* IKEV2 */
if ((hdr->isa_version >> ISA_MAJ_SHIFT) != ISAKMP_MAJOR_VERSION)
{
SEND_NOTIFICATION(INVALID_MAJOR_VERSION);
diff -Naur strongswan-2.6.3/programs/starter/Makefile strongswan-2.6.3-charon/programs/starter/Makefile
--- strongswan-2.6.3/programs/starter/Makefile 2006-02-17 20:34:02.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/Makefile 2006-03-21 09:26:24.000000000 +0100
@@ -34,6 +34,11 @@
DEFINES+= -DLEAK_DETECTIVE
endif
+# Enable charon support
+ifeq ($(USE_IKEV2),true)
+ DEFINES+= -DIKEV2
+endif
+
INCLUDES=-I${FREESWANDIR}/linux/include
CFLAGS=$(DEFINES) $(INCLUDES) -Wall
CFLAGS+=-DIPSEC_EXECDIR=\"${FINALLIBEXECDIR}\" -DIPSEC_CONFDDIR=\"${FINALCONFDDIR}\"
@@ -46,6 +51,11 @@
starterwhack.o klips.o netkey.o interfaces.o exec.o cmp.o confread.o \
loglite.o ${PLUTO_OBJS}
+# Build charon-only objs
+ifeq ($(USE_IKEV2),true)
+ OBJS+= invokecharon.o starterstroke.o
+endif
+
DISTSRC=$(OBJS:.o=.c)
DISTSRC+=cmp.h confread.h confwrite.h exec.h files.h interfaces.h klips.h netkey.h
DISTSRC+=parser.h args.h invokepluto.h starterwhack.h keywords.h keywords.txt
diff -Naur strongswan-2.6.3/programs/starter/args.c strongswan-2.6.3-charon/programs/starter/args.c
--- strongswan-2.6.3/programs/starter/args.c 2006-03-10 21:37:10.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/args.c 2006-03-21 09:26:24.000000000 +0100
@@ -86,6 +86,10 @@
static const char *LST_keyexchange[] = {
"ike",
+#ifdef IKEV2
+ "ikev1",
+ "ikev2",
+#endif /* IKEV2 */
NULL
};
diff -Naur strongswan-2.6.3/programs/starter/files.h strongswan-2.6.3-charon/programs/starter/files.h
--- strongswan-2.6.3/programs/starter/files.h 2006-02-04 19:52:58.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/files.h 2006-03-21 09:26:24.000000000 +0100
@@ -37,8 +37,15 @@
#define SECRETS_FILE IPSEC_CONFDIR"/ipsec.secrets"
#define PLUTO_CMD IPSEC_EXECDIR"/pluto"
-#define CTL_FILE DEFAULT_CTLBASE CTL_SUFFIX
-#define PID_FILE DEFAULT_CTLBASE PID_SUFFIX
+#define PLUTO_CTL_FILE DEFAULT_CTLBASE CTL_SUFFIX
+#define PLUTO_PID_FILE DEFAULT_CTLBASE PID_SUFFIX
+
+#ifdef IKEV2
+#define CHARON_CMD IPSEC_EXECDIR"/charon"
+#define CHARON_BASE "/var/run/charon"
+#define CHARON_CTL_FILE CHARON_BASE CTL_SUFFIX
+#define CHARON_PID_FILE CHARON_BASE PID_SUFFIX
+#endif /* IKEV2 */
#define DYNIP_DIR "/var/run/dynip"
#define INFO_FILE "/var/run/ipsec.info"
diff -Naur strongswan-2.6.3/programs/starter/invokecharon.c strongswan-2.6.3-charon/programs/starter/invokecharon.c
--- strongswan-2.6.3/programs/starter/invokecharon.c 1970-01-01 01:00:00.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/invokecharon.c 2006-03-21 09:26:24.000000000 +0100
@@ -0,0 +1,168 @@
+/* strongSwan charon launcher
+ * Copyright (C) 2001-2002 Mathieu Lafon - Arkoon Network Security
+ * Copyright (C) 2006 Martin Willi - Hochschule fuer Technik Rapperswil
+ *
+ * Ported from invokepluto.c to fit charons needs.
+ *
+ * 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.
+ *
+ * RCSID $Id: invokecharon.c $
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <freeswan.h>
+
+#include "../pluto/constants.h"
+#include "../pluto/defs.h"
+#include "../pluto/log.h"
+
+#include "confread.h"
+#include "invokecharon.h"
+#include "files.h"
+
+static int _charon_pid = 0;
+static int _stop_requested;
+
+pid_t
+starter_charon_pid(void)
+{
+ return _charon_pid;
+}
+
+void
+starter_charon_sigchild(pid_t pid)
+{
+ if (pid == _charon_pid)
+ {
+ _charon_pid = 0;
+ if (!_stop_requested)
+ {
+ plog("charon has died -- restart scheduled (%dsec)"
+ , CHARON_RESTART_DELAY);
+ alarm(CHARON_RESTART_DELAY); // restart in 5 sec
+ }
+ unlink(CHARON_PID_FILE);
+ }
+}
+
+int
+starter_stop_charon (void)
+{
+ pid_t pid;
+ int i;
+
+ pid = _charon_pid;
+ if (pid)
+ {
+ _stop_requested = 1;
+
+ /* be more and more aggressive */
+ for (i = 0; i < 20 && (pid = _charon_pid) != 0; i++)
+ {
+ if (i == 0)
+ kill(pid, SIGINT);
+ else if (i < 10)
+ kill(pid, SIGTERM);
+ else
+ kill(pid, SIGKILL);
+ usleep(20000);
+ }
+ if (_charon_pid == 0)
+ return 0;
+ plog("starter_stop_charon(): can't stop charon !!!");
+ return -1;
+ }
+ else
+ {
+ plog("stater_stop_charon(): charon is not started...");
+ }
+ return -1;
+}
+
+
+int
+starter_start_charon (starter_config_t *cfg, bool debug)
+{
+ int pid, i;
+ struct stat stb;
+ char *arg[] = {
+ CHARON_CMD, NULL
+ };
+
+ if (_charon_pid)
+ {
+ plog("starter_start_charon(): charon already started...");
+ return -1;
+ }
+ else
+ {
+ unlink(CHARON_CTL_FILE);
+ _stop_requested = 0;
+
+ pid = fork();
+ switch (pid)
+ {
+ case -1:
+ plog("can't fork(): %s", strerror(errno));
+ return -1;
+ case 0:
+ /* child */
+ setsid();
+ sigprocmask(SIG_SETMASK, 0, NULL);
+ execv(arg[0], arg);
+ plog("can't execv(%s,...): %s", arg[0], strerror(errno));
+ exit(1);
+ default:
+ /* father */
+ _charon_pid = pid;
+ for (i = 0; i < 50 && _charon_pid; i++)
+ {
+ /* wait for charon */
+ usleep(20000);
+ if (stat(CHARON_PID_FILE, &stb) == 0)
+ {
+ DBG(DBG_CONTROL,
+ DBG_log("charon (%d) started", _charon_pid)
+ )
+ return 0;
+ }
+ }
+ if (_charon_pid)
+ {
+ /* If charon is started but with no ctl file, stop it */
+ plog("charon too long to start... - kill kill");
+ for (i = 0; i < 20 && (pid = _charon_pid) != 0; i++)
+ {
+ if (i == 0)
+ kill(pid, SIGINT);
+ else if (i < 10)
+ kill(pid, SIGTERM);
+ else
+ kill(pid, SIGKILL);
+ usleep(20000);
+ }
+ }
+ else
+ {
+ plog("charon refused to be started");
+ }
+ return -1;
+ }
+ }
+ return -1;
+}
diff -Naur strongswan-2.6.3/programs/starter/invokecharon.h strongswan-2.6.3-charon/programs/starter/invokecharon.h
--- strongswan-2.6.3/programs/starter/invokecharon.h 1970-01-01 01:00:00.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/invokecharon.h 2006-03-21 09:26:24.000000000 +0100
@@ -0,0 +1,31 @@
+/* strongSwan charon launcher
+ * Copyright (C) 2001-2002 Mathieu Lafon - Arkoon Network Security
+ * Copyright (C) 2006 Martin Willi - Hochschule fuer Technik Rapperswil
+ *
+ * Ported from invokepluto.h to fit charons needs.
+ *
+ * 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.
+ *
+ * RCSID $Id: invokecharon.h $
+ */
+
+#ifndef _STARTER_CHARON_H_
+#define _STARTER_CHARON_H_
+
+#define CHARON_RESTART_DELAY 5
+
+extern void starter_charon_sigchild (pid_t pid);
+extern pid_t starter_charon_pid (void);
+extern int starter_stop_charon (void);
+extern int starter_start_charon(struct starter_config *cfg, bool debug);
+
+#endif /* _STARTER_CHARON_H_ */
+
diff -Naur strongswan-2.6.3/programs/starter/invokepluto.c strongswan-2.6.3-charon/programs/starter/invokepluto.c
--- strongswan-2.6.3/programs/starter/invokepluto.c 2006-02-17 22:41:50.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/invokepluto.c 2006-03-21 09:26:24.000000000 +0100
@@ -54,7 +54,7 @@
, PLUTO_RESTART_DELAY);
alarm(PLUTO_RESTART_DELAY); // restart in 5 sec
}
- unlink(PID_FILE);
+ unlink(PLUTO_PID_FILE);
}
}
@@ -203,7 +203,7 @@
}
else
{
- unlink(CTL_FILE);
+ unlink(PLUTO_CTL_FILE);
_stop_requested = 0;
if (cfg->setup.prepluto)
@@ -252,7 +252,7 @@
{
/* wait for pluto */
usleep(20000);
- if (stat(CTL_FILE, &stb) == 0)
+ if (stat(PLUTO_CTL_FILE, &stb) == 0)
{
DBG(DBG_CONTROL,
DBG_log("pluto (%d) started", _pluto_pid)
diff -Naur strongswan-2.6.3/programs/starter/starter.c strongswan-2.6.3-charon/programs/starter/starter.c
--- strongswan-2.6.3/programs/starter/starter.c 2006-02-15 19:37:46.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/starter.c 2006-03-21 09:26:24.000000000 +0100
@@ -37,6 +37,7 @@
#include "files.h"
#include "starterwhack.h"
#include "invokepluto.h"
+#include "invokecharon.h"
#include "klips.h"
#include "netkey.h"
#include "cmp.h"
@@ -47,6 +48,9 @@
#define FLAG_ACTION_RELOAD 0x04
#define FLAG_ACTION_QUIT 0x08
#define FLAG_ACTION_LISTEN 0x10
+#ifdef IKEV2
+#define FLAG_ACTION_START_CHARON 0x20
+#endif /* IKEV2 */
static unsigned int _action_ = 0;
@@ -65,6 +69,10 @@
{
if (pid == starter_pluto_pid())
name = " (Pluto)";
+#ifdef IKEV2
+ if (pid == starter_charon_pid())
+ name = " (Charon)";
+#endif /* IKEV2 */
if (WIFSIGNALED(status))
DBG(DBG_CONTROL,
DBG_log("child %d%s has been killed by sig %d\n",
@@ -87,6 +95,10 @@
if (pid == starter_pluto_pid())
starter_pluto_sigchild(pid);
+#ifdef IKEV2
+ if (pid == starter_charon_pid())
+ starter_charon_sigchild(pid);
+#endif /* IKEV2 */
}
}
break;
@@ -97,6 +109,9 @@
case SIGALRM:
_action_ |= FLAG_ACTION_START_PLUTO;
+#ifdef IKEV2
+ _action_ |= FLAG_ACTION_START_CHARON;
+#endif /* IKEV2 */
break;
case SIGHUP:
@@ -193,6 +208,9 @@
signal(SIGQUIT, fsig);
signal(SIGALRM, fsig);
signal(SIGUSR1, fsig);
+
+
+ plog("Starting strongSwan IPsec %s [starter]...", ipsec_version_code());
/* verify that we can start */
if (getuid() != 0)
@@ -201,12 +219,24 @@
exit(1);
}
- if (stat(PID_FILE, &stb) == 0)
+ if (stat(PLUTO_PID_FILE, &stb) == 0)
{
- plog("pluto is already running (%s exists) -- aborting", PID_FILE);
- exit(1);
+ plog("pluto is already running (%s exists) -- skipping pluto start", PLUTO_PID_FILE);
}
-
+ else
+ {
+ _action_ |= FLAG_ACTION_START_PLUTO;
+ }
+#ifdef IKEV2
+ if (stat(CHARON_PID_FILE, &stb) == 0)
+ {
+ plog("charon is already running (%s exists) -- skipping charon start", CHARON_PID_FILE);
+ }
+ else
+ {
+ _action_ |= FLAG_ACTION_START_CHARON;
+ }
+#endif /* IKEV2 */
if (stat(DEV_RANDOM, &stb) != 0)
{
plog("unable to start strongSwan IPsec -- no %s!", DEV_RANDOM);
@@ -247,7 +277,11 @@
last_reload = time(NULL);
- plog("Starting strongSwan IPsec %s [starter]...", ipsec_version_code());
+ if (stat(MY_PID_FILE, &stb) == 0)
+ {
+ plog("starter is already running (%s exists) -- no fork done", MY_PID_FILE);
+ exit(0);
+ }
/* fork if we're not debugging stuff */
if (!no_fork)
@@ -296,17 +330,19 @@
, &cfg->defaultroute);
}
- _action_ = FLAG_ACTION_START_PLUTO;
-
for (;;)
{
/*
- * Stop pluto (if started) and exit
- */
+ * Stop pluto/charon (if started) and exit
+ */
if (_action_ & FLAG_ACTION_QUIT)
{
if (starter_pluto_pid())
starter_stop_pluto();
+#ifdef IKEV2
+ if (starter_charon_pid())
+ starter_stop_charon();
+#endif IKEV2
if (has_netkey)
starter_netkey_cleanup();
else
@@ -337,6 +373,9 @@
if (conn->state == STATE_ADDED)
{
starter_whack_del_conn(conn);
+#ifdef IKEV2
+ starter_stroke_del_conn(conn);
+#endif /* IKEV2 */
conn->state = STATE_TO_ADD;
}
}
@@ -427,6 +466,9 @@
{
if (conn->state == STATE_ADDED)
starter_whack_del_conn(conn);
+#ifdef IKEV2
+ starter_stroke_del_conn(conn);
+#endif /* IKEV2 */
}
/* Look for new ca sections that are already loaded */
@@ -502,6 +544,27 @@
conn->state = STATE_TO_ADD;
}
}
+
+#ifdef IKEV2
+ /*
+ * Start charon
+ */
+ if (_action_ & FLAG_ACTION_START_CHARON)
+ {
+ if (starter_charon_pid() == 0)
+ {
+ DBG(DBG_CONTROL,
+ DBG_log("Attempting to start charon...")
+ )
+ if (starter_start_charon(cfg, no_fork) != 0)
+ {
+ /* schedule next try */
+ alarm(PLUTO_RESTART_DELAY);
+ }
+ }
+ _action_ &= ~FLAG_ACTION_START_CHARON;
+ }
+#endif /* IKEV2 */
/*
* Tell pluto to reread its interfaces
@@ -536,11 +599,36 @@
conn->id = id++;
}
starter_whack_add_conn(conn);
+#ifdef IKEV2
+ starter_stroke_add_conn(conn);
+#endif /* IKEV2 */
conn->state = STATE_ADDED;
if (conn->startup == STARTUP_START)
- starter_whack_initiate_conn(conn);
+ {
+#ifdef IKEV2
+ if (conn->keyexchange == 2)
+ {
+ starter_stroke_initiate_conn(conn);
+ }
+ else
+#endif /* IKEV2 */
+ {
+ starter_whack_initiate_conn(conn);
+ }
+ }
else if (conn->startup == STARTUP_ROUTE)
- starter_whack_route_conn(conn);
+ {
+#ifdef IKEV2
+ if (conn->keyexchange == 2)
+ {
+ starter_stroke_route_conn(conn);
+ }
+ else
+#endif /* IKEV2 */
+ {
+ starter_whack_route_conn(conn);
+ }
+ }
}
}
}
diff -Naur strongswan-2.6.3/programs/starter/starterstroke.c strongswan-2.6.3-charon/programs/starter/starterstroke.c
--- strongswan-2.6.3/programs/starter/starterstroke.c 1970-01-01 01:00:00.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/starterstroke.c 2006-03-21 09:26:24.000000000 +0100
@@ -0,0 +1,193 @@
+/* Stroke for charon is the counterpart to whack from pluto
+ * Copyright (C) 2006 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.
+ *
+ * RCSID $Id: starterstroke.c $
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <linux/stddef.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <freeswan.h>
+
+#include "../pluto/constants.h"
+#include "../pluto/defs.h"
+#include "../pluto/log.h"
+
+#include "starterstroke.h"
+#include "confread.h"
+#include "files.h"
+
+typedef struct stroke_msg_t stroke_msg_t;
+
+struct stroke_msg_t {
+ /* length of this message with all strings */
+ u_int16_t length;
+ /* type of the message */
+ enum {
+ /* initiate a connection */
+ STR_INITIATE,
+ /* install SPD entries for a connection */
+ STR_INSTALL,
+ /* add a connection */
+ STR_ADD_CONN,
+ /* delete a connection */
+ STR_DEL_CONN,
+ /* more to come */
+ } type;
+ union {
+ /* data for STR_INITIATE, STR_INSTALL */
+ struct {
+ char *name;
+ } initiate, install;
+ /* data for STR_ADD_CONN */
+ struct {
+ char *name;
+ struct {
+ char *id;
+ char *address;
+ char *subnet;
+ u_int8_t subnet_mask;
+ } me, other;
+ } add_conn;
+ };
+ u_int8_t buffer[];
+};
+
+static char* push_string(stroke_msg_t **strm, char *string)
+{
+ stroke_msg_t *stroke_msg;
+ size_t string_length;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+ stroke_msg = *strm;
+ string_length = strlen(string) + 1;
+ stroke_msg->length += string_length;
+
+ stroke_msg = realloc(stroke_msg, stroke_msg->length);
+ strcpy((char*)stroke_msg + stroke_msg->length - string_length, string);
+
+ *strm = stroke_msg;
+ return (char*)(u_int)stroke_msg->length - string_length;
+}
+
+static int
+send_stroke_msg (stroke_msg_t *msg)
+{
+ struct sockaddr_un ctl_addr = { AF_UNIX, CHARON_CTL_FILE };
+ int sock;
+
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0)
+ {
+ plog("socket() failed: %s", strerror(errno));
+ return -1;
+ }
+ if (connect(sock, (struct sockaddr *)&ctl_addr,
+ offsetof(struct sockaddr_un, sun_path) + strlen(ctl_addr.sun_path)) < 0)
+ {
+ plog("connect(charon_ctl) failed: %s", strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+ /* send message */
+ if (write(sock, msg, msg->length) != msg->length)
+ {
+ plog("write(charon_ctl) failed: %s", strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+ close(sock);
+ return 0;
+}
+
+static char *
+connection_name(starter_conn_t *conn)
+{
+ /* if connection name is '%auto', create a new name like conn_xxxxx */
+ static char buf[32];
+
+ if (streq(conn->name, "%auto"))
+ {
+ sprintf(buf, "conn_%ld", conn->id);
+ return buf;
+ }
+ return conn->name;
+}
+
+
+int starter_stroke_add_conn(starter_conn_t *conn)
+{
+ stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
+ int res;
+
+ msg->length = sizeof(stroke_msg_t);
+ msg->type = STR_ADD_CONN;
+
+ msg->add_conn.name = push_string(&msg, connection_name(conn));
+
+ msg->add_conn.me.id = push_string(&msg, conn->left.id);
+ msg->add_conn.me.address = push_string(&msg, inet_ntoa(conn->left.addr.u.v4.sin_addr));
+ msg->add_conn.me.subnet = push_string(&msg, inet_ntoa(conn->left.subnet.addr.u.v4.sin_addr));
+ msg->add_conn.me.subnet_mask = conn->left.subnet.maskbits;
+
+ msg->add_conn.other.id = push_string(&msg, conn->right.id);
+ msg->add_conn.other.address = push_string(&msg, inet_ntoa(conn->right.addr.u.v4.sin_addr));
+ msg->add_conn.other.subnet = push_string(&msg, inet_ntoa(conn->right.subnet.addr.u.v4.sin_addr));
+ msg->add_conn.other.subnet_mask = conn->right.subnet.maskbits;
+
+ res = send_stroke_msg(msg);
+ free(msg);
+ return res;
+}
+
+int starter_stroke_del_conn(starter_conn_t *conn)
+{
+ return 0;
+}
+int starter_stroke_route_conn(starter_conn_t *conn)
+{
+ stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
+ int res;
+
+ msg->length = sizeof(stroke_msg_t);
+ msg->type = STR_INSTALL;
+ msg->install.name = push_string(&msg, connection_name(conn));
+ res = send_stroke_msg(msg);
+ free(msg);
+ return res;
+}
+
+int starter_stroke_initiate_conn(starter_conn_t *conn)
+{
+ stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
+ int res;
+
+ msg->length = sizeof(stroke_msg_t);
+ msg->type = STR_INITIATE;
+ msg->initiate.name = push_string(&msg, connection_name(conn));
+ res = send_stroke_msg(msg);
+ free(msg);
+ return res;
+}
diff -Naur strongswan-2.6.3/programs/starter/starterstroke.h strongswan-2.6.3-charon/programs/starter/starterstroke.h
--- strongswan-2.6.3/programs/starter/starterstroke.h 1970-01-01 01:00:00.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/starterstroke.h 2006-03-21 09:26:24.000000000 +0100
@@ -0,0 +1,27 @@
+/* Stroke for charon is the counterpart to whack from pluto
+ * Copyright (C) 2006 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.
+ *
+ * RCSID $Id: starterstroke.h $
+ */
+
+#ifndef _STARTER_STROKE_H_
+#define _STARTER_STROKE_H_
+
+#include "confread.h"
+
+extern int starter_stroke_add_conn(starter_conn_t *conn);
+extern int starter_stroke_del_conn(starter_conn_t *conn);
+extern int starter_stroke_route_conn(starter_conn_t *conn);
+extern int starter_stroke_initiate_conn(starter_conn_t *conn);
+
+#endif /* _STARTER_STROKE_H_ */
diff -Naur strongswan-2.6.3/programs/starter/starterwhack.c strongswan-2.6.3-charon/programs/starter/starterwhack.c
--- strongswan-2.6.3/programs/starter/starterwhack.c 2006-02-08 21:56:07.000000000 +0100
+++ strongswan-2.6.3-charon/programs/starter/starterwhack.c 2006-03-21 09:26:24.000000000 +0100
@@ -54,7 +54,7 @@
static int
send_whack_msg (whack_message_t *msg)
{
- struct sockaddr_un ctl_addr = { AF_UNIX, CTL_FILE };
+ struct sockaddr_un ctl_addr = { AF_UNIX, PLUTO_CTL_FILE };
int sock;
ssize_t len;
char *str_next, *str_roof;
+6 -6
View File
@@ -12,26 +12,26 @@
# for more details.
#
CONFIG_DIR= $(MAIN_DIR)config/
CONFIG_DIR= $(CHARON_DIR)config/
OBJS+= $(BUILD_DIR)connection.o
CHARON_OBJS+= $(BUILD_DIR)connection.o
$(BUILD_DIR)connection.o : $(CONFIG_DIR)connection.c $(CONFIG_DIR)connection.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)policy.o
CHARON_OBJS+= $(BUILD_DIR)policy.o
$(BUILD_DIR)policy.o : $(CONFIG_DIR)policy.c $(CONFIG_DIR)policy.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)traffic_selector.o
CHARON_OBJS+= $(BUILD_DIR)traffic_selector.o
$(BUILD_DIR)traffic_selector.o : $(CONFIG_DIR)traffic_selector.c $(CONFIG_DIR)traffic_selector.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)proposal.o
CHARON_OBJS+= $(BUILD_DIR)proposal.o
$(BUILD_DIR)proposal.o : $(CONFIG_DIR)proposal.c $(CONFIG_DIR)proposal.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)configuration.o
CHARON_OBJS+= $(BUILD_DIR)configuration.o
$(BUILD_DIR)configuration.o : $(CONFIG_DIR)configuration.c $(CONFIG_DIR)configuration.h
$(CC) $(CFLAGS) -c -o $@ $<
+2 -2
View File
@@ -24,11 +24,11 @@
#define CONNECTION_H_
#include <types.h>
#include <network/host.h>
#include <utils/host.h>
#include <utils/linked_list.h>
#include <utils/identification.h>
#include <config/proposal.h>
#include <transforms/diffie_hellman.h>
#include <crypto/diffie_hellman.h>
typedef enum auth_method_t auth_method_t;
+2 -2
View File
@@ -24,8 +24,8 @@
#define CREDENTIAL_STORE_H_
#include <types.h>
#include <transforms/rsa/rsa_private_key.h>
#include <transforms/rsa/rsa_public_key.h>
#include <crypto/rsa/rsa_private_key.h>
#include <crypto/rsa/rsa_public_key.h>
typedef struct credential_store_t credential_store_t;
+4 -4
View File
@@ -26,10 +26,10 @@
#include <types.h>
#include <utils/identification.h>
#include <utils/linked_list.h>
#include <network/host.h>
#include <transforms/crypters/crypter.h>
#include <transforms/signers/signer.h>
#include <transforms/diffie_hellman.h>
#include <utils/host.h>
#include <crypto/crypters/crypter.h>
#include <crypto/signers/signer.h>
#include <crypto/diffie_hellman.h>
#include <config/traffic_selector.h>
+1 -1
View File
@@ -24,7 +24,7 @@
#define TRAFFIC_SELECTOR_H_
#include <types.h>
#include <network/host.h>
#include <utils/host.h>
typedef enum ts_type_t ts_type_t;
+55
View File
@@ -40,6 +40,61 @@
#include <config/policy_store.h>
#include <config/credential_store.h>
/**
* @mainpage
*
* @section Threading Architecture
*
* All IKEv2 stuff is handled in charon. It uses a newer and more flexible
* architecture than pluto. Charon uses a thread-pool, which allows parallel
* execution SA-management. Beside the thread-pool, there are some special purpose
* threads which do their job for the common health of the daemon.
@verbatim
+------+
| E Q |
| v u |---+ +------+ +------+
| e e | | | | | IKE- |
| n u | +-----------+ | |--| SA |
| t e | | | | I M | +------+
+------------+ | - | | Scheduler | | K a |
| receiver | +------+ | | | E n | +------+
+----+-------+ +-----------+ | - a | | IKE- |
| | +------+ | | S g |--| SA |
+-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
-| socket | | o u | | | | - r |
+-------+--+ | b e | | Thread- | | |
| | - u | | Pool | | |
+----+-------+ | e |------| |---| |
| sender | +------+ +------------+ +------+
+----+-------+
| +------+
| | S Q |
| | e u |
| | n e |
+------------| d u |
| - e |
+--+---+
@endverbatim
* The thread-pool is the heart of the architecture. It processes jobs from a
* (fully synchronized) job-queue. Mostly, a job is associated with a specific
* IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
* This makes it unnecesary to use further synchronisation methods once a IKE SA
* is checked out. The (rather complex) synchronization of IKE SAs is completely
* done in the IKE SA manager.
* The sceduler is responsible for event firing. It waits until a event in the
* (fully synchronized) event-queue is ready for processing and pushes the event
* down to the job-queue. A thread form the pool will pick it up as quick as
* possible. Every thread can queue events or jobs. Furter, an event can place a
* packet in the send-queue. The sender thread waits for those packets and sends
* them over the wire, via the socket. The receiver does exactly the opposite of
* the sender. It waits on the socket, reads in packets an places them on the
* job-queue for further processing by a thread from the pool.
* There are even more threads, not drawn in the upper scheme. The stroke thread
* is responsible for reading and processessing commands from another process. The
* kernel interface thread handles communication from and to the kernel via a
* netlink socket. It waits for kernel events and processes them appropriately.
*/
/**
* Name of the daemon.
*/
-40
View File
@@ -1,40 +0,0 @@
/**
* @file definitions.c
*
* @brief General purpose definitions and macros.
*
*/
/*
* 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 "definitions.h"
/*
* Described in header.
*/
char *mapping_find(mapping_t * maps, int value)
{
int i = 0;
while (maps[i].value != MAPPING_END)
{
if (maps[i].value == value)
{
return maps[i].string;
}
i++;
}
return "INVALID MAPPING";
}
-292
View File
@@ -1,292 +0,0 @@
/**
* @file definitions.h
*
* @brief General purpose definitions and macros.
*
*/
/*
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
* Copyright (C) 1998, 1999 D. Hugh Redelmeier. (Endian stuff)
*
* 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 DEFINITIONS_H_
#define DEFINITIONS_H_
/* stolen from strongswan */
#if linux
# if defined(i386) && !defined(__i386__)
# define __i386__ 1
# define MYHACKFORTHIS 1
# endif
# include <endian.h>
# ifdef MYHACKFORTHIS
# undef __i386__
# undef MYHACKFORTHIS
# endif
#elif !(defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER))
/* we don't know how to do this, so we require the macros to be defined
* with compiler flags:
* -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
* or -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN
* Thse match the GNU definitions
*/
# include <sys/endian.h>
#endif
#ifndef BIG_ENDIAN
#error "BIG_ENDIAN must be defined"
#endif
#ifndef LITTLE_ENDIAN
#error "LITTLE_ENDIAN must be defined"
#endif
#ifndef BYTE_ORDER
#error "BYTE_ORDER must be defined"
#endif
/**
* @mainpage
*
* @section Threading Architecture
*
* All IKEv2 stuff is handled in charon. It uses a newer and more flexible
* architecture than pluto. Charon uses a thread-pool, which allows parallel
* execution SA-management. Beside the thread-pool, there are some special purpose
* threads which do their job for the common health of the daemon.
@verbatim
+------+
| E Q |
| v u |---+ +------+ +------+
| e e | | | | | IKE- |
| n u | +-----------+ | |--| SA |
| t e | | | | I M | +------+
+------------+ | - | | Scheduler | | K a |
| receiver | +------+ | | | E n | +------+
+----+-------+ +-----------+ | - a | | IKE- |
| | +------+ | | S g |--| SA |
+-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
-| socket | | o u | | | | - r |
+-------+--+ | b e | | Thread- | | |
| | - u | | Pool | | |
+----+-------+ | e |------| |---| |
| sender | +------+ +------------+ +------+
+----+-------+
| +------+
| | S Q |
| | e u |
| | n e |
+------------| d u |
| - e |
+--+---+
@endverbatim
* The thread-pool is the heart of the architecture. It processes jobs from a
* (fully synchronized) job-queue. Mostly, a job is associated with a specific
* IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
* This makes it unnecesary to use further synchronisation methods once a IKE SA
* is checked out. The (rather complex) synchronization of IKE SAs is completely
* done in the IKE SA manager.
* The sceduler is responsible for event firing. It waits until a event in the
* (fully synchronized) event-queue is ready for processing and pushes the event
* down to the job-queue. A thread form the pool will pick it up as quick as
* possible. Every thread can queue events or jobs. Furter, an event can place a
* packet in the send-queue. The sender thread waits for those packets and sends
* them over the wire, via the socket. The receiver does exactly the opposite of
* the sender. It waits on the socket, reads in packets an places them on the
* job-queue for further processing by a thread from the pool.
* There are even more threads, not drawn in the upper scheme. The stroke thread
* is responsible for reading and processessing commands from another process. The
* kernel interface thread handles communication from and to the kernel via a
* netlink socket. It waits for kernel events and processes them appropriately.
*/
/**
* @defgroup config config
*
* Classes implementing configuration related things.
*/
/**
* @defgroup encoding encoding
*
* Classes used to encode and decode IKEv2 messages.
*/
/**
* @defgroup network network
*
* Classes for network relevant stuff.
*/
/**
* @defgroup payloads payloads
*
* Classes representing specific IKEv2 payloads.
*
* @ingroup encoding
*/
/**
* @defgroup sa sa
*
* Security association and helper classes.
*/
/**
* @defgroup states states
*
* Varius states in which an IKE SA can be.
*
* @ingroup sa
*/
/**
* @defgroup queues queues
*
* Different kind of queues.
*/
/**
* @defgroup jobs jobs
*
* Jobs used in job queue and event queue.
*
* @ingroup queues
*/
/**
* @defgroup testcases testcases
*
* Testcases used to test the different classes in seperate module tests.
*/
/**
* @defgroup transforms transforms
*
* Transform algorithms of different kind.
*/
/**
* @defgroup rsa rsa
*
* RSA public key algorithm.
*
* @ingroup transforms
*/
/**
* @defgroup prfs prfs
*
* Pseudo random functions.
*
* @ingroup transforms
*/
/**
* @defgroup signers signers
*
* Symmetric signing algorithms, used to ensure message integrity.
*
* @ingroup transforms
*/
/**
* @defgroup crypters crypters
*
* Symmetric encryption algorithms, used to encrypt and decrypt.
*
* @ingroup transforms
*/
/**
* @defgroup hashers hashers
*
* Hashing algorithms.
*
* @ingroup transforms
*/
/**
* @defgroup asn1 asn1
*
* ASN1 structure definition, en-/decoder of for DER
*
* @todo Implement a der_encoder_t class.
*/
/**
* @defgroup utils utils
*
* Generic helper classes.
*/
/**
* @defgroup threads threads
*
* Threaded classes, which will do their job alone.
*/
/**
* Macro gives back larger of two values.
*/
#define max(x,y) (x > y ? x : y)
/**
* Macro gives back smaller of two values.
*/
#define min(x,y) (x < y ? x : y)
/**
* Debug macro to follow control flow
*/
#define POS printf("%s, line %d\n", __FILE__, __LINE__)
/**
* Papping entry which defines the end of a mapping_t array.
*/
#define MAPPING_END (-1)
typedef struct mapping_t mapping_t;
/**
* @brief Mapping entry, where enum-to-string mappings are stored.
*/
struct mapping_t
{
/**
* Enumeration value.
*/
int value;
/**
* Mapped string.
*/
char *string;
};
/**
* @brief Find a mapping_string in the mapping[].
*
* @param mappings mappings array
* @param value enum-value to get the string from
*
*/
char *mapping_find(mapping_t *mappings, int value);
#endif /*DEFINITIONS_H_*/
-128
View File
@@ -1,128 +0,0 @@
strongSwans overall design
============================
IKEv1 and IKEv2 is handled in different keying daemons. The ole IKEv1 stuff is
completely handled in pluto, as it was all the times. IKEv2 is handled in the
new keying daemon, which is called charon.
Daemon control is done over unix sockets. Pluto uses whack, as it did for years.
Charon uses another socket interface, called stroke. Stroke uses another
format as whack and therefore is not compatible to whack. The starter utility,
wich does fast configuration parsing, speaks both the protocols, whack and
stroke. It also handles daemon startup and termination.
Pluto uses starter for some commands, for other it uses the whack utility. To be
as close to pluto as possible, charon has the same split up of commands to
starter and stroke. All commands are wrapped together in the ipsec script, which
allows transparent control of both daemons.
+-----------------------------------------+
| ipsec |
+-----+--------------+---------------+----+
| | |
| | |
| +-----+-----+ |
+-----+----+ | | +-----+----+
| | | starter | | |
| stroke | | | | whack |
| | +---+--+----+ | |
+------+---+ | | +--+-------+
| | | |
+---+------+ | | +------+--+
| | | | | |
| charon +----+ +----+ pluto |
| | | |
+-----+----+ +----+----+
| |
+-----+----+ |
| LSF | |
+-----+----+ |
| |
+-----+----+ +----+----+
| RAW Sock | | UDP/500 |
+----------+ +---------+
Since IKEv2 uses the same port as IKEv1, both daemons must listen to UDP port
500. Under Linux, there is no clean way to set up two sockets at the same port.
To reslove this problem, charon uses a RAW socket, as they are used in network
sniffers. An installed Linux Socket Filter (LSF) filters out all none-IKEv2
traffic. Pluto receives any IKE message, independant of charons behavior.
Therefore plutos behavior is changed to discard any IKEv2 traffic silently.
IKEv2 keying daemon: charon
=============================
Threading modell
------------------
All IKEv2 stuff is handled in charon. It uses a newer and more flexible
architecture than pluto. Charon uses a thread-pool, which allows parallel
execution SA-management. Beside the thread-pool, there are some special purpose
threads which do their job for the common health of the daemon.
+------+
| E Q |
| v u |---+ +------+ +------+
| e e | | | | | IKE- |
| n u | +-----------+ | |--| SA |
| t e | | | | I M | +------+
+------------+ | - | | Scheduler | | K a |
| receiver | +------+ | | | E n | +------+
+----+-------+ +-----------+ | - a | | IKE- |
| | +------+ | | S g |--| SA |
+-------+--+ +-----| J Q |---+ +------------+ | A e | +------+
-| socket | | o u | | | | - r |
+-------+--+ | b e | | Thread- | | |
| | - u | | Pool | | |
+----+-------+ | e |------| |---| |
| sender | +------+ +------------+ +------+
+----+-------+
| +------+
| | S Q |
| | e u |
| | n e |
+------------| d u |
| - e |
+--+---+
The thread-pool is the heart of the architecture. It processes jobs from a
(fully synchronized) job-queue. Mostly, a job is associated with a specific
IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA.
This makes it unnecesary to use further synchronisation methods once a IKE SA
is checked out. The (rather complex) synchronization of IKE SAs is completely
done in the IKE SA manager.
The sceduler is responsible for event firing. It waits until a event in the
(fully synchronized) event-queue is ready for processing and pushes the event
down to the job-queue. A thread form the pool will pick it up as quick as
possible. Every thread can queue events or jobs. Furter, an event can place a
packet in the send-queue. The sender thread waits for those packets and sends
them over the wire, via the socket. The receiver does exactly the opposite of
the sender. It waits on the socket, reads in packets an places them on the
job-queue for further processing by a thread from the pool.
There are even more threads, not drawn in the upper scheme. The stroke thread
is responsible for reading and processessing commands from another process. The
kernel interface thread handles communication from and to the kernel via a
netlink socket. It waits for kernel events and processes them appropriately.
configuration backends
------------------------
The configuration architecture for charon is complex, but is flexible and
extensible. All configuration stuff is split up in multiple parts:
connection Defines a connection between two hosts. Proposals define with
wich algorithms a IKE SA should be set up.
policy Defines the rules to apply ontop of a connection. A policy is
defined between two IDs. Proposals and traffic selectors allow
fine grained configuration of the CHILD SAs (AH and ESP) to set
up.
credential A credential is something used for authentication, such as a
preshared key, a RSA private or public key, certificate, ...
configuration The configuration itself handles daemon related configuration
stuff, such as interface binding or logging settings.
These configuration types are defined as interfaces, and are currently
implemented only in the stroke class. Through the modular design, parts could be
replaced with more powerful backends, such as a RADIUS server for the
credentials, a SQL database for the connections, policy definitions on an LDAP
server, and so on...
-41
View File
@@ -1,41 +0,0 @@
TODO-List for charon
======================
+ = done, - = todo, ordered by priority
+ private key loading: der, without passphrase
+ load all private keys from ipsec.d/private/ in stroke.c
+ handle leftcert and rightcert in starterstroke.c/stroke.c
+ load specified certs in stroke.c
+ extract public keys from certs
+ public key authentication
+ release for Andreas
+ stroke loglevels
+ stroke up
+ ike_sa_manager checkout_by_hosts
+ stroke down
+ stroke output redirection
+ stroke status
- libx509
- new charon build - libstrong?
- transforms
- utils (plus host)
- integrate asn1 parser/oid (asn1/oid)
- integrate PEM loading (pem)
- ... (more to come, for sure)
- ipsec.secrets parsing
- certificate DN parsing
- certificate subjectAltName parsing
- certificate lookup via ID
- certificate validation/chaining
- certificate exchange
- trapping
- delete notify, when to send?
- notifys on connection setup failure
- create child sa message
+4 -4
View File
@@ -12,17 +12,17 @@
# for more details.
#
ENCODING_DIR= $(MAIN_DIR)encoding/
ENCODING_DIR= $(CHARON_DIR)encoding/
OBJS+= $(BUILD_DIR)generator.o
CHARON_OBJS+= $(BUILD_DIR)generator.o
$(BUILD_DIR)generator.o : $(ENCODING_DIR)generator.c $(ENCODING_DIR)generator.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)parser.o
CHARON_OBJS+= $(BUILD_DIR)parser.o
$(BUILD_DIR)parser.o : $(ENCODING_DIR)parser.c $(ENCODING_DIR)parser.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)message.o
CHARON_OBJS+= $(BUILD_DIR)message.o
$(BUILD_DIR)message.o : $(ENCODING_DIR)message.c $(ENCODING_DIR)message.h
$(CC) $(CFLAGS) -c -o $@ $<
+2 -2
View File
@@ -29,8 +29,8 @@
#include <encoding/payloads/ike_header.h>
#include <encoding/payloads/notify_payload.h>
#include <utils/linked_list.h>
#include <transforms/crypters/crypter.h>
#include <transforms/signers/signer.h>
#include <crypto/crypters/crypter.h>
#include <crypto/signers/signer.h>
typedef struct message_t message_t;
@@ -14,95 +14,95 @@
PAYLOADS_DIR= $(ENCODING_DIR)payloads/
OBJS+= $(BUILD_DIR)encodings.o
CHARON_OBJS+= $(BUILD_DIR)encodings.o
$(BUILD_DIR)encodings.o : $(PAYLOADS_DIR)encodings.c $(PAYLOADS_DIR)encodings.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ike_header.o
CHARON_OBJS+= $(BUILD_DIR)ike_header.o
$(BUILD_DIR)ike_header.o : $(PAYLOADS_DIR)ike_header.c $(PAYLOADS_DIR)ike_header.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ke_payload.o
CHARON_OBJS+= $(BUILD_DIR)ke_payload.o
$(BUILD_DIR)ke_payload.o : $(PAYLOADS_DIR)ke_payload.c $(PAYLOADS_DIR)ke_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)nonce_payload.o
CHARON_OBJS+= $(BUILD_DIR)nonce_payload.o
$(BUILD_DIR)nonce_payload.o : $(PAYLOADS_DIR)nonce_payload.c $(PAYLOADS_DIR)nonce_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)notify_payload.o
CHARON_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
CHARON_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)auth_payload.o
CHARON_OBJS+= $(BUILD_DIR)auth_payload.o
$(BUILD_DIR)auth_payload.o : $(PAYLOADS_DIR)auth_payload.c $(PAYLOADS_DIR)auth_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)cert_payload.o
CHARON_OBJS+= $(BUILD_DIR)cert_payload.o
$(BUILD_DIR)cert_payload.o : $(PAYLOADS_DIR)cert_payload.c $(PAYLOADS_DIR)cert_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)certreq_payload.o
CHARON_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
CHARON_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)vendor_id_payload.o
CHARON_OBJS+= $(BUILD_DIR)vendor_id_payload.o
$(BUILD_DIR)vendor_id_payload.o : $(PAYLOADS_DIR)vendor_id_payload.c $(PAYLOADS_DIR)vendor_id_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)cp_payload.o
CHARON_OBJS+= $(BUILD_DIR)cp_payload.o
$(BUILD_DIR)cp_payload.o : $(PAYLOADS_DIR)cp_payload.c $(PAYLOADS_DIR)cp_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)configuration_attribute.o
CHARON_OBJS+= $(BUILD_DIR)configuration_attribute.o
$(BUILD_DIR)configuration_attribute.o : $(PAYLOADS_DIR)configuration_attribute.c $(PAYLOADS_DIR)configuration_attribute.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)eap_payload.o
CHARON_OBJS+= $(BUILD_DIR)eap_payload.o
$(BUILD_DIR)eap_payload.o : $(PAYLOADS_DIR)eap_payload.c $(PAYLOADS_DIR)eap_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)unknown_payload.o
CHARON_OBJS+= $(BUILD_DIR)unknown_payload.o
$(BUILD_DIR)unknown_payload.o : $(PAYLOADS_DIR)unknown_payload.c $(PAYLOADS_DIR)unknown_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ts_payload.o
CHARON_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 $@ $<
OBJS+= $(BUILD_DIR)traffic_selector_substructure.o
CHARON_OBJS+= $(BUILD_DIR)traffic_selector_substructure.o
$(BUILD_DIR)traffic_selector_substructure.o : $(PAYLOADS_DIR)traffic_selector_substructure.c $(PAYLOADS_DIR)traffic_selector_substructure.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)payload.o
CHARON_OBJS+= $(BUILD_DIR)payload.o
$(BUILD_DIR)payload.o : $(PAYLOADS_DIR)payload.c $(PAYLOADS_DIR)payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)proposal_substructure.o
CHARON_OBJS+= $(BUILD_DIR)proposal_substructure.o
$(BUILD_DIR)proposal_substructure.o : $(PAYLOADS_DIR)proposal_substructure.c $(PAYLOADS_DIR)proposal_substructure.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)sa_payload.o
CHARON_OBJS+= $(BUILD_DIR)sa_payload.o
$(BUILD_DIR)sa_payload.o : $(PAYLOADS_DIR)sa_payload.c $(PAYLOADS_DIR)sa_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)transform_attribute.o
CHARON_OBJS+= $(BUILD_DIR)transform_attribute.o
$(BUILD_DIR)transform_attribute.o : $(PAYLOADS_DIR)transform_attribute.c $(PAYLOADS_DIR)transform_attribute.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)transform_substructure.o
CHARON_OBJS+= $(BUILD_DIR)transform_substructure.o
$(BUILD_DIR)transform_substructure.o : $(PAYLOADS_DIR)transform_substructure.c $(PAYLOADS_DIR)transform_substructure.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)encryption_payload.o
CHARON_OBJS+= $(BUILD_DIR)encryption_payload.o
$(BUILD_DIR)encryption_payload.o : $(PAYLOADS_DIR)encryption_payload.c $(PAYLOADS_DIR)encryption_payload.h
$(CC) $(CFLAGS) -c -o $@ $<
@@ -34,7 +34,7 @@
#include <encoding/parser.h>
#include <utils/iterator.h>
#include <utils/randomizer.h>
#include <transforms/signers/signer.h>
#include <crypto/signers/signer.h>
@@ -294,7 +294,12 @@ static status_t encrypt(private_encryption_payload_t *this)
/* build padding */
block_size = this->crypter->get_block_size(this->crypter);
padding.len = block_size - ((this->decrypted.len + 1) % block_size);
randomizer->allocate_pseudo_random_bytes(randomizer, padding.len, &padding);
status = randomizer->allocate_pseudo_random_bytes(randomizer, padding.len, &padding);
if (status != SUCCESS)
{
randomizer->destroy(randomizer);
return status;
}
/* concatenate payload data, padding, padding len */
to_crypt.len = this->decrypted.len + padding.len + 1;
@@ -306,8 +311,14 @@ static status_t encrypt(private_encryption_payload_t *this)
/* build iv */
iv.len = block_size;
randomizer->allocate_pseudo_random_bytes(randomizer, iv.len, &iv);
status = randomizer->allocate_pseudo_random_bytes(randomizer, iv.len, &iv);
randomizer->destroy(randomizer);
if (status != SUCCESS)
{
allocator_free_chunk(&to_crypt);
allocator_free_chunk(&padding);
return status;
}
this->logger->log_chunk(this->logger, RAW|LEVEL2, "data before encryption with padding", to_crypt);
@@ -23,8 +23,8 @@
#define ENCRYPTION_PAYLOAD_H_
#include <types.h>
#include <transforms/crypters/crypter.h>
#include <transforms/signers/signer.h>
#include <crypto/crypters/crypter.h>
#include <crypto/signers/signer.h>
#include <encoding/payloads/payload.h>
#include <utils/linked_list.h>
@@ -26,7 +26,7 @@
#include <types.h>
#include <encoding/payloads/payload.h>
#include <network/host.h>
#include <utils/host.h>
#include <config/traffic_selector.h>
/**
@@ -28,10 +28,10 @@
#include <encoding/payloads/payload.h>
#include <encoding/payloads/transform_attribute.h>
#include <utils/linked_list.h>
#include <transforms/diffie_hellman.h>
#include <transforms/signers/signer.h>
#include <transforms/prfs/prf.h>
#include <transforms/crypters/crypter.h>
#include <crypto/diffie_hellman.h>
#include <crypto/signers/signer.h>
#include <crypto/prfs/prf.h>
#include <crypto/crypters/crypter.h>
#include <config/proposal.h>
+3 -7
View File
@@ -12,17 +12,13 @@
# for more details.
#
NETWORK_DIR= $(MAIN_DIR)network/
NETWORK_DIR= $(CHARON_DIR)network/
OBJS+= $(BUILD_DIR)packet.o
CHARON_OBJS+= $(BUILD_DIR)packet.o
$(BUILD_DIR)packet.o : $(NETWORK_DIR)packet.c $(NETWORK_DIR)packet.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)socket.o
CHARON_OBJS+= $(BUILD_DIR)socket.o
$(BUILD_DIR)socket.o : $(NETWORK_DIR)socket.c $(NETWORK_DIR)socket.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)host.o
$(BUILD_DIR)host.o : $(NETWORK_DIR)host.c $(NETWORK_DIR)host.h
$(CC) $(CFLAGS) -c -o $@ $<
-365
View File
@@ -1,365 +0,0 @@
/**
* @file host.c
*
* @brief Implementation of host_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 "host.h"
#include <utils/allocator.h>
typedef struct private_host_t private_host_t;
/**
* @brief Private Data of a host object.
*/
struct private_host_t {
/**
* Public data
*/
host_t public;
/**
* Address family to use, such as AF_INET or AF_INET6
*/
int family;
/**
* string representation of host
*/
char *string;
/**
* low-lewel structure, wich stores the address
*/
union {
struct sockaddr address;
struct sockaddr_in address4;
};
/**
* length of address structure
*/
socklen_t socklen;
};
/**
* implements host_t.get_sockaddr
*/
static sockaddr_t *get_sockaddr(private_host_t *this)
{
return &(this->address);
}
/**
* implements host_t.get_sockaddr_len
*/
static socklen_t *get_sockaddr_len(private_host_t *this)
{
return &(this->socklen);
}
/**
* Implementation of host_t.is_default_route.
*/
static bool is_default_route (private_host_t *this)
{
switch (this->family)
{
case AF_INET:
{
static u_int8_t default_route[4] = {0x00,0x00,0x00,0x00};
if (memcmp(default_route,&(this->address4.sin_addr.s_addr),4) == 0)
{
return TRUE;
}
return FALSE;
}
default:
{
/* empty chunk is returned */
return FALSE;
}
}
}
/**
* implements host_t.get_address
*/
static char *get_address(private_host_t *this)
{
switch (this->family)
{
case AF_INET:
{
char *string;
/* we need to clone it, since inet_ntoa overwrites
* internal buffer on subsequent calls
*/
allocator_free(this->string);
string = inet_ntoa(this->address4.sin_addr);
this->string = allocator_alloc(strlen(string)+1);
strcpy(this->string, string);
return this->string;
}
default:
{
return "(family not supported)";
}
}
}
/**
* Implementation of host_t.get_address_as_chunk.
*/
static chunk_t get_address_as_chunk(private_host_t *this)
{
chunk_t address = CHUNK_INITIALIZER;
switch (this->family)
{
case AF_INET:
{
/* allocate 4 bytes for IPV4 address*/
address.ptr = allocator_alloc(4);
address.len = 4;
memcpy(address.ptr,&(this->address4.sin_addr.s_addr),4);
}
default:
{
/* empty chunk is returned */
return address;
}
}
}
static xfrm_address_t get_xfrm_addr(private_host_t *this)
{
switch (this->family)
{
case AF_INET:
{
return (xfrm_address_t)(this->address4.sin_addr.s_addr);
}
default:
{
/* todo */
return (xfrm_address_t)(this->address4.sin_addr.s_addr);
}
}
}
static int get_family(private_host_t *this)
{
return this->family;
}
/**
* implements host_t.get_port
*/
static u_int16_t get_port(private_host_t *this)
{
switch (this->family)
{
case AF_INET:
{
return ntohs(this->address4.sin_port);
}
default:
{
return 0;
}
}
}
/**
* Implements host_t.clone.
*/
static private_host_t *clone(private_host_t *this)
{
private_host_t *new = allocator_alloc_thing(private_host_t);
memcpy(new, this, sizeof(private_host_t));
if (this->string)
{
new->string = allocator_alloc(strlen(this->string)+1);
strcpy(new->string, this->string);
}
return new;
}
/**
* Impelements host_t.ip_equals
*/
static bool ip_equals(private_host_t *this, private_host_t *other)
{
switch (this->family)
{
/* IPv4 */
case AF_INET:
{
if ((this->address4.sin_family == other->address4.sin_family) &&
(this->address4.sin_addr.s_addr == other->address4.sin_addr.s_addr))
{
return TRUE;
}
}
}
return FALSE;
}
/**
* Impelements host_t.equals
*/
static bool equals(private_host_t *this, private_host_t *other)
{
switch (this->family)
{
/* IPv4 */
case AF_INET:
{
if ((this->address4.sin_family == other->address4.sin_family) &&
(this->address4.sin_addr.s_addr == other->address4.sin_addr.s_addr) &&
(this->address4.sin_port == other->address4.sin_port))
{
return TRUE;
}
}
}
return FALSE;
}
/**
* Implements host_t.destroy
*/
static void destroy(private_host_t *this)
{
allocator_free(this->string);
allocator_free(this);
}
/**
* Creates an empty host_t object
*/
static private_host_t *host_create_empty()
{
private_host_t *this = allocator_alloc_thing(private_host_t);
this->public.get_sockaddr = (sockaddr_t* (*) (host_t*))get_sockaddr;
this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len;
this->public.clone = (host_t* (*) (host_t*))clone;
this->public.get_family = (int (*) (host_t*))get_family;
this->public.get_xfrm_addr = (xfrm_address_t (*) (host_t *))get_xfrm_addr;
this->public.get_address = (char* (*) (host_t *))get_address;
this->public.get_address_as_chunk = (chunk_t (*) (host_t *)) get_address_as_chunk;
this->public.get_port = (u_int16_t (*) (host_t *))get_port;
this->public.ip_equals = (bool (*) (host_t *,host_t *)) ip_equals;
this->public.equals = (bool (*) (host_t *,host_t *)) equals;
this->public.is_default_route = (bool (*) (host_t *)) is_default_route;
this->public.destroy = (void (*) (host_t*))destroy;
this->string = NULL;
return this;
}
/*
* Described in header.
*/
host_t *host_create(int family, char *address, u_int16_t port)
{
private_host_t *this = host_create_empty();
this->family = family;
switch (family)
{
/* IPv4 */
case AF_INET:
{
this->address4.sin_family = AF_INET;
this->address4.sin_addr.s_addr = inet_addr(address);
this->address4.sin_port = htons(port);
this->socklen = sizeof(struct sockaddr_in);
return &(this->public);
}
default:
{
allocator_free(this);
return NULL;
}
}
}
/*
* Described in header.
*/
host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
{
private_host_t *this = host_create_empty();
this->family = family;
switch (family)
{
/* IPv4 */
case AF_INET:
{
if (address.len != 4)
{
break;
}
this->address4.sin_family = AF_INET;
memcpy(&(this->address4.sin_addr.s_addr),address.ptr,4);
this->address4.sin_port = htons(port);
this->socklen = sizeof(struct sockaddr_in);
return &(this->public);
}
}
allocator_free(this);
return NULL;
}
/*
* Described in header.
*/
host_t *host_create_from_sockaddr(sockaddr_t *sockaddr)
{
chunk_t address;
switch (sockaddr->sa_family)
{
/* IPv4 */
case AF_INET:
{
struct sockaddr_in *sin = (struct sockaddr_in *)sockaddr;
address.ptr = (void*)&(sin->sin_addr.s_addr);
address.len = 4;
return host_create_from_chunk(AF_INET, address, ntohs(sin->sin_port));
}
default:
return NULL;
}
}
-225
View File
@@ -1,225 +0,0 @@
/**
* @file host.h
*
* @brief Interface of host_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 HOST_H_
#define HOST_H_
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/xfrm.h>
#include <types.h>
typedef struct host_t host_t;
/**
* @brief Representates a Host
*
* Host object, identifies a address:port pair and defines some
* useful functions on it.
*
* @b Constructors:
* - host_create()
* - host_create_from_chunk()
* - host_create_from_sockaddr()
*
* @todo Add IPv6 support
*
* @ingroup network
*/
struct host_t {
/**
* @brief Build a clone of this host object.
*
* @param this object to clone
* @return cloned host
*/
host_t *(*clone) (host_t *this);
/**
* @brief Get a pointer to the internal sockaddr struct.
*
* This is used for sending and receiving via sockets.
*
* @param this object to clone
* @return pointer to the internal sockaddr structure
*/
sockaddr_t *(*get_sockaddr) (host_t *this);
/**
* @brief Get the length of the sockaddr struct.
*
* Sepending on the family, the length of the sockaddr struct
* is different. Use this function to get the length of the sockaddr
* struct returned by get_sock_addr.
*
* This is used for sending and receiving via sockets.
*
* @param this object to clone
* @return length of the sockaddr struct
*/
socklen_t *(*get_sockaddr_len) (host_t *this);
/**
* @brief Gets the address as xfrm_address_t.
*
* This function allows the conversion to an
* xfrm_address_t, used for netlink communication
* with the kernel.
*
* @see kernel_interface_t.
*
* @param this calling object
* @return address in xfrm_address_t format
*/
xfrm_address_t (*get_xfrm_addr) (host_t *this);
/**
* @brief Gets the family of the address
*
* @param this calling object
* @return family
*/
int (*get_family) (host_t *this);
/**
* @brief get the address of this host
*
* Mostly used for debugging purposes.
* @warning string must NOT be freed
*
* @param this object
* @return address string,
*/
char* (*get_address) (host_t *this);
/**
* @brief Checks if the ip address of host is set to default route.
*
* @param this calling object
* @return
* - TRUE if host has IP 0.0.0.0 for default route
* - FALSE otherwise
*/
bool (*is_default_route) (host_t *this);
/**
* @brief get the address of this host as chunk_t
*
* @warning returned chunk has to get destroyed by caller.
*
* @param this object
* @return address string,
*/
chunk_t (*get_address_as_chunk) (host_t *this);
/**
* @brief get the port of this host
*
* Mostly used for debugging purposes.
*
* @param this object to clone
* @return port number
*/
u_int16_t (*get_port) (host_t *this);
/**
* @brief Compare the ips of two hosts hosts.
*
* @param this object to compare
* @param other the other to compare
* @return TRUE if addresses are equal.
*/
bool (*ip_equals) (host_t *this, host_t *other);
/**
* @brief Compare two hosts, with port.
*
* @param this object to compare
* @param other the other to compare
* @return TRUE if addresses and ports are equal.
*/
bool (*equals) (host_t *this, host_t *other);
/**
* @brief Destroy this host object
*
* @param this calling
* @return SUCCESS in any case
*/
void (*destroy) (host_t *this);
};
/**
* @brief Constructor to create a host_t object from an address string
*
* Currently supports only IPv4!
*
* @param family Address family to use for this object, such as AF_INET or AF_INET6
* @param address string of an address, such as "152.96.193.130"
* @param port port number
* @return
* - host_t object
* - NULL, if family not supported.
*
* @ingroup network
*/
host_t *host_create(int family, char *address, u_int16_t port);
/**
* @brief Constructor to create a host_t object from an address chunk
*
* Currently supports only IPv4!
*
* @param family Address family to use for this object, such as AF_INET or AF_INET6
* @param address address as 4 byte chunk_t in networ order
* @param port port number
* @return
* - host_t object
* - NULL, if family not supported or chunk_t length not 4 bytes.
*
* @ingroup network
*/
host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port);
/**
* @brief Constructor to create a host_t object from a sockaddr struct
*
* Currently supports only IPv4!
*
* @param sockaddr sockaddr struct which contains family, address and port
* @return
* - host_t object
* - NULL, if family not supported.
*
* @ingroup network
*/
host_t *host_create_from_sockaddr(sockaddr_t *sockaddr);
#endif /*HOST_H_*/
+1 -1
View File
@@ -25,7 +25,7 @@
#include <types.h>
#include <network/host.h>
#include <utils/host.h>
typedef struct packet_t packet_t;
+4 -4
View File
@@ -12,17 +12,17 @@
# for more details.
#
QUEUES_DIR= $(MAIN_DIR)queues/
QUEUES_DIR= $(CHARON_DIR)queues/
OBJS+= $(BUILD_DIR)event_queue.o
CHARON_OBJS+= $(BUILD_DIR)event_queue.o
$(BUILD_DIR)event_queue.o : $(QUEUES_DIR)event_queue.c $(QUEUES_DIR)event_queue.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)job_queue.o
CHARON_OBJS+= $(BUILD_DIR)job_queue.o
$(BUILD_DIR)job_queue.o : $(QUEUES_DIR)job_queue.c $(QUEUES_DIR)job_queue.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)send_queue.o
CHARON_OBJS+= $(BUILD_DIR)send_queue.o
$(BUILD_DIR)send_queue.o : $(QUEUES_DIR)send_queue.c $(QUEUES_DIR)send_queue.h
$(CC) $(CFLAGS) -c -o $@ $<
+6 -6
View File
@@ -14,27 +14,27 @@
JOBS_DIR= $(QUEUES_DIR)jobs/
OBJS+= $(BUILD_DIR)delete_half_open_ike_sa_job.o
CHARON_OBJS+= $(BUILD_DIR)delete_half_open_ike_sa_job.o
$(BUILD_DIR)delete_half_open_ike_sa_job.o : $(JOBS_DIR)delete_half_open_ike_sa_job.c $(JOBS_DIR)delete_half_open_ike_sa_job.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)delete_established_ike_sa_job.o
CHARON_OBJS+= $(BUILD_DIR)delete_established_ike_sa_job.o
$(BUILD_DIR)delete_established_ike_sa_job.o : $(JOBS_DIR)delete_established_ike_sa_job.c $(JOBS_DIR)delete_established_ike_sa_job.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)incoming_packet_job.o
CHARON_OBJS+= $(BUILD_DIR)incoming_packet_job.o
$(BUILD_DIR)incoming_packet_job.o : $(JOBS_DIR)incoming_packet_job.c $(JOBS_DIR)incoming_packet_job.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)initiate_ike_sa_job.o
CHARON_OBJS+= $(BUILD_DIR)initiate_ike_sa_job.o
$(BUILD_DIR)initiate_ike_sa_job.o : $(JOBS_DIR)initiate_ike_sa_job.c $(JOBS_DIR)initiate_ike_sa_job.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)retransmit_request_job.o
CHARON_OBJS+= $(BUILD_DIR)retransmit_request_job.o
$(BUILD_DIR)retransmit_request_job.o : $(JOBS_DIR)retransmit_request_job.c $(JOBS_DIR)retransmit_request_job.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)job.o
CHARON_OBJS+= $(BUILD_DIR)job.o
$(BUILD_DIR)job.o : $(JOBS_DIR)job.c $(JOBS_DIR)job.h
$(CC) $(CFLAGS) -c -o $@ $<
+6 -6
View File
@@ -12,25 +12,25 @@
# for more details.
#
SA_DIR= $(MAIN_DIR)sa/
SA_DIR= $(CHARON_DIR)sa/
OBJS+= $(BUILD_DIR)ike_sa_id.o
CHARON_OBJS+= $(BUILD_DIR)ike_sa_id.o
$(BUILD_DIR)ike_sa_id.o : $(SA_DIR)ike_sa_id.c $(SA_DIR)ike_sa_id.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ike_sa_manager.o
CHARON_OBJS+= $(BUILD_DIR)ike_sa_manager.o
$(BUILD_DIR)ike_sa_manager.o : $(SA_DIR)ike_sa_manager.c $(SA_DIR)ike_sa_manager.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ike_sa.o
CHARON_OBJS+= $(BUILD_DIR)ike_sa.o
$(BUILD_DIR)ike_sa.o : $(SA_DIR)ike_sa.c $(SA_DIR)ike_sa.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)authenticator.o
CHARON_OBJS+= $(BUILD_DIR)authenticator.o
$(BUILD_DIR)authenticator.o : $(SA_DIR)authenticator.c $(SA_DIR)authenticator.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)child_sa.o
CHARON_OBJS+= $(BUILD_DIR)child_sa.o
$(BUILD_DIR)child_sa.o : $(SA_DIR)child_sa.c $(SA_DIR)child_sa.h
$(CC) $(CFLAGS) -c -o $@ $<
+1 -1
View File
@@ -25,7 +25,7 @@
#define CHILD_SA_H_
#include <types.h>
#include <transforms/prf_plus.h>
#include <crypto/prf_plus.h>
#include <encoding/payloads/proposal_substructure.h>
typedef struct child_sa_t child_sa_t;
+3 -3
View File
@@ -29,9 +29,9 @@
#include <utils/linked_list.h>
#include <utils/logger_manager.h>
#include <utils/randomizer.h>
#include <transforms/diffie_hellman.h>
#include <transforms/prf_plus.h>
#include <transforms/crypters/crypter.h>
#include <crypto/diffie_hellman.h>
#include <crypto/prf_plus.h>
#include <crypto/crypters/crypter.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/nonce_payload.h>
#include <encoding/payloads/ke_payload.h>
+3 -3
View File
@@ -32,9 +32,9 @@
#include <config/configuration.h>
#include <utils/logger.h>
#include <utils/randomizer.h>
#include <transforms/prfs/prf.h>
#include <transforms/crypters/crypter.h>
#include <transforms/signers/signer.h>
#include <crypto/prfs/prf.h>
#include <crypto/crypters/crypter.h>
#include <crypto/signers/signer.h>
#include <config/connection.h>
#include <config/policy.h>
+7 -7
View File
@@ -14,30 +14,30 @@
STATES_DIR= $(SA_DIR)states/
OBJS+= $(BUILD_DIR)ike_auth_requested.o
CHARON_OBJS+= $(BUILD_DIR)ike_auth_requested.o
$(BUILD_DIR)ike_auth_requested.o : $(STATES_DIR)ike_auth_requested.c $(STATES_DIR)ike_auth_requested.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ike_sa_established.o
CHARON_OBJS+= $(BUILD_DIR)ike_sa_established.o
$(BUILD_DIR)ike_sa_established.o : $(STATES_DIR)ike_sa_established.c $(STATES_DIR)ike_sa_established.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ike_sa_init_requested.o
CHARON_OBJS+= $(BUILD_DIR)ike_sa_init_requested.o
$(BUILD_DIR)ike_sa_init_requested.o : $(STATES_DIR)ike_sa_init_requested.c $(STATES_DIR)ike_sa_init_requested.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)ike_sa_init_responded.o
CHARON_OBJS+= $(BUILD_DIR)ike_sa_init_responded.o
$(BUILD_DIR)ike_sa_init_responded.o : $(STATES_DIR)ike_sa_init_responded.c $(STATES_DIR)ike_sa_init_responded.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)initiator_init.o
CHARON_OBJS+= $(BUILD_DIR)initiator_init.o
$(BUILD_DIR)initiator_init.o : $(STATES_DIR)initiator_init.c $(STATES_DIR)initiator_init.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)responder_init.o
CHARON_OBJS+= $(BUILD_DIR)responder_init.o
$(BUILD_DIR)responder_init.o : $(STATES_DIR)responder_init.c $(STATES_DIR)responder_init.h
$(CC) $(CFLAGS) -c -o $@ $<
OBJS+= $(BUILD_DIR)state.o
CHARON_OBJS+= $(BUILD_DIR)state.o
$(BUILD_DIR)state.o : $(STATES_DIR)state.c $(STATES_DIR)state.h
$(CC) $(CFLAGS) -c -o $@ $<
+2 -2
View File
@@ -29,8 +29,8 @@
#include <encoding/payloads/id_payload.h>
#include <encoding/payloads/auth_payload.h>
#include <encoding/payloads/notify_payload.h>
#include <transforms/signers/signer.h>
#include <transforms/crypters/crypter.h>
#include <crypto/signers/signer.h>
#include <crypto/crypters/crypter.h>
#include <sa/states/ike_sa_established.h>
#include <sa/authenticator.h>
#include <sa/child_sa.h>
@@ -31,7 +31,7 @@
#include <encoding/payloads/id_payload.h>
#include <encoding/payloads/auth_payload.h>
#include <encoding/payloads/ts_payload.h>
#include <transforms/diffie_hellman.h>
#include <crypto/diffie_hellman.h>
#include <sa/states/ike_auth_requested.h>
#include <sa/states/initiator_init.h>
#include <sa/authenticator.h>
@@ -27,7 +27,7 @@
#include <types.h>
#include <sa/ike_sa.h>
#include <sa/states/state.h>
#include <transforms/diffie_hellman.h>
#include <crypto/diffie_hellman.h>
typedef struct ike_sa_init_requested_t ike_sa_init_requested_t;
@@ -31,8 +31,8 @@
#include <encoding/payloads/id_payload.h>
#include <encoding/payloads/auth_payload.h>
#include <encoding/payloads/notify_payload.h>
#include <transforms/signers/signer.h>
#include <transforms/crypters/crypter.h>
#include <crypto/signers/signer.h>
#include <crypto/crypters/crypter.h>
#include <sa/states/ike_sa_established.h>
+18 -7
View File
@@ -28,7 +28,7 @@
#include <sa/states/ike_sa_init_requested.h>
#include <utils/allocator.h>
#include <queues/jobs/retransmit_request_job.h>
#include <transforms/diffie_hellman.h>
#include <crypto/diffie_hellman.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/ke_payload.h>
#include <encoding/payloads/nonce_payload.h>
@@ -92,7 +92,7 @@ struct private_initiator_init_t {
* @param this calling object
* @param request message_t object to add the NONCE payload
*/
void (*build_nonce_payload) (private_initiator_init_t *this,message_t *request);
status_t (*build_nonce_payload) (private_initiator_init_t *this,message_t *request);
/**
* Destroy function called internally of this class after state change to state
@@ -177,9 +177,14 @@ status_t retry_initiate_connection (private_initiator_init_t *this, diffie_hellm
this->build_ke_payload(this, message);
/* build Nonce payload */
this->build_nonce_payload(this,message);
status = this->build_nonce_payload(this, message);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Building nonce payload failed. Aborting");
message->destroy(message);
return DELETE_ME;
}
/* message can now be sent (must not be destroyed) */
status = this->ike_sa->send_request(this->ike_sa, message);
if (status != SUCCESS)
@@ -251,17 +256,22 @@ static void build_ke_payload(private_initiator_init_t *this, message_t *request)
/**
* Implementation of private_initiator_init_t.build_nonce_payload.
*/
static void build_nonce_payload(private_initiator_init_t *this, message_t *request)
static status_t build_nonce_payload(private_initiator_init_t *this, message_t *request)
{
nonce_payload_t *nonce_payload;
randomizer_t *randomizer;
status_t status;
this->logger->log(this->logger, CONTROL|LEVEL1, "Building NONCE payload");
this->logger->log(this->logger, CONTROL|LEVEL2, "Get pseudo random bytes for NONCE");
randomizer = this->ike_sa->get_randomizer(this->ike_sa);
randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
status = randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
if (status != SUCCESS)
{
return status;
}
this->logger->log(this->logger, RAW|LEVEL2, "Initiator NONCE",&(this->sent_nonce));
@@ -271,6 +281,7 @@ static void build_nonce_payload(private_initiator_init_t *this, message_t *reque
this->logger->log(this->logger, CONTROL|LEVEL2, "Add NONCE payload to message");
request->add_payload(request, (payload_t *) nonce_payload);
return SUCCESS;
}
/**
+7 -2
View File
@@ -30,7 +30,7 @@
#include <encoding/payloads/ke_payload.h>
#include <encoding/payloads/nonce_payload.h>
#include <encoding/payloads/notify_payload.h>
#include <transforms/diffie_hellman.h>
#include <crypto/diffie_hellman.h>
typedef struct private_responder_init_t private_responder_init_t;
@@ -428,6 +428,7 @@ static status_t build_nonce_payload(private_responder_init_t *this,nonce_payload
{
nonce_payload_t *nonce_payload;
randomizer_t *randomizer;
status_t status;
this->logger->log(this->logger, CONTROL | LEVEL2, "Process received NONCE payload");
allocator_free(this->received_nonce.ptr);
@@ -439,7 +440,11 @@ static status_t build_nonce_payload(private_responder_init_t *this,nonce_payload
this->logger->log(this->logger, CONTROL | LEVEL2, "Create new NONCE value.");
randomizer = this->ike_sa->get_randomizer(this->ike_sa);
randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
status = randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
if (status != SUCCESS)
{
return status;
}
this->logger->log(this->logger, CONTROL|LEVEL2, "Building NONCE payload");
nonce_payload = nonce_payload_create();
-304
View File
@@ -1,304 +0,0 @@
/* Stroke for charon is the counterpart to whack from pluto
* Copyright (C) 2006 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 <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <linux/stddef.h>
#include "stroke.h"
static char* push_string(stroke_msg_t **strm, char *string)
{
stroke_msg_t *stroke_msg;
size_t string_length;
if (string == NULL)
{
return NULL;
}
stroke_msg = *strm;
string_length = strlen(string) + 1;
stroke_msg->length += string_length;
stroke_msg = realloc(stroke_msg, stroke_msg->length);
strcpy((char*)stroke_msg + stroke_msg->length - string_length, string);
*strm = stroke_msg;
return (char*)(u_int)stroke_msg->length - string_length;
}
static int send_stroke_msg (stroke_msg_t *msg)
{
struct sockaddr_un ctl_addr = { AF_UNIX, STROKE_SOCKET };
int sock;
char buffer[64];
int byte_count;
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0)
{
fprintf(stderr, "Opening unix socket %s: %s\n", STROKE_SOCKET, strerror(errno));
return -1;
}
if (connect(sock, (struct sockaddr *)&ctl_addr,
offsetof(struct sockaddr_un, sun_path) + strlen(ctl_addr.sun_path)) < 0)
{
fprintf(stderr, "Connect to socket failed: %s\n", strerror(errno));
close(sock);
return -1;
}
/* send message */
if (write(sock, msg, msg->length) != msg->length)
{
fprintf(stderr, "writing to socket failed: %s\n", strerror(errno));
close(sock);
return -1;
}
while ((byte_count = read(sock, buffer, sizeof(buffer)-1)) > 0)
{
buffer[byte_count] = '\0';
printf("%s", buffer);
}
if (byte_count < 0)
{
fprintf(stderr, "reading from socket failed: %s\n", strerror(errno));
}
close(sock);
return 0;
}
static int add_connection(char *name,
char *my_id, char *other_id,
char *my_cert, char *other_cert,
char *my_addr, char *other_addr,
char *my_net, char *other_net,
u_int my_netmask, u_int other_netmask)
{
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
int res;
msg->length = sizeof(stroke_msg_t);
msg->type = STR_ADD_CONN;
msg->add_conn.name = push_string(&msg, name);
msg->add_conn.me.id = push_string(&msg, my_id);
msg->add_conn.me.cert = push_string(&msg, my_cert);
msg->add_conn.me.address = push_string(&msg, my_addr);
msg->add_conn.me.subnet = push_string(&msg, my_net);
msg->add_conn.me.subnet_mask = my_netmask;
msg->add_conn.other.id = push_string(&msg, other_id);
msg->add_conn.other.cert = push_string(&msg, other_cert);
msg->add_conn.other.address = push_string(&msg, other_addr);
msg->add_conn.other.subnet = push_string(&msg, other_net);
msg->add_conn.other.subnet_mask = other_netmask;
res = send_stroke_msg(msg);
free(msg);
return res;
}
static int initiate_connection(char *name)
{
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
int res;
msg->length = sizeof(stroke_msg_t);
msg->type = STR_INITIATE;
msg->initiate.name = push_string(&msg, name);
res = send_stroke_msg(msg);
free(msg);
return res;
}
static int terminate_connection(char *name)
{
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
int res;
msg->length = sizeof(stroke_msg_t);
msg->type = STR_TERMINATE;
msg->initiate.name = push_string(&msg, name);
res = send_stroke_msg(msg);
free(msg);
return res;
}
static int show_status()
{
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
int res;
msg->length = sizeof(stroke_msg_t);
msg->type = STR_STATUS;
res = send_stroke_msg(msg);
free(msg);
return res;
}
static int set_logtype(char *context, char *type, int enable)
{
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
int res;
msg->length = sizeof(stroke_msg_t);
msg->type = STR_LOGTYPE;
msg->logtype.context = push_string(&msg, context);
msg->logtype.type = push_string(&msg, type);
msg->logtype.enable = enable;
res = send_stroke_msg(msg);
free(msg);
return res;
}
static int set_loglevel(char *context, u_int level)
{
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
int res;
msg->length = sizeof(stroke_msg_t);
msg->type = STR_LOGLEVEL;
msg->loglevel.context = push_string(&msg, context);
msg->loglevel.level = level;
res = send_stroke_msg(msg);
free(msg);
return res;
}
static void exit_error(char *error)
{
if (error)
{
fprintf(stderr, "%s\n", error);
}
exit(-1);
}
static void exit_usage(char *error)
{
printf("Usage:\n");
printf(" Add a connection:\n");
printf(" stroke add NAME MY_ID OTHER_ID MY_CERT OTHER_CERT\\\n");
printf(" MY_ADDR OTHER_ADDR MY_NET OTHER_NET\\\n");
printf(" MY_NETBITS OTHER_NETBITS\n");
printf(" where: ID is any IKEv2 ID (currently only IPv4 adresses\n");
printf(" CERT is a certificate filename\n");
printf(" ADDR is a IPv4 address\n");
printf(" NET is a IPv4 address of the subnet to tunnel\n");
printf(" NETBITS is the size of the subnet, as the \"24\" in 192.168.0.0/24\n");
printf(" Initiate a connection:\n");
printf(" stroke up NAME\n");
printf(" where: NAME is a connection name added with \"stroke add\"\n");
printf(" Terminate a connection:\n");
printf(" stroke down NAME\n");
printf(" where: NAME is a connection name added with \"stroke add\"\n");
printf(" Set logtype for a logging context:\n");
printf(" stroke logtype CONTEXT TYPE ENABLE\n");
printf(" where: CONTEXT is PARSR|GNRAT|IKESA|SAMGR|CHDSA|MESSG|TPOOL|WORKR|SCHED|\n");
printf(" SENDR|RECVR|SOCKT|TESTR|DAEMN|CONFG|ENCPL|PAYLD\n");
printf(" TYPE is CONTROL|ERROR|AUDIT|RAW|PRIVATE\n");
printf(" ENABLE is 0|1\n");
printf(" Set loglevel for a logging context:\n");
printf(" stroke loglevel CONTEXT LEVEL\n");
printf(" where: CONTEXT is PARSR|GNRAT|IKESA|SAMGR|CHDSA|MESSG|TPOOL|WORKR|SCHED|\n");
printf(" SENDR|RECVR|SOCKT|TESTR|DAEMN|CONFG|ENCPL|PAYLD\n");
printf(" LEVEL is 0|1|2|3\n");
printf(" Show connection status:\n");
printf(" stroke status\n");
exit_error(error);
}
int main(int argc, char *argv[])
{
int res;
if (argc < 2)
{
exit_usage(NULL);
}
if (strcmp(argv[1], "status") == 0 ||
strcmp(argv[1], "statusall") == 0)
{
res = show_status();
}
else if (strcmp(argv[1], "up") == 0)
{
if (argc < 3)
{
exit_usage("\"up\" needs a connection name");
}
res = initiate_connection(argv[2]);
}
else if (strcmp(argv[1], "down") == 0)
{
if (argc < 3)
{
exit_usage("\"down\" needs a connection name");
}
res = terminate_connection(argv[2]);
}
else if (strcmp(argv[1], "add") == 0)
{
if (argc < 13)
{
exit_usage("\"add\" needs more parameters...");
}
res = add_connection(argv[2],
argv[3], argv[4],
argv[5], argv[6],
argv[7], argv[8],
argv[9], argv[10],
atoi(argv[11]), atoi(argv[12]));
}
else if (strcmp(argv[1], "logtype") == 0)
{
if (argc < 5)
{
exit_usage("\"logtype\" needs more parameters...");
}
res = set_logtype(argv[2], argv[3], atoi(argv[4]));
}
else if (strcmp(argv[1], "loglevel") == 0)
{
if (argc < 4)
{
exit_usage("\"logtype\" needs more parameters...");
}
res = set_loglevel(argv[2], atoi(argv[3]));
}
else
{
exit_usage(NULL);
}
if (res)
{
exit_error("communication with charon failed!\n");
}
return 0;
}
-86
View File
@@ -1,86 +0,0 @@
/**
* @file stroke.h
*
* @brief Definition of stroke_msg_t.
*
*/
/*
* Copyright (C) 2006 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 STROKE_H_
#define STROKE_H_
#define STROKE_SOCKET "/var/run/charon.ctl"
/**
* @brief A stroke message sent over the unix socket.
*
*/
typedef struct stroke_msg_t stroke_msg_t;
struct stroke_msg_t {
/* length of this message with all strings */
u_int16_t length;
/* type of the message */
enum {
/* initiate a connection */
STR_INITIATE,
/* install SPD entries for a connection */
STR_INSTALL,
/* add a connection */
STR_ADD_CONN,
/* delete a connection */
STR_DEL_CONN,
/* terminate connection */
STR_TERMINATE,
/* show connection status */
STR_STATUS,
/* set a log type to log/not log */
STR_LOGTYPE,
/* set the verbosity of a logging context */
STR_LOGLEVEL,
/* more to come */
} type;
union {
/* data for STR_INITIATE, STR_INSTALL, STR_UP, STR_DOWN */
struct {
char *name;
} initiate, install, terminate;
/* data for STR_ADD_CONN */
struct {
char *name;
struct {
char *id;
char *cert;
char *address;
char *subnet;
u_int8_t subnet_mask;
} me, other;
} add_conn;
struct {
char *context;
char *type;
int enable;
} logtype;
struct {
char *context;
u_int level;
} loglevel;
};
u_int8_t buffer[];
};
#endif /* STROKE_H_ */
-142
View File
@@ -1,142 +0,0 @@
# 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.
#
TESTCASES_DIR= $(MAIN_DIR)testcases/
TEST_OBJS+= $(BUILD_DIR)aes_cbc_crypter_test.o
$(BUILD_DIR)aes_cbc_crypter_test.o : $(TESTCASES_DIR)aes_cbc_crypter_test.c $(TESTCASES_DIR)aes_cbc_crypter_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)diffie_hellman_test.o
$(BUILD_DIR)diffie_hellman_test.o : $(TESTCASES_DIR)diffie_hellman_test.c $(TESTCASES_DIR)diffie_hellman_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)event_queue_test.o
$(BUILD_DIR)event_queue_test.o : $(TESTCASES_DIR)event_queue_test.c $(TESTCASES_DIR)event_queue_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)generator_test.o
$(BUILD_DIR)generator_test.o : $(TESTCASES_DIR)generator_test.c $(TESTCASES_DIR)generator_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)ike_sa_id_test.o
$(BUILD_DIR)ike_sa_id_test.o : $(TESTCASES_DIR)ike_sa_id_test.c $(TESTCASES_DIR)ike_sa_id_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)job_queue_test.o
$(BUILD_DIR)job_queue_test.o : $(TESTCASES_DIR)job_queue_test.c $(TESTCASES_DIR)job_queue_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)parser_test.o
$(BUILD_DIR)parser_test.o : $(TESTCASES_DIR)parser_test.c $(TESTCASES_DIR)parser_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)hasher_test.o
$(BUILD_DIR)hasher_test.o : $(TESTCASES_DIR)hasher_test.c $(TESTCASES_DIR)hasher_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)ike_sa_manager_test.o
$(BUILD_DIR)ike_sa_manager_test.o : $(TESTCASES_DIR)ike_sa_manager_test.c $(TESTCASES_DIR)ike_sa_manager_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)linked_list_test.o
$(BUILD_DIR)linked_list_test.o : $(TESTCASES_DIR)linked_list_test.c $(TESTCASES_DIR)linked_list_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)hmac_test.o
$(BUILD_DIR)hmac_test.o : $(TESTCASES_DIR)hmac_test.c $(TESTCASES_DIR)hmac_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)hmac_signer_test.o
$(BUILD_DIR)hmac_signer_test.o : $(TESTCASES_DIR)hmac_signer_test.c $(TESTCASES_DIR)hmac_signer_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)scheduler_test.o
$(BUILD_DIR)scheduler_test.o : $(TESTCASES_DIR)scheduler_test.c $(TESTCASES_DIR)scheduler_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)prf_plus_test.o
$(BUILD_DIR)prf_plus_test.o : $(TESTCASES_DIR)prf_plus_test.c $(TESTCASES_DIR)prf_plus_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)send_queue_test.o
$(BUILD_DIR)send_queue_test.o : $(TESTCASES_DIR)send_queue_test.c $(TESTCASES_DIR)send_queue_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)socket_test.o
$(BUILD_DIR)socket_test.o : $(TESTCASES_DIR)socket_test.c $(TESTCASES_DIR)socket_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)packet_test.o
$(BUILD_DIR)packet_test.o : $(TESTCASES_DIR)packet_test.c $(TESTCASES_DIR)packet_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)testcases.o
$(BUILD_DIR)testcases.o : $(TESTCASES_DIR)testcases.c
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)receiver_test.o
$(BUILD_DIR)receiver_test.o : $(TESTCASES_DIR)receiver_test.c $(TESTCASES_DIR)receiver_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)ike_sa_test.o
$(BUILD_DIR)ike_sa_test.o : $(TESTCASES_DIR)ike_sa_test.c $(TESTCASES_DIR)ike_sa_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)sender_test.o
$(BUILD_DIR)sender_test.o : $(TESTCASES_DIR)sender_test.c $(TESTCASES_DIR)sender_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)thread_pool_test.o
$(BUILD_DIR)thread_pool_test.o : $(TESTCASES_DIR)thread_pool_test.c $(TESTCASES_DIR)thread_pool_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)encryption_payload_test.o
$(BUILD_DIR)encryption_payload_test.o : $(TESTCASES_DIR)encryption_payload_test.c $(TESTCASES_DIR)encryption_payload_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)connection_test.o
$(BUILD_DIR)connection_test.o : $(TESTCASES_DIR)connection_test.c $(TESTCASES_DIR)connection_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)policy_test.o
$(BUILD_DIR)policy_test.o : $(TESTCASES_DIR)policy_test.c $(TESTCASES_DIR)policy_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)proposal_test.o
$(BUILD_DIR)proposal_test.o : $(TESTCASES_DIR)proposal_test.c $(TESTCASES_DIR)proposal_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)rsa_test.o
$(BUILD_DIR)rsa_test.o : $(TESTCASES_DIR)rsa_test.c $(TESTCASES_DIR)rsa_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)kernel_interface_test.o
$(BUILD_DIR)kernel_interface_test.o : $(TESTCASES_DIR)kernel_interface_test.c $(TESTCASES_DIR)kernel_interface_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)child_sa_test.o
$(BUILD_DIR)child_sa_test.o : $(TESTCASES_DIR)child_sa_test.c $(TESTCASES_DIR)child_sa_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)der_decoder_test.o
$(BUILD_DIR)der_decoder_test.o : $(TESTCASES_DIR)der_decoder_test.c $(TESTCASES_DIR)der_decoder_test.h
$(CC) $(CFLAGS) -c -o $@ $<
TEST_OBJS+= $(BUILD_DIR)certificate_test.o
$(BUILD_DIR)certificate_test.o : $(TESTCASES_DIR)certificate_test.c $(TESTCASES_DIR)certificate_test.h
$(CC) $(CFLAGS) -c -o $@ $<
@@ -1,202 +0,0 @@
/**
* @file aes_cbc_crypter_test.c
*
* @brief Tests for the aes_cbc_crypter_t class.
*
*/
/*
* 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 <string.h>
#include "aes_cbc_crypter_test.h"
#include <utils/allocator.h>
#include <daemon.h>
void test_aes_cbc_crypter(protected_tester_t *tester)
{
/*
* Test 1 of RFC3602
* Key : 0x06a9214036b8a15b512e03d534120006
* IV : 0x3dafba429d9eb430b422da802c9fac41
* Plaintext : "Single block msg"
* Ciphertext: 0xe353779c1079aeb82708942dbe77181a
*/
crypter_t *crypter;
u_int8_t key1[] = {0x06,0xa9,0x21,0x40,0x36,0xb8,0xa1,0x5b,
0x51,0x2e,0x03,0xd5,0x34,0x12,0x00,0x06};
chunk_t key1_chunk = {ptr: key1, len : 16};
u_int8_t iv1[] = {0x3d,0xaf,0xba,0x42,0x9d,0x9e,0xb4,0x30,
0xb4,0x22,0xda,0x80,0x2c,0x9f,0xac,0x41};
chunk_t iv1_chunk = {ptr: iv1, len : 16};
u_int8_t ciphertext1[] = { 0xe3,0x53,0x77,0x9c,0x10,0x79,0xae,0xb8,
0x27,0x08,0x94,0x2d,0xbe,0x77,0x18,0x1a};
chunk_t expected_encrypted1 = {ptr: ciphertext1, len : 16};
char * plaintext1 = "Single block msg";
chunk_t data1 = {ptr: plaintext1, len : 16};
chunk_t encrypted1;
chunk_t decrypted1;
logger_t *logger;
logger = charon->logger_manager->get_logger(charon->logger_manager,TESTER);
crypter = (crypter_t *) aes_cbc_crypter_create(16);
tester->assert_true(tester, (crypter != NULL), "create call test");
tester->assert_true(tester, (crypter->set_key(crypter,key1_chunk) == SUCCESS), "set_key call test");
tester->assert_true(tester, (crypter->encrypt(crypter,data1,iv1_chunk,&encrypted1) == SUCCESS), "encrypt call test");
tester->assert_true(tester, (memcmp(encrypted1.ptr, expected_encrypted1.ptr, 16) == 0), "Encrypted value");
logger->log_chunk(logger,RAW,"exptected encrypted :", expected_encrypted1);
logger->log_chunk(logger,RAW,"encrypted :", encrypted1);
tester->assert_true(tester, (crypter->decrypt(crypter,encrypted1,iv1_chunk,&decrypted1) == SUCCESS), "decrypt call test");
allocator_free_chunk(&encrypted1);
tester->assert_true(tester, (memcmp(decrypted1.ptr, plaintext1, 16) == 0), "decrypted value");
logger->log_chunk(logger,RAW,"expected decrypted :", data1);
logger->log_chunk(logger,RAW,"decrypted :", decrypted1);
allocator_free_chunk(&decrypted1);
crypter->destroy(crypter);
/*
* Test 2 of RFC3602
* Key : 0xc286696d887c9aa0611bbb3e2025a45a
* IV : 0x562e17996d093d28ddb3ba695a2e6f58
* Plaintext : 0x000102030405060708090a0b0c0d0e0f
* 101112131415161718191a1b1c1d1e1f
* Ciphertext: 0xd296cd94c2cccf8a3a863028b5e1dc0a
* 7586602d253cfff91b8266bea6d61ab1
*/
u_int8_t key2[] = {0xc2,0x86,0x69,0x6d,0x88,0x7c,0x9a,0xa0,
0x61,0x1b,0xbb,0x3e,0x20,0x25,0xa4,0x5a};
chunk_t key2_chunk = {ptr: key2, len : 16};
u_int8_t iv2[] = {0x56,0x2e,0x17,0x99,0x6d,0x09,0x3d,0x28,
0xdd,0xb3,0xba,0x69,0x5a,0x2e,0x6f,0x58};
chunk_t iv2_chunk = {ptr: iv2, len : 16};
u_int8_t ciphertext2[] = { 0xd2,0x96,0xcd,0x94,0xc2,0xcc,0xcf,0x8a,
0x3a,0x86,0x30,0x28,0xb5,0xe1,0xdc,0x0a,
0x75,0x86,0x60,0x2d,0x25,0x3c,0xff,0xf9,
0x1b,0x82,0x66,0xbe,0xa6,0xd6,0x1a,0xb1};
chunk_t expected_encrypted2 = {ptr: ciphertext2, len : 32};
u_int8_t plaintext2[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f};
chunk_t data2 = {ptr: plaintext2, len : 32};
chunk_t encrypted2;
chunk_t decrypted2;
crypter = (crypter_t *) aes_cbc_crypter_create(16);
tester->assert_true(tester, (crypter != NULL), "create call test");
tester->assert_true(tester, (crypter->set_key(crypter,key2_chunk) == SUCCESS), "set_key call test");
tester->assert_true(tester, (crypter->encrypt(crypter,data2,iv2_chunk,&encrypted2) == SUCCESS), "encrypt call test");
tester->assert_true(tester, (memcmp(encrypted2.ptr, expected_encrypted2.ptr, 32) == 0), "Encrypted value");
logger->log_chunk(logger,RAW,"exptected encrypted :", expected_encrypted2);
logger->log_chunk(logger,RAW,"encrypted :", encrypted2);
tester->assert_true(tester, (crypter->decrypt(crypter,encrypted2,iv2_chunk,&decrypted2) == SUCCESS), "decrypt call test");
allocator_free_chunk(&encrypted2);
tester->assert_true(tester, (memcmp(decrypted2.ptr, plaintext2, 32) == 0), "decrypted value");
logger->log_chunk(logger,RAW,"expected decrypted :", data2);
logger->log_chunk(logger,RAW,"decrypted :", decrypted2);
allocator_free_chunk(&decrypted2);
crypter->destroy(crypter);
/*
* Test 3 of RFC3603
* Key : 0x56e47a38c5598974bc46903dba290349
* IV : 0x8ce82eefbea0da3c44699ed7db51b7d9
* Plaintext : 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf
* b0b1b2b3b4b5b6b7b8b9babbbcbdbebf
* c0c1c2c3c4c5c6c7c8c9cacbcccdcecf
* d0d1d2d3d4d5d6d7d8d9dadbdcdddedf
* Ciphertext: 0xc30e32ffedc0774e6aff6af0869f71aa
* 0f3af07a9a31a9c684db207eb0ef8e4e
* 35907aa632c3ffdf868bb7b29d3d46ad
* 83ce9f9a102ee99d49a53e87f4c3da55
*/
u_int8_t key3[] = {0x56,0xe4,0x7a,0x38,0xc5,0x59,0x89,0x74,
0xbc,0x46,0x90,0x3d,0xba,0x29,0x03,0x49};
chunk_t key3_chunk = {ptr: key3, len : 16};
u_int8_t iv3[] = {0x8c,0xe8,0x2e,0xef,0xbe,0xa0,0xda,0x3c,
0x44,0x69,0x9e,0xd7,0xdb,0x51,0xb7,0xd9};
chunk_t iv3_chunk = {ptr: iv3, len : 16};
u_int8_t ciphertext3[] = { 0xc3,0x0e,0x32,0xff,0xed,0xc0,0x77,0x4e,
0x6a,0xff,0x6a,0xf0,0x86,0x9f,0x71,0xaa,
0x0f,0x3a,0xf0,0x7a,0x9a,0x31,0xa9,0xc6,
0x84,0xdb,0x20,0x7e,0xb0,0xef,0x8e,0x4e,
0x35,0x90,0x7a,0xa6,0x32,0xc3,0xff,0xdf,
0x86,0x8b,0xb7,0xb2,0x9d,0x3d,0x46,0xad,
0x83,0xce,0x9f,0x9a,0x10,0x2e,0xe9,0x9d,
0x49,0xa5,0x3e,0x87,0xf4,0xc3,0xda,0x55};
chunk_t expected_encrypted3 = {ptr: ciphertext3, len : 64};
u_int8_t plaintext3[] = {0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,
0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf};
chunk_t data3 = {ptr: plaintext3, len : 64};
chunk_t encrypted3;
chunk_t decrypted3;
crypter = (crypter_t *) aes_cbc_crypter_create(16);
tester->assert_true(tester, (crypter != NULL), "create call test");
tester->assert_true(tester, (crypter->set_key(crypter,key3_chunk) == SUCCESS), "set_key call test");
tester->assert_true(tester, (crypter->encrypt(crypter,data3,iv3_chunk,&encrypted3) == SUCCESS), "encrypt call test");
tester->assert_true(tester, (memcmp(encrypted3.ptr, expected_encrypted3.ptr, 64) == 0), "Encrypted value");
logger->log_chunk(logger,RAW,"exptected encrypted :", expected_encrypted3);
logger->log_chunk(logger,RAW,"encrypted :", encrypted3);
tester->assert_true(tester, (crypter->decrypt(crypter,encrypted3,iv3_chunk,&decrypted3) == SUCCESS), "decrypt call test");
allocator_free_chunk(&encrypted3);
tester->assert_true(tester, (memcmp(decrypted3.ptr, plaintext3, 64) == 0), "decrypted value");
logger->log_chunk(logger,RAW,"expected decrypted :", data3);
logger->log_chunk(logger,RAW,"decrypted :", decrypted3);
allocator_free_chunk(&decrypted3);
crypter->destroy(crypter);
}
@@ -1,38 +0,0 @@
/**
* @file aes_cbc_crypter_test.h
*
* @brief Tests for the aes_cbc_crypter_t class.
*
*/
/*
* 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 AES_CBC_CRYPTER_TEST_H_
#define AES_CBC_CRYPTER_TEST_H_
#include <transforms/crypters/aes_cbc_crypter.h>
#include <utils/tester.h>
/**
* @brief Test function used to test the aes_cbc_crypter_t class.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_aes_cbc_crypter(protected_tester_t *tester);
#endif /* AES_CBC_CRYPTER_TEST_H_ */
@@ -1,95 +0,0 @@
/**
* @file certificate_test.c
*
* @brief Tests for the certificate_t class.
*
*/
/*
* Copyright (C) 2006 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 "certificate_test.h"
#include <daemon.h>
#include <transforms/certificate.h>
#include <utils/allocator.h>
#include <utils/logger.h>
static char certificate_buffer[] = {
0x30,0x82,0x02,0xf9,0x30,0x82,0x01,0xe1,0xa0,0x03,0x02,0x01,0x02,0x02,0x11,0x00,
0xfe,0xae,0xe3,0xcf,0x00,0x27,0x8d,0xa0,0xe1,0xfa,0xb2,0x07,0xd4,0x15,0x40,0x93,
0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,
0x38,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x19,
0x30,0x17,0x06,0x03,0x55,0x04,0x0a,0x13,0x10,0x4c,0x69,0x6e,0x75,0x78,0x20,0x73,
0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,
0x04,0x03,0x13,0x05,0x6d,0x61,0x65,0x6e,0x6f,0x30,0x1e,0x17,0x0d,0x30,0x36,0x30,
0x33,0x32,0x37,0x30,0x36,0x35,0x32,0x33,0x38,0x5a,0x17,0x0d,0x31,0x31,0x30,0x33,
0x32,0x36,0x30,0x36,0x35,0x32,0x33,0x38,0x5a,0x30,0x38,0x31,0x0b,0x30,0x09,0x06,
0x03,0x55,0x04,0x06,0x13,0x02,0x43,0x48,0x31,0x19,0x30,0x17,0x06,0x03,0x55,0x04,
0x0a,0x13,0x10,0x4c,0x69,0x6e,0x75,0x78,0x20,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,
0x77,0x61,0x6e,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x6d,0x61,
0x65,0x6e,0x6f,0x30,0x82,0x01,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,
0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0f,0x00,0x30,0x82,0x01,0x0a,0x02,
0x82,0x01,0x01,0x00,0xe3,0x75,0x56,0xb9,0x68,0x46,0xa6,0x3e,0x6c,0x19,0x36,0xfb,
0x9a,0xb4,0xbc,0xc1,0x22,0x47,0xc0,0x00,0x8a,0x44,0x1c,0xa7,0x44,0x2e,0x73,0x50,
0xfc,0xd2,0x91,0x9c,0xaa,0xc3,0xa3,0x88,0x8c,0x4b,0x33,0xef,0x9a,0x52,0x89,0x9c,
0x8e,0x01,0x62,0x21,0x7a,0x75,0x5e,0xa3,0x3b,0xc0,0xb0,0x58,0xc0,0xc0,0xce,0x77,
0xe0,0x84,0x9a,0x9e,0xc1,0x51,0x71,0xc7,0xc4,0xa0,0x1e,0xf0,0x8e,0xb3,0x90,0x3e,
0xcd,0xe3,0x7d,0x8e,0x11,0x7b,0x92,0x5d,0x4a,0x37,0x3b,0x4b,0xb3,0x3d,0x58,0x9a,
0x8b,0x51,0x39,0x15,0xcd,0x27,0xd4,0x5b,0xad,0x5e,0xa5,0x07,0x94,0x29,0x0f,0x02,
0x0c,0x61,0x85,0x97,0x3b,0xc4,0xcf,0x5d,0x17,0x86,0x4d,0x96,0x5e,0x42,0xe9,0xf2,
0x72,0x2f,0xd4,0x58,0x4d,0x02,0xf8,0x0f,0xbd,0xe7,0x37,0xc8,0xa9,0x87,0xfe,0xab,
0x26,0x37,0x13,0x90,0x65,0x2d,0x51,0x41,0x18,0x18,0xdf,0x48,0x21,0x87,0x70,0x61,
0xcb,0x1b,0x62,0xad,0xaf,0x65,0xd2,0x29,0x27,0x93,0x58,0x7b,0xea,0x89,0xdd,0x58,
0x01,0x6d,0xeb,0x60,0xd8,0xc3,0x82,0x07,0x2c,0x67,0x39,0xc3,0x68,0xfc,0xcd,0xeb,
0xe9,0x7c,0x67,0xe3,0x1b,0x7a,0x50,0xf9,0x36,0x68,0xea,0xe2,0x15,0x01,0xee,0x99,
0xf2,0x52,0xe0,0x0a,0x8e,0x5f,0x63,0xb1,0x61,0x7a,0x38,0x88,0x07,0xae,0xb0,0x8d,
0x44,0x26,0xe8,0xce,0x1b,0x6f,0xcd,0x05,0x4b,0x94,0x9d,0xee,0xb5,0xeb,0x28,0xc4,
0x93,0x47,0xfd,0x47,0x40,0x45,0x58,0xc0,0x3e,0x44,0x74,0x7b,0x78,0x8d,0xc8,0x25,
0xc1,0xe1,0x0a,0x43,0x02,0x03,0x01,0x00,0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,
0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x82,0x01,0x01,0x00,0x77,0xfd,0xd2,
0x68,0x7e,0xb9,0xc2,0x40,0xb4,0xa3,0xea,0xe8,0x15,0x55,0x18,0xfe,0xe3,0x80,0xe0,
0x73,0xf9,0xe1,0xe5,0xe2,0x91,0xf5,0xa7,0xcb,0xdf,0xfb,0xc1,0x36,0xa6,0x55,0x6a,
0xd9,0x27,0xcd,0xef,0x64,0x30,0x70,0xd8,0x4b,0x72,0x7c,0xd1,0x9c,0x32,0xf8,0xb4,
0x15,0x7f,0xd7,0x79,0x0c,0x9f,0x24,0xf8,0x50,0xea,0xc7,0xd9,0xef,0x1f,0xf1,0x76,
0x3c,0x19,0xdb,0x61,0xb7,0x35,0x97,0xf9,0x03,0x87,0x42,0x77,0x23,0xd8,0xfe,0xd1,
0x74,0xf2,0x1e,0x95,0x87,0x5f,0x42,0x80,0x8e,0xee,0x6c,0x19,0x7b,0x2c,0x25,0xe6,
0xf9,0xdb,0x24,0x35,0x94,0x65,0x44,0xa0,0x56,0x6f,0x7f,0x57,0x2e,0x1a,0xcd,0xa6,
0xed,0x7f,0x42,0xf2,0x64,0xd4,0xf9,0x3f,0xc1,0x46,0xf6,0xc8,0xb1,0xb2,0x80,0x75,
0x3e,0xd1,0xa8,0x5e,0x07,0xd0,0x3b,0x35,0x81,0x49,0x93,0x77,0xd2,0xcf,0xf7,0xb6,
0xd0,0xeb,0xe5,0xf3,0x2c,0x03,0x52,0xc7,0x6d,0x02,0x26,0xa6,0xdc,0x39,0xcd,0x4d,
0x9e,0xca,0x99,0x01,0x01,0x73,0xd6,0x55,0x89,0x93,0x12,0xa0,0xc5,0xe6,0xa7,0x9a,
0xdc,0x5f,0x9f,0x5c,0x2c,0x2b,0xdb,0x23,0xa5,0xee,0x69,0x15,0x1f,0x3a,0xf1,0x76,
0x36,0xb5,0x77,0x18,0x57,0xff,0xff,0xf7,0x45,0x59,0xce,0x1b,0x0b,0x56,0xcb,0x09,
0x00,0x12,0x17,0xb8,0xa2,0x81,0x86,0x70,0x29,0x63,0x99,0x76,0xff,0x18,0x80,0x2b,
0x9b,0x5e,0x04,0xb1,0xcc,0xe4,0x15,0x90,0x29,0xa6,0x40,0xdd,0x85,0x38,0xd7,0xfe,
0x10,0xb5,0x97,0x6e,0x62,0x60,0xb9,0x02,0x67,0xef,0xf1,0xab,0xb3,
};
/**
* Described in header.
*/
void test_certificate(protected_tester_t *tester)
{
chunk_t certificate = {certificate_buffer, sizeof(certificate_buffer)};
certificate_t *cert = certificate_create_from_chunk(certificate);
//certificate_t *cert = certificate_create_from_file("myCert.der");
cert->destroy(cert);
}
@@ -1,42 +0,0 @@
/**
* @file certificate_test.h
*
* @brief Tests for the certificate_t class.
*
*/
/*
* Copyright (C) 2006 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 CERTIFICATE_TEST_H_
#define CERTIFICATE_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the certificate_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_certificate(protected_tester_t *tester);
#endif /* CERTIFICATE_TEST_H_ */
-102
View File
@@ -1,102 +0,0 @@
/**
* @file child_sa_test.c
*
* @brief Tests for the child_sa_t class.
*
*/
/*
* 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 "child_sa_test.h"
#include <daemon.h>
#include <sa/child_sa.h>
#include <utils/allocator.h>
#include <utils/logger.h>
/**
* Described in header.
*/
void test_child_sa(protected_tester_t *tester)
{
proposal_t *proposal1, *proposal2;
linked_list_t *list;
host_t *local_me, *remote_me;
host_t *local_other, *remote_other;
child_sa_t *local_sa, *remote_sa;
prf_plus_t *local_prf_plus, *remote_prf_plus;
prf_t *local_prf, *remote_prf;
u_int8_t key_buffer[] = {0x01,0x02,0x03,0x04};
chunk_t key = {key_buffer, sizeof(key_buffer)};
status_t status;
/* setup test data */
local_me = host_create(AF_INET, "192.168.0.1", 0);
local_other = host_create(AF_INET, "192.168.0.2", 0);
remote_me = host_create(AF_INET, "192.168.0.3", 0);
remote_other = host_create(AF_INET, "192.168.0.4", 0);
local_sa = child_sa_create(local_me, local_other);
remote_sa = child_sa_create(remote_me, remote_other);
proposal1 = proposal_create(1);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
proposal2 = proposal_create(2);
proposal2->add_algorithm(proposal2, PROTO_AH, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
list = linked_list_create();
list->insert_last(list, proposal1);
list->insert_last(list, proposal2);
local_prf = prf_create(PRF_HMAC_SHA1);
remote_prf = prf_create(PRF_HMAC_SHA1);
local_prf->set_key(local_prf, key);
remote_prf->set_key(remote_prf, key);
local_prf_plus = prf_plus_create(local_prf, key);
remote_prf_plus = prf_plus_create(remote_prf, key);
/*
* local plays initiator
***********************
*/
status = local_sa->alloc(local_sa, list);
tester->assert_true(tester, status == SUCCESS, "spi allocation");
status = remote_sa->add(remote_sa, proposal1, remote_prf_plus);
tester->assert_true(tester, status == SUCCESS, "sa add");
status = local_sa->update(local_sa, proposal1, local_prf_plus);
tester->assert_true(tester, status == SUCCESS, "sa update");
/* cleanup */
proposal1->destroy(proposal1);
proposal2->destroy(proposal2);
list->destroy(list);
local_prf->destroy(local_prf);
local_prf_plus->destroy(local_prf_plus);
remote_prf->destroy(remote_prf);
remote_prf_plus->destroy(remote_prf_plus);
local_sa->destroy(local_sa);
remote_sa->destroy(remote_sa);
local_me->destroy(local_me);
local_other->destroy(local_other);
remote_me->destroy(remote_me);
remote_other->destroy(remote_other);
}
-42
View File
@@ -1,42 +0,0 @@
/**
* @file child_sa_test.h
*
* @brief Tests for the child_sa_t class.
*
*/
/*
* 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 CHILD_SA_TEST_H_
#define CHILD_SA_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the child_sa_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_child_sa(protected_tester_t *tester);
#endif /* CHILD_SA_TEST_H_ */
-83
View File
@@ -1,83 +0,0 @@
/**
* @file connection_test.c
*
* @brief Tests for the connection_t class.
*
*/
/*
* 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 "connection_test.h"
#include <config/connection.h>
#include <utils/allocator.h>
#include <transforms/prfs/prf.h>
/**
* Described in header.
*/
void test_connection(protected_tester_t *tester)
{
host_t *alice = host_create(AF_INET, "192.168.0.1", 500);
host_t *bob = host_create(AF_INET, "192.168.0.2", 500);
identification_t *alice_id = identification_create_from_string(AF_INET, "192.168.0.1");
identification_t *bob_id = identification_create_from_string(AF_INET, "192.168.0.2");
connection_t *connection = connection_create(alice, bob, alice_id, bob_id, RSA_DIGITAL_SIGNATURE);
proposal_t *prop1, *prop2, *prop3, *prop4;
linked_list_t *list;
prop1 = proposal_create(1);
prop1->add_algorithm(prop1, PROTO_IKE, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 20);
prop1->add_algorithm(prop1, PROTO_IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
prop1->add_algorithm(prop1, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 20);
prop1->add_algorithm(prop1, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
prop2 = proposal_create(2);
prop2->add_algorithm(prop2, PROTO_IKE, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 20);
prop2->add_algorithm(prop2, PROTO_IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
prop2->add_algorithm(prop2, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 20);
prop2->add_algorithm(prop2, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
prop3 = proposal_create(3);
prop3->add_algorithm(prop3, PROTO_IKE, ENCRYPTION_ALGORITHM, ENCR_DES, 20);
prop3->add_algorithm(prop3, PROTO_IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
prop3->add_algorithm(prop3, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_MD5, 20);
prop3->add_algorithm(prop3, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_768_BIT, 0);
prop4 = proposal_create(4);
prop4->add_algorithm(prop4, PROTO_IKE, ENCRYPTION_ALGORITHM, ENCR_3DES, 20);
prop4->add_algorithm(prop4, PROTO_IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
prop4->add_algorithm(prop4, PROTO_IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_TIGER, 20);
prop4->add_algorithm(prop4, PROTO_IKE, DIFFIE_HELLMAN_GROUP, MODP_768_BIT, 0);
connection->add_proposal(connection, prop1);
connection->add_proposal(connection, prop2);
connection->add_proposal(connection, prop3);
connection->add_proposal(connection, prop4);
list = connection->get_proposals(connection);
tester->assert_true(tester,(list->get_count(list) == 4), "proposal count check ");
/* going to check proposals */
/* TODO test?*/
list->destroy(list);
connection->destroy(connection);
}
-38
View File
@@ -1,38 +0,0 @@
/**
* @file connection_test.h
*
* @brief Tests for the connection_t class.
*
*/
/*
* 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 INIT_CONFIG_TEST_H_
#define INIT_CONFIG_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the connection_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_connection(protected_tester_t *tester);
#endif /* INIT_CONFIG_TEST_H_ */
-140
View File
@@ -1,140 +0,0 @@
/**
* @file der_decoder_test.c
*
* @brief Tests for the der_decoder_t class.
*
*/
/*
* Copyright (C) 2006 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 "der_decoder_test.h"
#include <daemon.h>
#include <asn1/der_decoder.h>
#include <utils/allocator.h>
#include <utils/logger.h>
static char private_key_buffer[] = {
0x30,0x82,0x04,0xa2,0x02,0x00,0x02,0x82,0x01,0x01,0x00,0x9b,0x28,0x10,0x02,0xd2,
0x43,0x5b,0x2b,0x7c,0x81,0xce,0x2b,0x77,0xb4,0xbf,0x5f,0x2a,0x9a,0x96,0xc9,0xa4,
0xd7,0xbb,0xb3,0xfb,0xc1,0x8a,0xad,0xbe,0x21,0x4e,0xd7,0x15,0xc4,0x8c,0x0a,0x88,
0x5b,0x02,0xa9,0xcd,0x2e,0xee,0xd3,0x5e,0xb9,0xfd,0x27,0x0b,0xdb,0xf6,0xe7,0xb7,
0x39,0xc1,0xfa,0x34,0x3f,0xa7,0xe4,0x04,0xaf,0xa8,0xc2,0x36,0x4e,0xf5,0x0c,0xf1,
0x9b,0x92,0x26,0x32,0x20,0xdb,0x04,0xf5,0xb8,0x2e,0xf5,0xfc,0x47,0xd3,0x2a,0xa1,
0x2d,0x5b,0x68,0x2c,0x5e,0xc6,0xc9,0x35,0x57,0x7b,0x65,0x17,0xd7,0x5d,0x10,0x5c,
0x51,0xfb,0xcb,0x95,0xd1,0x17,0x42,0xa9,0xfd,0xd1,0xc4,0x32,0x1f,0x13,0xf2,0xeb,
0x6b,0x91,0x01,0xe9,0x89,0x19,0x3a,0x2b,0x6d,0xae,0x91,0x27,0xe2,0x5e,0x06,0x5b,
0x99,0xfb,0x20,0x3c,0xc4,0x92,0x20,0xc4,0x68,0x24,0x6b,0x74,0xdc,0x6d,0xf7,0xa8,
0x10,0x1b,0xdf,0x20,0xed,0x4e,0x90,0x0e,0x3d,0xf6,0xef,0x3a,0x94,0x8b,0x12,0x61,
0xac,0xed,0x95,0xbc,0xe2,0xed,0xb9,0x22,0xc2,0xdd,0xc7,0x19,0x68,0x09,0x14,0x71,
0xb0,0x37,0xf7,0xbd,0x65,0x11,0x31,0x9d,0x89,0x6e,0x21,0xcf,0x60,0xc1,0x8d,0xbe,
0x31,0x96,0xd2,0xdd,0x0e,0x20,0x38,0x07,0xd5,0xea,0xda,0xc8,0x9a,0x47,0x5b,0x05,
0xce,0x7d,0xf7,0x4e,0xcd,0xbb,0x89,0xdd,0x46,0x16,0x8f,0x39,0x9d,0x32,0x19,0xaf,
0x6e,0xc4,0xb3,0x6c,0x79,0x5a,0x70,0x11,0x8f,0xe2,0x75,0x33,0x09,0xc8,0xf6,0xd7,
0x40,0x25,0xe7,0xa3,0xf0,0x6f,0x9a,0xdb,0x35,0x74,0xc1,0x02,0x03,0x01,0x00,0x01,
0x02,0x82,0x01,0x00,0x12,0x42,0x38,0x58,0x21,0xfc,0x51,0x34,0xa0,0x8b,0x4f,0x58,
0x28,0x2c,0x7a,0x14,0xd8,0x98,0xfb,0xee,0x5b,0x85,0x69,0x0e,0x63,0x83,0x16,0xd9,
0xc9,0x5f,0xcc,0x12,0x5d,0xa5,0x15,0x41,0xd6,0xb8,0x0c,0x6b,0xda,0x67,0x3a,0x83,
0x09,0xf3,0xb8,0x89,0xd4,0x1d,0xc7,0x99,0x8f,0x23,0x59,0xe3,0x78,0x2b,0x41,0x8b,
0xab,0x78,0x2c,0x7e,0x3b,0xbb,0xe0,0xf4,0x96,0xa8,0xd3,0x1d,0xc6,0xea,0x67,0x91,
0x2c,0x30,0x1c,0xe9,0x4f,0xb8,0xa2,0xc3,0x5d,0x2c,0xf9,0x99,0x1c,0x6c,0xee,0xd7,
0x16,0x28,0x3c,0x5a,0x32,0x35,0xb8,0x3a,0xf3,0xa7,0xa6,0x35,0x02,0xba,0xbf,0x67,
0xab,0x44,0xe1,0x09,0x9b,0x48,0x5d,0xa5,0x9e,0xf4,0xb7,0xf4,0xd1,0xfc,0x68,0x9e,
0x98,0x26,0x69,0x28,0xcc,0x19,0x75,0xf2,0x61,0x0e,0x23,0xeb,0xf9,0x6d,0x2c,0x2b,
0x01,0x3f,0x4d,0x18,0x41,0xc5,0x31,0x9d,0x1c,0x20,0x81,0x4e,0x38,0x92,0xd5,0xbb,
0xd7,0xe7,0x49,0x0c,0x3a,0xf3,0x8f,0x9e,0xf0,0xb3,0x32,0x1e,0xa7,0x77,0xe8,0x9c,
0xf3,0xce,0x88,0x66,0xcc,0xe8,0x16,0xbb,0xfd,0xbc,0x62,0xc7,0xc3,0xeb,0x0a,0xf5,
0xd8,0x53,0x02,0x6c,0x45,0xcb,0x1d,0xa3,0x96,0xfb,0xa5,0x26,0x18,0x7f,0x04,0x9f,
0x80,0x4a,0xdb,0x3b,0x74,0xcf,0x0d,0x45,0xf4,0xd5,0x49,0xe9,0x27,0x54,0x9c,0x57,
0x92,0x48,0x78,0x52,0xb6,0x40,0x89,0x3f,0xf3,0x95,0x06,0x3d,0x90,0xab,0xa0,0x8a,
0xc7,0x54,0xf1,0x63,0xcf,0xa6,0xd2,0x83,0x1e,0x69,0x54,0xe0,0x77,0x2c,0x9e,0x3a,
0x4f,0xdd,0x14,0x6d,0x02,0x81,0x81,0x00,0xd9,0x40,0x76,0x90,0x7c,0xe7,0x3b,0xa3,
0x59,0x23,0x14,0x6b,0xf3,0x5f,0x6e,0x6b,0x82,0x34,0xf6,0xbd,0x3e,0xfb,0x65,0xac,
0x2f,0x46,0xd5,0x6e,0x9b,0xb8,0x62,0x80,0xc3,0x0c,0xa9,0xa6,0x00,0xd6,0xb8,0x1c,
0x12,0x8d,0x4d,0xd0,0x64,0x29,0x4c,0xac,0x38,0xe8,0x6c,0xe4,0x82,0x02,0x4e,0x10,
0xd5,0x39,0x19,0x29,0x0c,0x58,0x3f,0x68,0xa0,0x11,0x0e,0x11,0x74,0x22,0x2b,0x7e,
0xc2,0xa7,0x88,0xe3,0x33,0xe8,0xb4,0x50,0x6e,0x0c,0x54,0xc5,0x3f,0xb7,0x16,0xcb,
0x39,0xed,0x23,0xd0,0x66,0x26,0x57,0xf9,0xcb,0xc9,0xac,0xe2,0xa4,0xb8,0xba,0xd8,
0xd2,0x1f,0x4a,0xed,0x73,0x89,0xda,0x42,0x27,0x5a,0x26,0x30,0x33,0xc8,0x42,0x2a,
0x3d,0xc5,0xf3,0xc2,0x29,0x3d,0x58,0x67,0x02,0x81,0x81,0x00,0xb6,0xd4,0x61,0x05,
0x49,0xcb,0xf4,0x29,0x8a,0x22,0xd3,0xa3,0x7c,0x9c,0xd2,0x07,0xa4,0x66,0xe4,0x36,
0xfa,0x5e,0xf6,0x64,0xb7,0x59,0x74,0x2f,0x36,0x6d,0x12,0xd0,0xc9,0x4d,0xf8,0xd1,
0xba,0xd1,0xee,0xd2,0x78,0xcd,0x51,0x69,0x33,0x6a,0x03,0xff,0xc2,0x35,0x1d,0x0d,
0x9c,0x0a,0x87,0x5e,0x09,0xa3,0x23,0x4c,0xab,0xc3,0x4c,0x4a,0x1c,0xa4,0xc5,0xe2,
0x70,0x42,0x1c,0xcf,0xea,0x79,0xfb,0xb9,0x87,0x67,0x4d,0xc3,0xfc,0xcc,0x86,0x9d,
0xfa,0xea,0x99,0xa5,0x1b,0xc1,0x96,0xf4,0x79,0x4d,0x66,0x12,0x8f,0x90,0x98,0xb4,
0xa1,0x3b,0xd6,0x2f,0x64,0xb4,0x5f,0x8f,0x47,0x7f,0x43,0xa5,0x6d,0xeb,0x06,0x58,
0xfb,0x04,0x9e,0xef,0xaf,0x88,0x35,0x88,0xa1,0x15,0x30,0x97,0x02,0x81,0x80,0x59,
0xbe,0xe0,0x7b,0xc5,0xad,0x3c,0x1c,0xb9,0x98,0xdd,0x39,0xce,0xfa,0xd0,0x41,0x87,
0x33,0x5b,0xee,0x47,0x93,0x50,0xa7,0xf5,0x8b,0xbc,0x65,0x89,0xdc,0x7c,0x8c,0x96,
0x86,0xa7,0x9a,0x54,0xe4,0x5e,0x7f,0xf2,0x45,0xff,0x2c,0x24,0x04,0x4f,0x91,0x21,
0x9d,0x1a,0x46,0xb7,0x52,0x3e,0x6f,0x83,0xb5,0xa7,0xa8,0x26,0x5a,0x5a,0x2f,0x5d,
0x58,0x4e,0x48,0x75,0x82,0x1c,0x17,0xac,0x4f,0xcb,0x23,0x98,0x70,0xfb,0xf3,0xf1,
0xd2,0x14,0x3e,0xbb,0x98,0x65,0xc9,0x24,0x2f,0xcb,0x48,0xae,0xba,0x0e,0x43,0xb9,
0xa4,0xa1,0x4f,0xab,0x1e,0x48,0xc9,0x82,0xdb,0xbc,0x77,0x24,0xf0,0x80,0x82,0x2d,
0x81,0x77,0x1f,0x18,0x75,0x14,0xa8,0x20,0x86,0xa2,0xb0,0xc5,0x9a,0x7a,0xe7,0x02,
0x81,0x80,0x1b,0x6d,0xb1,0x40,0x81,0xd9,0xbf,0x3f,0x9c,0x21,0xad,0x6e,0x91,0x7b,
0x55,0x67,0x20,0x1a,0xef,0x91,0xef,0xed,0xdf,0x39,0x2c,0xe8,0x96,0xad,0x9e,0x94,
0xae,0x85,0xf4,0x2d,0x66,0x6e,0xd0,0x80,0x3e,0x3c,0x05,0x33,0x88,0x4b,0x28,0x13,
0x77,0x96,0x1f,0x24,0xa8,0xbf,0x29,0xf1,0xca,0x6d,0x29,0x34,0xf8,0x4e,0xc0,0x56,
0x04,0x53,0xfa,0x08,0x1e,0x47,0xe2,0x5f,0x88,0xc3,0x08,0x82,0x54,0x69,0x79,0x0e,
0xde,0x73,0xd0,0xb1,0x3e,0x60,0xe5,0x0b,0xdd,0x11,0x10,0x20,0xf2,0xec,0xaa,0x66,
0x1a,0x32,0x1e,0xa7,0xaa,0xc1,0x2e,0x8f,0x33,0x8a,0xd8,0xa8,0xd6,0xcd,0x40,0x04,
0xaf,0xb9,0x59,0xcc,0x30,0x9f,0x98,0xc9,0x10,0xaf,0x14,0xbe,0x72,0x89,0x94,0xe1,
0x00,0xf1,0x02,0x81,0x81,0x00,0xd6,0xac,0x26,0xd2,0x42,0x5b,0x16,0xa9,0x39,0x02,
0x63,0x76,0xa4,0xf5,0x40,0x3a,0xde,0xfa,0xea,0xd8,0xd3,0x12,0xee,0x44,0x00,0xfe,
0xcb,0xa1,0x78,0x18,0xaa,0xa7,0x08,0xea,0x5e,0x36,0x52,0x28,0x0d,0x02,0x5a,0x9e,
0x2d,0xc1,0x22,0x29,0x08,0x4f,0xed,0xff,0xa9,0xa6,0x08,0x8d,0x77,0xa4,0x5c,0xae,
0xa7,0x8a,0x19,0x90,0xc2,0x12,0xc8,0x0f,0xb8,0x24,0xb5,0xba,0x45,0x2f,0xa6,0xc2,
0x10,0x4c,0x0d,0x7e,0xf2,0xfd,0x11,0x26,0x16,0x34,0xbe,0x08,0x25,0x41,0x8b,0xcc,
0x60,0xe7,0x02,0x3e,0x6a,0x54,0x05,0x80,0x66,0x2d,0x55,0x06,0xe6,0xbe,0x9b,0x15,
0x9d,0xd3,0x5d,0xc4,0x6b,0x3f,0x74,0xa6,0x24,0xbc,0x7f,0x13,0xdf,0xe3,0x51,0x86,
0x64,0x0f,0x1d,0x1f,0xf2,0x1e,
};
asn1_rule_t private_key_rules[] = {
{ASN1_SEQUENCE, 0, 0, 0},
{ ASN1_INTEGER, 0, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ ASN1_INTEGER, ASN1_MPZ, 0, 0},
{ASN1_END, 0, 0, 0},
};
/**
* Described in header.
*/
void test_der_decoder(protected_tester_t *tester)
{
chunk_t private_key = {private_key_buffer, sizeof(private_key_buffer)};
der_decoder_t *dd = der_decoder_create(private_key_rules);
dd->decode(dd, private_key, NULL);
dd->destroy(dd);
}
@@ -1,42 +0,0 @@
/**
* @file der_decoder_test.h
*
* @brief Tests for the der_decoder_t class.
*
*/
/*
* Copyright (C) 2006 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 DER_DECODER_TEST_H_
#define DER_DECODER_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the der_decoder_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_der_decoder(protected_tester_t *tester);
#endif /* DER_DECODER_TEST_H_ */
@@ -1,76 +0,0 @@
/**
* @file diffie_hellman_test.c
*
* @brief Tests for the diffie_hellman_t class.
*
*/
/*
* 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 "diffie_hellman_test.h"
#include "../transforms/diffie_hellman.h"
#include <daemon.h>
#include <utils/logger_manager.h>
#include <utils/allocator.h>
#include <encoding/payloads/transform_substructure.h>
/*
* described in Header-File
*/
void test_diffie_hellman(protected_tester_t *tester)
{
diffie_hellman_t *my_diffie_hellman, *other_diffie_hellman;
logger_t *logger;
chunk_t my_public_value, other_public_value;
chunk_t my_secret, other_secret;
logger = charon->logger_manager->get_logger(charon->logger_manager,TESTER);
my_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
tester->assert_true(tester,(my_diffie_hellman != NULL), "create call check");
other_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
tester->assert_true(tester,(other_diffie_hellman != NULL), "create call check");
my_diffie_hellman->get_my_public_value(my_diffie_hellman,&my_public_value);
logger->log_chunk(logger,RAW,"My public value",my_public_value);
other_diffie_hellman->get_my_public_value(other_diffie_hellman,&other_public_value);
logger->log_chunk(logger,RAW,"Other public value",other_public_value);
my_diffie_hellman->set_other_public_value(my_diffie_hellman,other_public_value);
other_diffie_hellman->set_other_public_value(other_diffie_hellman,my_public_value);
allocator_free(my_public_value.ptr);
allocator_free(other_public_value.ptr);
tester->assert_true(tester,(my_diffie_hellman->get_shared_secret(my_diffie_hellman,&my_secret) == SUCCESS), "get_shared_secret call check");
logger->log_chunk(logger,RAW,"My shared secret",my_secret);
tester->assert_true(tester,(other_diffie_hellman->get_shared_secret(other_diffie_hellman,&other_secret) == SUCCESS), "get_shared_secret call check");
logger->log_chunk(logger,RAW,"Other shared secret",other_secret);
tester->assert_true(tester,(memcmp(my_secret.ptr,other_secret.ptr,other_secret.len) == 0), "shared secret same value check");
allocator_free(my_secret.ptr);
allocator_free(other_secret.ptr);
my_diffie_hellman->destroy(my_diffie_hellman);
other_diffie_hellman->destroy(other_diffie_hellman);
}
@@ -1,37 +0,0 @@
/**
* @file diffie_hellman_test.h
*
* @brief Tests for the diffie_hellman_t class.
*
*/
/*
* 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 DIFFIE_HELLMAN_TEST_H_
#define DIFFIE_HELLMAN_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the diffie_hellman_t functionality.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_diffie_hellman(protected_tester_t *tester);
#endif /*DIFFIE_HELLMAN_TEST_H_*/
@@ -1,138 +0,0 @@
/**
* @file encryption_payload_test.c
*
* @brief Tests for the encryption_payload_t class.
*
*/
/*
* 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 "encryption_payload_test.h"
#include <daemon.h>
#include <utils/logger_manager.h>
#include <utils/allocator.h>
#include <encoding/generator.h>
#include <encoding/parser.h>
#include <encoding/payloads/encryption_payload.h>
#include <encoding/payloads/nonce_payload.h>
#include <transforms/crypters/crypter.h>
#include <transforms/signers/signer.h>
/*
* described in Header-File
*/
void test_encryption_payload(protected_tester_t *tester)
{
encryption_payload_t *encryption_payload;
nonce_payload_t *nonce_payload;
crypter_t *crypter;
signer_t *signer;
chunk_t nonce, got_nonce;
chunk_t data;
chunk_t key;
generator_t *generator;
parser_t *parser;
status_t status;
logger_t *logger;
iterator_t *iterator;
u_int8_t key_bytes[] = {
0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01
};
key.ptr = key_bytes;
key.len = sizeof(key_bytes);
logger = charon->logger_manager->get_logger(charon->logger_manager, TESTER);
nonce.ptr = "test text und so...";
nonce.len = strlen(nonce.ptr) +1;
logger->log_chunk(logger, RAW, "nonce", nonce);
encryption_payload = encryption_payload_create();
nonce_payload = nonce_payload_create();
nonce_payload->set_nonce(nonce_payload, nonce);
encryption_payload->add_payload(encryption_payload, (payload_t*)nonce_payload);
signer = signer_create(AUTH_HMAC_SHA1_96);
crypter = crypter_create(ENCR_AES_CBC, 16);
signer->set_key(signer, key);
crypter->set_key(crypter, key);
/* generating */
encryption_payload->set_transforms(encryption_payload, crypter, signer);
logger->log(logger, RAW, "encrypt");
status = encryption_payload->encrypt(encryption_payload);
tester->assert_true(tester, (status == SUCCESS), "encryption");
generator = generator_create();
generator->generate_payload(generator, (payload_t*)encryption_payload);
generator->write_to_chunk(generator, &data);
logger->log_chunk(logger, RAW, "generated data", data);
encryption_payload->build_signature(encryption_payload, data);
logger->log_chunk(logger, RAW, "generated data", data);
encryption_payload->destroy(encryption_payload);
/* parsing */
parser = parser_create(data);
status = parser->parse_payload(parser, ENCRYPTED, (payload_t**)&encryption_payload);
tester->assert_true(tester, (status == SUCCESS), "parsing");
encryption_payload->set_transforms(encryption_payload, crypter, signer);
status = encryption_payload->verify_signature(encryption_payload, data);
tester->assert_true(tester, (status == SUCCESS), "signature verification");
status = encryption_payload->decrypt(encryption_payload);
tester->assert_true(tester, (status == SUCCESS), "decryption");
iterator = encryption_payload->create_payload_iterator(encryption_payload, TRUE);
while (iterator->has_next(iterator))
{
iterator->current(iterator, (void**)&nonce_payload);
got_nonce = nonce_payload->get_nonce(nonce_payload);
}
iterator->destroy(iterator);
tester->assert_true(tester, (got_nonce.len == nonce.len), "decrypted nonce");
tester->assert_false(tester, memcmp(nonce.ptr, got_nonce.ptr, nonce.len), "decrypted nonce");
logger->log_chunk(logger, RAW, "nonce", got_nonce);
allocator_free(data.ptr);
allocator_free(got_nonce.ptr);
encryption_payload->destroy(encryption_payload);
crypter->destroy(crypter);
signer->destroy(signer);
generator->destroy(generator);
parser->destroy(parser);
}
@@ -1,37 +0,0 @@
/**
* @file encryption_payload_test.h
*
* @brief Tests for the encryption_payload_t class.
*
*/
/*
* 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 ENCRYPTION_PAYLOAD_TEST_H_
#define ENCRYPTION_PAYLOAD_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the encryption_payload_t functionality.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_encryption_payload(protected_tester_t *tester);
#endif /*ENCRYPTION_PAYLOAD_TEST_H_*/
-144
View File
@@ -1,144 +0,0 @@
/**
* @file event_queue_test.h
*
* @brief Tests for the event_queue_t class.
*
*/
/*
* 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 <stdlib.h>
#include <pthread.h>
#include "event_queue_test.h"
#include <utils/allocator.h>
#include <queues/event_queue.h>
#include <queues/jobs/initiate_ike_sa_job.h>
/**
* Number of different times to insert per thread
*/
#define EVENT_QUEUE_TIMES 5
/**
* Number of entries per time per thread
*/
#define EVENT_QUEUE_ENTRY_PER_TIME 20
/**
* Number of test-thread
*/
#define EVENT_QUEUE_INSERT_THREADS 1
/**
* @brief Informations for the involved test-thread used in this test
*
*/
typedef struct event_queue_test_s event_queue_test_t;
struct event_queue_test_s{
protected_tester_t *tester;
event_queue_t *event_queue;
/**
* number of different event times to be inserted in the event-queue by each thread
*/
int insert_times_count;
/**
* number of event to insert at one time
*/
int entries_per_time;
};
static void event_queue_insert_thread(event_queue_test_t * testinfos)
{
timeval_t current_time;
timeval_t time;
job_t * job;
int i,j;
connection_t *connection;
gettimeofday(&current_time,NULL);
for (i = 0; i < testinfos->insert_times_count;i++)
{
for (j = 0; j < testinfos->entries_per_time;j++)
{
job = (job_t *) initiate_ike_sa_job_create(connection);
time.tv_usec = 0;
time.tv_sec = current_time.tv_sec + i;
testinfos->event_queue->add_absolute(testinfos->event_queue,job,time);
}
}
}
void test_event_queue(protected_tester_t *tester)
{
event_queue_t * event_queue = event_queue_create();
event_queue_test_t testinfos;
pthread_t threads[EVENT_QUEUE_INSERT_THREADS];
int i,j, number_of_total_events;
timeval_t current_time, start_time;
testinfos.tester = tester;
testinfos.event_queue = event_queue;
testinfos.insert_times_count = EVENT_QUEUE_TIMES;
testinfos.entries_per_time = EVENT_QUEUE_ENTRY_PER_TIME;
number_of_total_events = EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_TIMES * EVENT_QUEUE_INSERT_THREADS;
gettimeofday(&start_time,NULL);
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
int retval;
retval = pthread_create( &(threads[i]), NULL,(void*(*)(void*)) &event_queue_insert_thread, (void*) &testinfos);
tester->assert_true(tester,(retval== 0), "thread creation call check");
}
/* wait for all threads */
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
int retval;
retval = pthread_join(threads[i], NULL);
tester->assert_true(tester,(retval== 0), "thread creation call check");
}
tester->assert_true(tester,(event_queue->get_count(event_queue) == number_of_total_events), "event count check");
for (i = 0; i < EVENT_QUEUE_TIMES;i++)
{
for (j = 0; j < (EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_INSERT_THREADS);j++)
{
job_t *job;
job = event_queue->get(event_queue);
gettimeofday(&current_time,NULL);
tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
job->destroy(job);
}
}
event_queue->destroy(event_queue);
return;
}
@@ -1,39 +0,0 @@
/**
* @file event_queue_test.h
*
* @brief Tests to test the Event-Queue type event_queue_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 EVENT_QUEUE_TEST_H_
#define EVENT_QUEUE_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the event_queue functionality.
*
* Tests are performed using one thread.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_event_queue(protected_tester_t *tester);
#endif /*EVENT_QUEUE_TEST_H_*/
File diff suppressed because it is too large Load Diff
-183
View File
@@ -1,183 +0,0 @@
/**
* @file generator_test.h
*
* @brief Tests for the generator_t class.
*
*/
/*
* 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 GENERATOR_TEST_H_
#define GENERATOR_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the generator with header payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_header_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with transform attribute payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_transform_attribute(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with transform substructure payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_transform_substructure(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with proposal substructure payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_proposal_substructure(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with SA payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_sa_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with KE payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_ke_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with Notify payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_notify_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with Nonce payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_nonce_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with ID payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_id_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with AUTH payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_auth_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with TS payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_ts_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with CERT payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_cert_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with CERTREQ payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_certreq_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with DELETE payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_delete_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with VENDOR ID payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_vendor_id_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with CP payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_cp_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the generator with EAP payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_generator_with_eap_payload(protected_tester_t *tester);
#endif /*GENERATOR_TEST_H_*/
-172
View File
@@ -1,172 +0,0 @@
/**
* @file hasher_test.h
*
* @brief Tests for the hasher_t classes.
*
*/
/*
* 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 <string.h>
#include "hasher_test.h"
#include <utils/allocator.h>
/*
* described in Header-File
*/
void test_md5_hasher(protected_tester_t *tester)
{
/*
* Test vectors from RFC1321:
* MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
* MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
* MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
* MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
* MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
*
* currently testing "", "abc", "abcdefghijklmnopqrstuvwxyz"
*/
hasher_t *hasher = hasher_create(HASH_MD5);
u_int8_t hash_buffer[16];
chunk_t empty, abc, abcd, hash_chunk;
u_int8_t hash_empty[] = {
0xd4,0x1d,0x8c,0xd9,
0x8f,0x00,0xb2,0x04,
0xe9,0x80,0x09,0x98,
0xec,0xf8,0x42,0x7e
};
u_int8_t hash_abc[] = {
0x90,0x01,0x50,0x98,
0x3c,0xd2,0x4f,0xb0,
0xd6,0x96,0x3f,0x7d,
0x28,0xe1,0x7f,0x72
};
u_int8_t hash_abcd[] = {
0xc3,0xfc,0xd3,0xd7,
0x61,0x92,0xe4,0x00,
0x7d,0xfb,0x49,0x6c,
0xca,0x67,0xe1,0x3b
};
empty.ptr = "";
empty.len = 0;
abc.ptr = "abc";
abc.len = 3;
abcd.ptr = "abcdefghijklmnopqrstuvwxyz";
abcd.len = strlen(abcd.ptr);
tester->assert_true(tester, hasher->get_block_size(hasher) == 16, "block size");
/* simple hashing, using empty */
hasher->get_hash(hasher, empty, hash_buffer);
tester->assert_false(tester, memcmp(hash_buffer, hash_empty, 16), "hash for empty");
/* simple hashing, using "abc" */
hasher->get_hash(hasher, abc, hash_buffer);
tester->assert_false(tester, memcmp(hash_buffer, hash_abc, 16), "hash for abc");
/* with allocation, using "abcdb..." */
hasher->reset(hasher);
hasher->allocate_hash(hasher, abcd, &hash_chunk);
tester->assert_true(tester, hash_chunk.len == 16, "hash len");
tester->assert_false(tester, memcmp(hash_chunk.ptr, hash_abcd, hash_chunk.len), "hash for abcd...");
allocator_free(hash_chunk.ptr);
hasher->destroy(hasher);
}
/*
* described in Header-File
*/
void test_sha1_hasher(protected_tester_t *tester)
{
/*
* Test Vectors (from FIPS PUB 180-1)
* "abc"
* A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
* "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
* 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
* A million repetitions of "a"
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
hasher_t *hasher = hasher_create(HASH_SHA1);
u_int8_t hash_buffer[20];
chunk_t abc, abcdb, aaa, hash_chunk;
u_int32_t i;
u_int8_t hash_abc[] = {
0xA9,0x99,0x3E,0x36,
0x47,0x06,0x81,0x6A,
0xBA,0x3E,0x25,0x71,
0x78,0x50,0xC2,0x6C,
0x9C,0xD0,0xD8,0x9D
};
u_int8_t hash_abcdb[] = {
0x84,0x98,0x3E,0x44,
0x1C,0x3B,0xD2,0x6E,
0xBA,0xAE,0x4A,0xA1,
0xF9,0x51,0x29,0xE5,
0xE5,0x46,0x70,0xF1
};
u_int8_t hash_aaa[] = {
0x34,0xAA,0x97,0x3C,
0xD4,0xC4,0xDA,0xA4,
0xF6,0x1E,0xEB,0x2B,
0xDB,0xAD,0x27,0x31,
0x65,0x34,0x01,0x6F
};
abc.ptr = "abc";
abc.len = 3;
abcdb.ptr = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
abcdb.len = strlen(abcdb.ptr);
aaa.ptr = "aaaaaaaaaa"; /* 10 a's */
aaa.len = 10;
tester->assert_true(tester, hasher->get_block_size(hasher) == 20, "block size");
/* simple hashing, using "abc" */
hasher->get_hash(hasher, abc, hash_buffer);
tester->assert_false(tester, memcmp(hash_buffer, hash_abc, 20), "hash for abc");
/* with allocation, using "abcdb..." */
hasher->reset(hasher);
hasher->allocate_hash(hasher, abcdb, &hash_chunk);
tester->assert_true(tester, hash_chunk.len == 20, "chunk len");
tester->assert_false(tester, memcmp(hash_chunk.ptr, hash_abcdb, hash_chunk.len), "hash for abcdb...");
allocator_free(hash_chunk.ptr);
/* updating, using "aaaaaaa..." */
hasher->reset(hasher);
for(i=0; i<100000; i++)
{
if (i != 99999)
{
hasher->get_hash(hasher, aaa, NULL);
}
else
{
hasher->get_hash(hasher, aaa, hash_buffer);
}
}
tester->assert_false(tester, memcmp(hash_buffer, hash_aaa, 20), "hash for aaa...");
hasher->destroy(hasher);
}
-49
View File
@@ -1,49 +0,0 @@
/**
* @file hasher_test.h
*
* @brief Tests for the hasher_t classes.
*
*/
/*
* 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 HASHER_TEST_H_
#define HASHER_TEST_H_
#include <transforms/hashers/hasher.h>
#include <transforms/hashers/md5_hasher.h>
#include <transforms/hashers/sha1_hasher.h>
#include <utils/tester.h>
/**
* @brief Test function used to test the SHA1-hasher functionality.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_sha1_hasher(protected_tester_t *tester);
/**
* @brief Test function used to test the Md5-hasher functionality.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_md5_hasher(protected_tester_t *tester);
#endif /*HASHER_TEST_H_*/
-204
View File
@@ -1,204 +0,0 @@
/**
* @file hmac_signer_test.c
*
* @brief Tests for the hmac_signer_t class.
*
*/
/*
* 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 <string.h>
#include "hmac_signer_test.h"
#include <transforms/signers/signer.h>
#include <utils/allocator.h>
#include <daemon.h>
/*
* Described in header.
*/
void test_hmac_md5_signer(protected_tester_t *tester)
{
/* Test cases from RFC2202
*
* test_case = 5
* key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
* key_len = 16
* data = "Test With Truncation"
* data_len = 20
* digest = 0x56461ef2342edc00f9bab995690efd4c
* digest-96 0x56461ef2342edc00f9bab995
*
* currently only this test 5 gets performed!
*/
chunk_t keys[4];
chunk_t data[4];
chunk_t signature[4];
chunk_t reference[4];
chunk_t wrong_reference[4];
int i;
logger_t *logger;
bool valid;
logger = charon->logger_manager->get_logger(charon->logger_manager, TESTER);
signer_t *signer = (signer_t *) signer_create(AUTH_HMAC_MD5_96);
tester->assert_true(tester, (signer != NULL), "signer create call check");
/*
* values for test 5
*/
u_int8_t key1[] = {
0x0c,0x0c,0x0c,0x0c,
0x0c,0x0c,0x0c,0x0c,
0x0c,0x0c,0x0c,0x0c,
0x0c,0x0c,0x0c,0x0c,
};
keys[0].ptr = key1;
keys[0].len = sizeof(key1);
data[0].ptr = "Test With Truncation";
data[0].len = 20;
u_int8_t reference1[] = {
0x56,0x46,0x1e,0xf2,0x34,0x2e,
0xdc,0x00,0xf9,0xba,0xb9,0x95
};
reference[0].ptr = reference1;
reference[0].len = sizeof(reference1);
u_int8_t wrong_reference1[] = {
0x56,0x46,0x1e,0xa2,0x34,0x2e,
0xdc,0x00,0xf9,0xba,0xb9,0x95
};
wrong_reference[0].ptr = wrong_reference1;
wrong_reference[0].len = sizeof(wrong_reference1);
for (i=0; i<1; i++)
{
signer->set_key(signer, keys[i]);
signer->allocate_signature(signer, data[i], &signature[i]);
tester->assert_true(tester, signature[i].len == 12, "chunk len");
tester->assert_true(tester, (memcmp(signature[i].ptr, reference[i].ptr, 12) == 0), "hmac value");
logger->log_chunk(logger,RAW,"expected signature:",reference[i]);
logger->log_chunk(logger,RAW,"signature:",signature[i]);
allocator_free(signature[i].ptr);
valid = signer->verify_signature(signer, data[i],reference[i]);
tester->assert_true(tester, (valid == TRUE), "Signature valid check");
valid = signer->verify_signature(signer, data[i],wrong_reference[i]);
tester->assert_true(tester, (valid == FALSE), "Signature not valid check");
}
signer->destroy(signer);
}
/*
* Described in header.
*/
void test_hmac_sha1_signer(protected_tester_t *tester)
{
/*
* test_case = 7
* key = 0xaa repeated 80 times
* key_len = 80
* data = "Test Using Larger Than Block-Size Key and Larger
* Than One Block-Size Data"
* data_len = 73
* digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04
* digest-96 = 0x4c1a03424b55e07fe7f27be1
*/
chunk_t keys[4];
chunk_t data[4];
chunk_t signature[4];
chunk_t reference[4];
chunk_t wrong_reference[4];
int i;
logger_t *logger;
bool valid;
logger = charon->logger_manager->get_logger(charon->logger_manager, TESTER);
signer_t *signer = (signer_t *) signer_create(AUTH_HMAC_SHA1_96);
tester->assert_true(tester, (signer != NULL), "signer create call check");
/*
* values for test 5
*/
u_int8_t key1[] = {
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,
};
keys[0].ptr = key1;
keys[0].len = sizeof(key1);
data[0].ptr = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
data[0].len = 73;
u_int8_t reference1[] = {
0xe8,0xe9,0x9d,0x0f,0x45,0x23,
0x7d,0x78,0x6d,0x6b,0xba,0xa7
};
reference[0].ptr = reference1;
reference[0].len = sizeof(reference1);
u_int8_t wrong_reference1[] = {
0xe8,0xe9,0x9d,0x0f,0x46,0x23,
0x7d,0x71,0x6d,0x6b,0xba,0xa7
};
wrong_reference[0].ptr = wrong_reference1;
wrong_reference[0].len = sizeof(wrong_reference1);
for (i=0; i<1; i++)
{
signer->set_key(signer, keys[i]);
signer->allocate_signature(signer, data[i], &signature[i]);
tester->assert_true(tester, signature[i].len == 12, "chunk len");
tester->assert_true(tester, (memcmp(signature[i].ptr, reference[i].ptr, 12) == 0), "hmac value");
logger->log_chunk(logger,RAW,"expected signature:",reference[i]);
logger->log_chunk(logger,RAW,"signature:",signature[i]);
allocator_free(signature[i].ptr);
valid = signer->verify_signature(signer, data[i],reference[i]);
tester->assert_true(tester, (valid == TRUE), "Signature valid check");
valid = signer->verify_signature(signer, data[i],wrong_reference[i]);
tester->assert_true(tester, (valid == FALSE), "Signature not valid check");
}
signer->destroy(signer);
}
@@ -1,46 +0,0 @@
/**
* @file hmac_signer_test.h
*
* @brief Tests for the hmac_signer_t class.
*
*/
/*
* 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 HMAC_SIGNER_TEST_H_
#define HMAC_SIGNER_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the hmac sign functionality using MD5.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_hmac_md5_signer(protected_tester_t *tester);
/**
* @brief Test function used to test the hmac sign functionality using SHA1.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_hmac_sha1_signer(protected_tester_t *tester);
#endif /* HMAC_SIGNER_TEST_H_ */
-409
View File
@@ -1,409 +0,0 @@
/**
* @file hmac_test.h
*
* @brief Tests for the hmac_t class.
*
*/
/*
* 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 <string.h>
#include "hmac_test.h"
#include <transforms/hmac.h>
#include <utils/allocator.h>
/*
* described in Header-File
*/
void test_hmac_sha1(protected_tester_t *tester)
{
/*
* Test cases from RFC2202
*
* test_case = 1
* key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
* key_len = 20
* data = "Hi There"
* data_len = 8
* digest = 0xb617318655057264e28bc0b6fb378c8ef146be00
*
* test_case = 2
* key = "Jefe"
* key_len = 4
* data = "what do ya want for nothing?"
* data_len = 28
* digest = 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79
*
* test_case = 3
* key = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* key_len = 20
* data = 0xdd repeated 50 times
* data_len = 50
* digest = 0x125d7342b9ac11cd91a39af48aa17b4f63f175d3
*
* test_case = 4
* key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819
* key_len = 25
* data = 0xcd repeated 50 times
* data_len = 50
* digest = 0x4c9007f4026250c6bc8414f9bf50c86c2d7235da
*
* test_case = 5
* key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
* key_len = 20
* data = "Test With Truncation"
* data_len = 20
* digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04
* digest-96 = 0x4c1a03424b55e07fe7f27be1
*
* test_case = 6
* key = 0xaa repeated 80 times
* key_len = 80
* data = "Test Using Larger Than Block-Size Key - Hash Key First"
* data_len = 54
* digest = 0xaa4ae5e15272d00e95705637ce8a3b55ed402112
*
* test_case = 7
* key = 0xaa repeated 80 times
* key_len = 80
* data = "Test Using Larger Than Block-Size Key and Larger
* Than One Block-Size Data"
* data_len = 73
* digest = 0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91
*
* currently performing test 1, 2, 4 and 7
*/
chunk_t keys[4];
chunk_t data[4];
chunk_t digest[4];
chunk_t reference[4];
int i;
/*
* values for test 1
*/
u_int8_t key1[] = {
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b
};
keys[0].ptr = key1;
keys[0].len = sizeof(key1);
data[0].ptr = "Hi There";
data[0].len = 8;
u_int8_t reference1[] = {
0xb6,0x17,0x31,0x86,
0x55,0x05,0x72,0x64,
0xe2,0x8b,0xc0,0xb6,
0xfb,0x37,0x8c,0x8e,
0xf1,0x46,0xbe,0x00
};
reference[0].ptr = reference1;
reference[0].len = sizeof(reference1);
/*
* values for test 2
*/
u_int8_t reference2[] = {
0xef,0xfc,0xdf,0x6a,
0xe5,0xeb,0x2f,0xa2,
0xd2,0x74,0x16,0xd5,
0xf1,0x84,0xdf,0x9c,
0x25,0x9a,0x7c,0x79
};
keys[1].ptr = "Jefe";
keys[1].len = 4;
data[1].ptr = "what do ya want for nothing?";
data[1].len = 28;
reference[1].ptr = reference2;
reference[1].len = sizeof(reference2);
/*
* values for test 7
*/
u_int8_t key7[] = {
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
};
u_int8_t reference7[] = {
0xe8,0xe9,0x9d,0x0f,
0x45,0x23,0x7d,0x78,
0x6d,0x6b,0xba,0xa7,
0x96,0x5c,0x78,0x08,
0xbb,0xff,0x1a,0x91
};
keys[2].ptr = key7;
keys[2].len = sizeof(key7);
data[2].ptr = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
data[2].len = 73;
reference[2].ptr = reference7;
reference[2].len = sizeof(reference7);
for (i=0; i<3; i++)
{
hmac_t *hmac = hmac_create(HASH_SHA1);
hmac->set_key(hmac, keys[i]);
hmac->allocate_mac(hmac, data[i], &digest[i]);
hmac->destroy(hmac);
tester->assert_true(tester, digest[i].len == 20, "chunk len");
tester->assert_false(tester, memcmp(digest[i].ptr, reference[i].ptr, 20), "hmac value");
allocator_free(digest[i].ptr);
}
/*
* test 4 is donne in append mode
*/
u_int8_t val = 0xcd;
u_int8_t key4[] = {
0x01,0x02,0x03,0x04,
0x05,0x06,0x07,0x08,
0x09,0x0a,0x0b,0x0c,
0x0d,0x0e,0x0f,0x10,
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19
};
keys[3].ptr = key4;
keys[3].len = sizeof(key4);
u_int8_t reference4[] = {
0x4c,0x90,0x07,0xf4,
0x02,0x62,0x50,0xc6,
0xbc,0x84,0x14,0xf9,
0xbf,0x50,0xc8,0x6c,
0x2d,0x72,0x35,0xda
};
reference[3].ptr = reference4;
reference[3].len = sizeof(reference4);
hmac_t *hmac = hmac_create(HASH_SHA1);
hmac->set_key(hmac, keys[3]);
data[3].ptr = &val;
data[3].len = 1;
for (i=0; i<49; i++)
{
hmac->get_mac(hmac, data[3], NULL);
}
hmac->allocate_mac(hmac, data[3], &digest[3]);
hmac->destroy(hmac);
tester->assert_true(tester, digest[3].len == 20, "chunk len append mode");
tester->assert_false(tester, memcmp(digest[3].ptr, reference[3].ptr, 20), "hmac value append mode");
allocator_free(digest[3].ptr);
}
/*
* described in Header-File
*/
void test_hmac_md5(protected_tester_t *tester)
{
/*
* Test cases from RFC2202
*
* test_case = 1
* key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
* key_len = 16
* data = "Hi There"
* data_len = 8
* digest = 0x9294727a3638bb1c13f48ef8158bfc9d
*
* test_case = 2
* key = "Jefe"
* key_len = 4
* data = "what do ya want for nothing?"
* data_len = 28
* digest = 0x750c783e6ab0b503eaa86e310a5db738
*
* test_case = 3
* key = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* key_len 16
* data = 0xdd repeated 50 times
* data_len = 50
* digest = 0x56be34521d144c88dbb8c733f0e8b3f6
*
* test_case = 4
* key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819
* key_len 25
* data = 0xcd repeated 50 times
* data_len = 50
* digest = 0x697eaf0aca3a3aea3a75164746ffaa79
*
* test_case = 5
* key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
* key_len = 16
* data = "Test With Truncation"
* data_len = 20
* digest = 0x56461ef2342edc00f9bab995690efd4c
* digest-96 0x56461ef2342edc00f9bab995
*
* test_case = 6
* key = 0xaa repeated 80 times
* key_len = 80
* data = "Test Using Larger Than Block-Size Key - Hash Key First"
* data_len = 54
* digest = 0x6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd
*
* test_case = 7
* key = 0xaa repeated 80 times
* key_len = 80
* data = "Test Using Larger Than Block-Size Key and Larger
* Than One Block-Size Data"
* data_len = 73
* digest = 0x6f630fad67cda0ee1fb1f562db3aa53e
*
*
*
* currently performing test 1, 2, 4 and 7
*
*/
chunk_t keys[4];
chunk_t data[4];
chunk_t digest[4];
chunk_t reference[4];
int i;
/*
* values for test 1
*/
u_int8_t key1[] = {
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,
};
keys[0].ptr = key1;
keys[0].len = sizeof(key1);
data[0].ptr = "Hi There";
data[0].len = 8;
u_int8_t reference1[] = {
0x92,0x94,0x72,0x7a,
0x36,0x38,0xbb,0x1c,
0x13,0xf4,0x8e,0xf8,
0x15,0x8b,0xfc,0x9d
};
reference[0].ptr = reference1;
reference[0].len = sizeof(reference1);
/*
* values for test 2
*/
u_int8_t reference2[] = {
0x75,0x0c,0x78,0x3e,
0x6a,0xb0,0xb5,0x03,
0xea,0xa8,0x6e,0x31,
0x0a,0x5d,0xb7,0x38
};
keys[1].ptr = "Jefe";
keys[1].len = 4;
data[1].ptr = "what do ya want for nothing?";
data[1].len = 28;
reference[1].ptr = reference2;
reference[1].len = sizeof(reference2);
/*
* values for test 7
*/
u_int8_t key7[] = {
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
};
u_int8_t reference7[] = {
0x6f,0x63,0x0f,0xad,
0x67,0xcd,0xa0,0xee,
0x1f,0xb1,0xf5,0x62,
0xdb,0x3a,0xa5,0x3e
};
keys[2].ptr = key7;
keys[2].len = sizeof(key7);
data[2].ptr = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
data[2].len = 73;
reference[2].ptr = reference7;
reference[2].len = sizeof(reference7);
for (i=0; i<3; i++)
{
hmac_t *hmac = hmac_create(HASH_MD5);
hmac->set_key(hmac, keys[i]);
hmac->allocate_mac(hmac, data[i], &digest[i]);
hmac->destroy(hmac);
tester->assert_true(tester, digest[i].len == 16, "chunk len");
tester->assert_false(tester, memcmp(digest[i].ptr, reference[i].ptr, 16), "hmac value");
allocator_free(digest[i].ptr);
}
/*
* test 4 is donne in append mode
*/
u_int8_t val = 0xcd;
u_int8_t key4[] = {
0x01,0x02,0x03,0x04,
0x05,0x06,0x07,0x08,
0x09,0x0a,0x0b,0x0c,
0x0d,0x0e,0x0f,0x10,
0x11,0x12,0x13,0x14,
0x15,0x16,0x17,0x18,
0x19
};
keys[3].ptr = key4;
keys[3].len = sizeof(key4);
u_int8_t reference4[] = {
0x69,0x7e,0xaf,0x0a,
0xca,0x3a,0x3a,0xea,
0x3a,0x75,0x16,0x47,
0x46,0xff,0xaa,0x79
};
reference[3].ptr = reference4;
reference[3].len = sizeof(reference4);
hmac_t *hmac = hmac_create(HASH_MD5);
hmac->set_key(hmac, keys[3]);
data[3].ptr = &val;
data[3].len = 1;
for (i=0; i<49; i++)
{
hmac->get_mac(hmac, data[3], NULL);
}
hmac->allocate_mac(hmac, data[3], &digest[3]);
hmac->destroy(hmac);
tester->assert_true(tester, digest[3].len == 16, "chunk len append mode");
tester->assert_false(tester, memcmp(digest[3].ptr, reference[3].ptr, 16), "hmac value append mode");
allocator_free(digest[3].ptr);
}
-49
View File
@@ -1,49 +0,0 @@
/**
* @file hmac_test.h
*
* @brief Tests for the hmac_t class.
*
*/
/*
* 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 HMAC_TEST_H_
#define HMAC_TEST_H_
#include <transforms/hmac.h>
#include <utils/tester.h>
/**
* @brief Test function used to test the hmac functionality
* using SHA1.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_hmac_sha1(protected_tester_t *tester);
/**
* @brief Test function used to test the hmac functionality
* using MD5.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_hmac_md5(protected_tester_t *tester);
#endif /*HMAC_TEST_H_*/
-84
View File
@@ -1,84 +0,0 @@
/**
* @file ike_sa_id_test.c
*
* @brief Tests for the ike_sa_id_t class.
*
*/
/*
* 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 "ike_sa_id_test.h"
#include <sa/ike_sa_id.h>
/*
* described in Header-File
*/
void test_ike_sa_id(protected_tester_t *tester)
{
ike_sa_id_t *ike_sa_id, *clone, *equal, *other1, *other2, *other3, *other4;
u_int64_t initiator, initiator2, responder, responder2;
bool is_initiator;
initiator = 0;
initiator2 = 12345612;
responder = 34334;
responder2 = 987863;
is_initiator = TRUE;
ike_sa_id = ike_sa_id_create(initiator, responder, is_initiator);
equal = ike_sa_id_create(initiator, responder, is_initiator);
other1 = ike_sa_id_create(initiator, responder2, is_initiator);
other2 = ike_sa_id_create(initiator2, responder2, is_initiator);
other3 = ike_sa_id_create(initiator2, responder, is_initiator);
is_initiator = FALSE;
other4 = ike_sa_id_create(initiator, responder, is_initiator);
/* check equality */
tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,equal) == TRUE), "equal check");
tester->assert_true(tester,(equal->equals(equal,ike_sa_id) == TRUE), "equal check");
/* check clone functionality and equality*/
clone = ike_sa_id->clone(ike_sa_id);
tester->assert_false(tester,(clone == ike_sa_id), "clone pointer check");
tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,clone) == TRUE), "equal check");
/* check for non equality */
tester->assert_false(tester,(ike_sa_id->equals(ike_sa_id,other1) == TRUE), "equal check");
tester->assert_false(tester,(ike_sa_id->equals(ike_sa_id,other2) == TRUE), "equal check");
tester->assert_false(tester,(ike_sa_id->equals(ike_sa_id,other3) == TRUE), "equal check");
tester->assert_false(tester,(ike_sa_id->equals(ike_sa_id,other4) == TRUE), "equal check");
other4->replace_values(other4,ike_sa_id);
tester->assert_true(tester,(ike_sa_id->equals(ike_sa_id,other4) == TRUE), "equal check");
/* check destroy functionality */
ike_sa_id->destroy(ike_sa_id);
equal->destroy(equal);
clone->destroy(clone);
other1->destroy(other1);
other2->destroy(other2);
other3->destroy(other3);
other4->destroy(other4);
}
-40
View File
@@ -1,40 +0,0 @@
/**
* @file ike_sa_id_test.h
*
* @brief Tests for the ike_sa_id_t class.
*
*/
/*
* 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 IKE_SA_ID_TEST_H_
#define IKE_SA_ID_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the ike_sa_id functionality.
*
* Tests are performed using one thread to test the
* features of the ike_sa_id_t.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_ike_sa_id(protected_tester_t *tester);
#endif /*IKE_SA_ID_TEST_H_*/
@@ -1,185 +0,0 @@
/**
* @file ike_sa_manager_test.c
*
* @brief Tests for the ike_sa_manager_t class.
*
*/
/*
* 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 <string.h>
#include <pthread.h>
#include <unistd.h>
#include "ike_sa_manager_test.h"
#include <types.h>
#include <sa/ike_sa_manager.h>
static struct ike_sa_manager_test_struct_s {
protected_tester_t *tester;
ike_sa_manager_t *isam;
} td;
static void test1_thread(ike_sa_id_t *ike_sa_id)
{
ike_sa_t *ike_sa;
status_t status;
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
td.tester->assert_true(td.tester, (status == SUCCESS), "checkout of a blocked ike_sa");
usleep(10000);
status = td.isam->checkin(td.isam, ike_sa);
td.tester->assert_true(td.tester, (status == SUCCESS), "checkin of a requested ike_sa");
}
static void test3_thread(ike_sa_id_t *ike_sa_id)
{
ike_sa_t *ike_sa;
status_t status;
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
td.tester->assert_true(td.tester, (status == NOT_FOUND), "IKE_SA already deleted");
}
void test_ike_sa_manager(protected_tester_t *tester)
{
status_t status;
u_int64_t initiator, responder;
ike_sa_id_t *ike_sa_id, *sa_id;
ike_sa_t *ike_sa;
int thread_count = 200;
int sa_count = 100;
int i;
pthread_t threads[thread_count];
td.tester = tester;
td.isam = ike_sa_manager_create();
tester->assert_true(tester, (td.isam != NULL), "ike_sa_manager creation");
/* First Test:
* we play initiator for IKE_SA_INIT first
* create an IKE_SA,
*
*/
td.isam->create_and_checkout(td.isam, &ike_sa);
/* for testing purposes, we manipulate the responder spi.
* this is usually done be the response from the communication partner,
* but we don't have one...
*/
responder = 123;
sa_id = ike_sa->get_id(ike_sa);
sa_id->set_responder_spi(sa_id, responder);
ike_sa_id = sa_id->clone(sa_id);
/* check in, so we should have a "completed" sa, specified by ike_sa_id */
status = td.isam->checkin(td.isam, ike_sa);
tester->assert_true(tester, (status == SUCCESS), "checkin modified IKE_SA");
/* now we check it out and start some other threads */
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
tester->assert_true(tester, (status == SUCCESS), "checkout existing IKE_SA 1");
for (i = 0; i < thread_count; i++)
{
if (pthread_create(&threads[i], NULL, (void*(*)(void*))test1_thread, (void*)ike_sa_id))
{
/* failed, decrease list */
thread_count--;
i--;
}
}
sleep(1);
status = td.isam->checkin(td.isam, ike_sa);
tester->assert_true(tester, (status == SUCCESS), "checkin IKE_SA");
sleep(1);
/* we now delete the IKE_SA, while it is requested by the threads.
* this should block until the have done their work.*/
status = td.isam->delete(td.isam, ike_sa_id);
tester->assert_true(tester, (status == SUCCESS), "delete IKE_SA by id");
for (i = 0; i < thread_count; i++)
{
pthread_join(threads[i], NULL);
}
ike_sa_id->destroy(ike_sa_id);
/* Second Test:
* now we simulate our partner initiates an IKE_SA_INIT,
* so we are the responder.
*
*/
memset(&initiator, 0, sizeof(initiator));
memset(&responder, 0, sizeof(responder));
initiator = 123;
ike_sa_id = ike_sa_id_create(initiator, responder, TRUE);
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
tester->assert_false(tester, (status == SUCCESS), "checkout unexisting IKE_SA 2");
/* let them go acquiring */
sleep(1);
ike_sa_id->destroy(ike_sa_id);
/* Third Test:
* put in a lot of IKE_SAs, check it out, set a thread waiting
* and destroy the manager...
*/
thread_count = sa_count;
for (i = 0; i < sa_count; i++)
{
td.isam->create_and_checkout(td.isam, &ike_sa);
if (pthread_create(&threads[i], NULL, (void*(*)(void*))test3_thread, (void*)ike_sa->get_id(ike_sa)))
{
/* failed, decrease list */
thread_count--;
}
}
/* let them go acquiring */
sleep(1);
td.isam->destroy(td.isam);
for (i = 0; i < thread_count; i++)
{
pthread_join(threads[i], NULL);
}
}
@@ -1,39 +0,0 @@
/**
* @file ike_sa_manager_test.h
*
* @brief Tests for the ike_sa_manager_t class.
*
*/
/*
* 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 IKE_SA_MANAGER_TEST_H_
#define IKE_SA_MANAGER_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the ike_sa_manager_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_ike_sa_manager(protected_tester_t *tester);
#endif /*IKE_SA_MANAGER_TEST_H_*/
-56
View File
@@ -1,56 +0,0 @@
/**
* @file ike_sa_test.c
*
* @brief Tests for the ike_sa_t class.
*
*/
/*
* 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 "ike_sa_test.h"
#include <types.h>
#include <encoding/message.h>
#include <sa/ike_sa.h>
void test_ike_sa(protected_tester_t *tester)
{
ike_sa_t *ike_sa;
ike_sa_id_t *ike_sa_id;
u_int64_t initiator, responder;
bool is_initiator;
initiator = 0;
responder = 34334LL;
is_initiator = TRUE;
/* create a ike_sa_id object for the new IKE_SA */
ike_sa_id = ike_sa_id_create(initiator, responder, is_initiator);
/* empty message and configuration objects are created */
/* test every ike_sa function */
ike_sa = ike_sa_create(ike_sa_id);
/* ike_sa->initialize_connection(ike_sa, NULL);
tester->assert_true(tester,(ike_sa != NULL), "ike_sa pointer check");
*/
ike_sa->destroy(ike_sa);
ike_sa_id->destroy(ike_sa_id);
}
-37
View File
@@ -1,37 +0,0 @@
/**
* @file ike_sa_test.h
*
* @brief Tests for the ike_sa_t class.
*
*/
/*
* 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 IKE_SA_TEST_H_
#define IKE_SA_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the ike_sa_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_ike_sa(protected_tester_t *tester);
#endif /*IKE_SA_TEST_H_*/
-133
View File
@@ -1,133 +0,0 @@
/**
* @file job_queue_test.c
*
* @brief Tests for the job_queue_t class.
*
*/
/*
* 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 <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include "job_queue_test.h"
#include <utils/allocator.h>
#include <queues/job_queue.h>
#include <queues/jobs/initiate_ike_sa_job.h>
typedef struct job_queue_test_s job_queue_test_t;
/**
* @brief Informations for the involved test-thread used in this test
*
*/
struct job_queue_test_s{
protected_tester_t *tester;
job_queue_t *job_queue;
/**
* number of items to be inserted in the job-queue
*/
int insert_item_count;
/**
* number of items to be removed by each
* receiver thread from the job-queue
*/
int remove_item_count;
};
/**
* @brief sender thread used in the the job_queue test function
*
* @param testinfo informations for the specific thread.
*/
static void test_job_queue_sender(job_queue_test_t * testinfo)
{
int i;
for (i = 0; i < testinfo->insert_item_count; i++)
{
job_t *job = (job_t *) initiate_ike_sa_job_create(NULL);
testinfo->job_queue->add(testinfo->job_queue,job);
}
}
/**
* @brief receiver thread used in the the job_queue test function
*
* @param testinfo informations for the specific thread.
*/
static void test_job_queue_receiver(job_queue_test_t * testinfo)
{
int i;
for (i = 0; i < testinfo->remove_item_count; i++)
{
job_t *job;
job = testinfo->job_queue->get(testinfo->job_queue);
testinfo->tester->assert_true(testinfo->tester,(job->get_type(job) == INITIATE_IKE_SA), "job type check");
job->destroy(job);
}
}
/*
* description is in header file
*/
void test_job_queue(protected_tester_t *tester)
{
int desired_value, i;
int sender_count = 10;
int receiver_count = 2;
pthread_t sender_threads[sender_count];
pthread_t receiver_threads[receiver_count];
job_queue_t *job_queue = job_queue_create();
job_queue_test_t test_infos;
test_infos.tester = tester;
test_infos.job_queue = job_queue;
test_infos.insert_item_count = 10000;
test_infos.remove_item_count = 50000;
desired_value = test_infos.insert_item_count * sender_count -
test_infos.remove_item_count * receiver_count;
for (i = 0; i < receiver_count;i++)
{
pthread_create( &receiver_threads[i], NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
}
for (i = 0; i < sender_count;i++)
{
pthread_create( &sender_threads[i], NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
}
/* Wait for all threads */
for (i = 0; i < sender_count;i++)
{
pthread_join(sender_threads[i], NULL);
}
for (i = 0; i < receiver_count;i++)
{
pthread_join(receiver_threads[i], NULL);
}
/* the job-queue has to have disered_value count entries! */
tester->assert_true(tester,(job_queue->get_count(job_queue) == desired_value), "get count value check");
job_queue->destroy(job_queue);
}
-40
View File
@@ -1,40 +0,0 @@
/**
* @file job_queue_test.h
*
* @brief Tests for the job_queue_test_t class.
*
*/
/*
* 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 JOB_QUEUE_TEST_H_
#define JOB_QUEUE_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the job_queue functionality.
*
* Tests are performed using different threads to test the multi-threaded
* features of the job_queue_t.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_job_queue(protected_tester_t *tester);
#endif /*JOB_QUEUE_TEST_H_*/
@@ -1,85 +0,0 @@
/**
* @file kernel_interface_test.h
*
* @brief Tests for the kernel_interface_t class.
*
*/
/*
* 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 "kernel_interface_test.h"
#include <daemon.h>
#include <threads/kernel_interface.h>
#include <utils/allocator.h>
#include <utils/logger.h>
#include <network/host.h>
/*
* described in Header-File
*/
void test_kernel_interface(protected_tester_t *tester)
{
kernel_interface_t *kernel_interface;
u_int32_t spi;
host_t *me, *other, *left, *right;
status_t status;
u_int8_t enc_key_bytes[] = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
};
u_int8_t inc_key_bytes[] = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
};
chunk_t enc_key,inc_key;
enc_key.ptr = enc_key_bytes;
enc_key.len = sizeof(enc_key_bytes);
inc_key.ptr = inc_key_bytes;
inc_key.len = sizeof(inc_key_bytes);
kernel_interface = kernel_interface_create();
me = host_create(AF_INET, "192.168.0.2", 0);
other = host_create(AF_INET, "192.168.0.3", 0);
status = kernel_interface->get_spi(kernel_interface, me, other, 50, 1234, &spi);
tester->assert_true(tester, status == SUCCESS, "spi get");
status = kernel_interface->add_sa(kernel_interface, me, other, spi, 50, 1234, ENCR_AES_CBC, enc_key,AUTH_UNDEFINED,inc_key,TRUE);
tester->assert_true(tester, status == SUCCESS, "add sa");
left = host_create(AF_INET, "10.1.0.0", 0);
right = host_create(AF_INET, "10.2.0.0", 0);
status = kernel_interface->add_policy(kernel_interface, me, other, left, right, 16, 16, XFRM_POLICY_OUT, 0, TRUE, FALSE, 1234);
tester->assert_true(tester, status == SUCCESS, "add policy");
me->destroy(me);
other->destroy(other);
left->destroy(left);
right->destroy(right);
kernel_interface->destroy(kernel_interface);
}
@@ -1,38 +0,0 @@
/**
* @file kernel_interface_test.h
*
* @brief Tests for the kernel_interface_t class.
*
*/
/*
* 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 KERNEL_INTERFACE_TEST_H_
#define KERNEL_INTERFACE_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the kernel_interface functionality.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_kernel_interface(protected_tester_t *tester);
#endif /*KERNEL_INTERFACE_TEST_H_*/
-241
View File
@@ -1,241 +0,0 @@
/**
* @file linked_list_test.c
*
* @brief Tests for the linked_list_t class.
*
*/
/*
* 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 <string.h>
#include "linked_list_test.h"
#include <utils/linked_list.h>
/*
* Description in header-file
*/
void test_linked_list(protected_tester_t *tester)
{
void *test_value = NULL;
linked_list_t *linked_list = linked_list_create();
tester->assert_true(tester,(linked_list->get_count(linked_list) == 0), "count check");
linked_list->insert_first(linked_list,"one");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 1), "count check");
linked_list->insert_first(linked_list,"two");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 2), "count check");
linked_list->insert_first(linked_list,"three");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 3), "count check");
linked_list->insert_first(linked_list,"four");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 4), "count check");
linked_list->insert_first(linked_list,"five");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 5), "count check");
tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
tester->assert_true(tester,(strcmp((char *) test_value,"five") == 0), "get_first value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 5), "count check");
tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_last value check");
tester->assert_true(tester,( linked_list->get_count(linked_list) == 5), "count check");
tester->assert_true(tester,(linked_list->remove_first(linked_list,&test_value) == SUCCESS), "remove_first call check");
tester->assert_true(tester,(strcmp((char *) test_value,"five") == 0), "remove_first value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 4), "count check");
tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 4), "count check");
tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_last value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 4), "count check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,0,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_at_position value check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,1,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"three") == 0), "get_at_position value check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,2,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"two") == 0), "get_at_position value check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,3,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_at_position value check");
tester->assert_false(tester,(linked_list->get_at_position(linked_list,4,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_false(tester,(linked_list->remove_at_position(linked_list,4,&test_value) == SUCCESS), "remove_at_position call check");
tester->assert_false(tester,(linked_list->insert_at_position(linked_list,5,test_value) == SUCCESS), "insert_at_position call 1 check");
tester->assert_true(tester,(linked_list->insert_at_position(linked_list,3,"six") == SUCCESS), "insert_at_position call 2 check");
tester->assert_true(tester,(linked_list->insert_at_position(linked_list,3,"seven") == SUCCESS), "insert_at_position call 3 check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,3,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"seven") == 0), "get_at_position value 1 check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,4,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"six") == 0), "get_at_position value 2 check");
tester->assert_true(tester,(linked_list->get_at_position(linked_list,5,&test_value) == SUCCESS), "get_at_position call check");
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "get_at_position value 3 check");
tester->assert_true(tester,(linked_list->remove_at_position(linked_list,3,&test_value) == SUCCESS), "remove_at_position call check");
tester->assert_true(tester,(linked_list->remove_at_position(linked_list,3,&test_value) == SUCCESS), "remove_at_position call check");
tester->assert_true(tester,(linked_list->remove_last(linked_list,&test_value) == SUCCESS), "remove_last call check");
tester->assert_true(tester,(strcmp((char *) test_value,"one") == 0), "remove_last value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 3), "count check");
tester->assert_true(tester,(linked_list->get_last(linked_list,&test_value) == SUCCESS), "get_last call check");
tester->assert_true(tester,(strcmp((char *) test_value,"two") == 0), "get_last value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 3), "count check");
tester->assert_true(tester,(linked_list->get_first(linked_list,&test_value) == SUCCESS), "get_first call check");
tester->assert_true(tester,(strcmp((char *) test_value,"four") == 0), "get_first value check");
tester->assert_true(tester,(linked_list->get_count(linked_list) == 3), "count check");
linked_list->destroy(linked_list);
}
/*
* Description in header-file
*/
void test_linked_list_iterator(protected_tester_t *tester)
{
void * value;
linked_list_t *linked_list = linked_list_create();
linked_list->insert_first(linked_list,"one");
linked_list->insert_first(linked_list,"two");
linked_list->insert_first(linked_list,"three");
linked_list->insert_first(linked_list,"four");
linked_list->insert_first(linked_list,"five");
iterator_t * iterator;
iterator_t * iterator2;
iterator = linked_list->create_iterator(linked_list,TRUE);
tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"five") == 0), "it 1 current value check");
tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"four") == 0), "it 1 current value check");
iterator2 = linked_list->create_iterator(linked_list,FALSE);
tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");
iterator2->current(iterator2,&value);
tester->assert_true(tester,(strcmp((char *) value,"one") == 0), "it 2 current value check");
tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "it 1 current value check");
tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");
iterator2->current(iterator2,&value);
tester->assert_true(tester,(strcmp((char *) value,"two") == 0), "it 2 current value check");
tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"two") == 0), "it 1 current value check");
tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");
iterator2->current(iterator2,&value);
tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "it 2 current value check");
tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"one") == 0), "it 1 current value check");
tester->assert_false(tester,iterator->has_next(iterator), "it 1 has_next value check");
tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");
tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check");
tester->assert_false(tester,iterator2->has_next(iterator2), "it 2 has_next value check");
iterator->destroy(iterator);
iterator2->destroy(iterator2);
linked_list->destroy(linked_list);
}
/*
* Description in header-file
*/
void test_linked_list_insert_and_remove(protected_tester_t *tester)
{
void *value;
iterator_t * iterator;
linked_list_t *linked_list = linked_list_create();
linked_list->insert_first(linked_list,"one");
linked_list->insert_first(linked_list,"two");
linked_list->insert_first(linked_list,"three");
linked_list->insert_first(linked_list,"four");
linked_list->insert_first(linked_list,"five");
iterator = linked_list->create_iterator(linked_list,TRUE);
iterator->has_next(iterator);
iterator->has_next(iterator);
iterator->has_next(iterator);
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
iterator->insert_before(iterator,"before_three");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
iterator->insert_after(iterator,"after_three");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"three") == 0), "current value check");
tester->assert_true(tester,(iterator->remove(iterator) == SUCCESS), "remove call check");
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"before_three") == 0), "current value check");
iterator->reset(iterator);
iterator->has_next(iterator);
iterator->has_next(iterator);
iterator->has_next(iterator);
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"before_three") == 0), "current value check");
iterator->has_next(iterator);
iterator->current(iterator,&value);
tester->assert_true(tester,(strcmp((char *) value,"after_three") == 0), "current value check");
iterator->destroy(iterator);
linked_list->destroy(linked_list);
}
@@ -1,74 +0,0 @@
/**
* @file linked_list_test.h
*
* @brief Tests for the linked_list_t class.
*
*/
/*
* 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 LINKED_LIST_TEST_H_
#define LINKED_LIST_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function for the type linked_list_t.
*
* Performs different kinds of assertions to check the functionality
* of the linked_list_t in a Single-Threaded environment.
*
* @warning To be usable in multi-threaded software
* this list has to get protected with locks.
*
* @param tester tester object
*
* @ingroup testcases
*/
void test_linked_list(protected_tester_t *tester);
/**
* @brief Test function for the type linked_list_t and its iterator.
*
* Performs different kinds of assertions to check the functionality
* of the linked_list_t and its iterator in a Single-Threaded environment.
*
* @warning To be usable in multi-threaded software
* this list has to get protected with locks.
*
* @param tester tester object
*
* @ingroup testcases
*/
void test_linked_list_iterator(protected_tester_t *tester);
/**
* @brief Test function for the type linked_list_t and its insert and remove
* functions.
*
* Performs different kinds of assertions to check the functionality
* of the linked_list_t and its insert and remove functions
*
* @warning To be usable in multi-threaded software
* this list has to get protected with locks.
*
* @param tester tester object
*
* @ingroup testcases
*/
void test_linked_list_insert_and_remove(protected_tester_t *tester);
#endif /*LINKED_LIST_TEST_H_*/
-56
View File
@@ -1,56 +0,0 @@
/**
* @file packet_test.c
*
* @brief Tests for the packet_t class.
*
*/
/*
* 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 <string.h>
#include "packet_test.h"
#include <daemon.h>
#include <network/packet.h>
#include <utils/allocator.h>
#include <utils/logger_manager.h>
/*
* Described in Header
*/
void test_packet(protected_tester_t *tester)
{
packet_t *packet = packet_create();
packet_t *packet2;
chunk_t data;
char *string_to_copy = "aha, soso";
data.len = strlen(string_to_copy) + 1;
data.ptr = allocator_alloc(data.len);
memcpy(data.ptr, string_to_copy, data.len);
packet->set_data(packet, data);
packet2 = packet->clone(packet);
data = packet2->get_data(packet2);
tester->assert_true(tester,(data.len == (strlen(string_to_copy) + 1)),"value length check");
tester->assert_true(tester,(memcmp(data.ptr,string_to_copy,data.len) == 0),"cloned value check");
packet2->destroy(packet2);
packet->destroy(packet);
}
-37
View File
@@ -1,37 +0,0 @@
/**
* @file packet_test.h
*
* @brief Tests for the packet_t class.
*
*/
/*
* 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 PACKET_TEST_H_
#define PACKET_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the packet_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_packet(protected_tester_t *tester);
#endif /*PACKET_TEST_H_*/
-964
View File
@@ -1,964 +0,0 @@
/**
* @file parser_test.c
*
* @brief Tests for the parser_t class.
*
*/
/*
* 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 <string.h>
#include "parser_test.h"
#include <utils/allocator.h>
#include <utils/logger_manager.h>
#include <encoding/generator.h>
#include <encoding/parser.h>
#include <encoding/payloads/encodings.h>
#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>
#include <encoding/payloads/auth_payload.h>
#include <encoding/payloads/cert_payload.h>
#include <encoding/payloads/certreq_payload.h>
#include <encoding/payloads/ts_payload.h>
#include <encoding/payloads/delete_payload.h>
#include <encoding/payloads/vendor_id_payload.h>
#include <encoding/payloads/cp_payload.h>
#include <encoding/payloads/eap_payload.h>
/*
* Described in Header
*/
void test_parser_with_header_payload(protected_tester_t *tester)
{
parser_t *parser;
ike_header_t *ike_header;
status_t status;
chunk_t header_chunk;
u_int8_t header_bytes[] = {
0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x03,0x45,0x06,0x28,
0x00,0x00,0x00,0x07,
0x00,0x00,0x00,0x1C,
};
header_chunk.ptr = header_bytes;
header_chunk.len = sizeof(header_bytes);
parser = parser_create(header_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, HEADER, (payload_t**)&ike_header);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
tester->assert_true(tester,(ike_header->get_initiator_spi(ike_header) == 1),"parsed initiator_spi value");
tester->assert_true(tester,(ike_header->get_responder_spi(ike_header) == 2),"parsed responder_spi value");
tester->assert_true(tester,(ike_header->payload_interface.get_next_type((payload_t*)ike_header) == 3),"parsed next_payload value");
tester->assert_true(tester,(ike_header->get_maj_version(ike_header) == 4),"parsed maj_version value");
tester->assert_true(tester,(ike_header->get_min_version(ike_header) == 5),"parsed min_version value");
tester->assert_true(tester,(ike_header->get_exchange_type(ike_header) == 6),"parsed exchange_type value");
tester->assert_true(tester,(ike_header->get_initiator_flag(ike_header) == TRUE),"parsed flags.initiator value");
tester->assert_true(tester,(ike_header->get_version_flag(ike_header) == FALSE),"parsed flags.version value");
tester->assert_true(tester,(ike_header->get_response_flag(ike_header) == TRUE),"parsed flags.response value");
tester->assert_true(tester,(ike_header->get_message_id(ike_header) == 7),"parsed message_id value");
tester->assert_true(tester,(ike_header->payload_interface.get_length((payload_t*)ike_header) == 0x1C),"parsed length value");
ike_header->destroy(ike_header);
}
/*
* Described in Header
*/
void test_parser_with_sa_payload(protected_tester_t *tester)
{
parser_t *parser;
sa_payload_t *sa_payload;
status_t status;
chunk_t sa_chunk, sa_chunk2, sa_chunk3;
iterator_t *proposals, *transforms, *attributes;
/* first test generic parsing functionality */
u_int8_t sa_bytes[] = {
0x00,0x80,0x00,0x24, /* payload header*/
0x00,0x00,0x00,0x20, /* a proposal */
0x01,0x02,0x04,0x05,
0x01,0x02,0x03,0x04, /* spi */
0x00,0x00,0x00,0x14, /* transform */
0x07,0x00,0x00,0x03,
0x80,0x01,0x00,0x05, /* attribute without length */
0x00,0x03,0x00,0x04, /* attribute with length */
0x01,0x02,0x03,0x04
};
sa_chunk.ptr = sa_bytes;
sa_chunk.len = sizeof(sa_bytes);
parser = parser_create(sa_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, SECURITY_ASSOCIATION, (payload_t**)&sa_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
proposals = sa_payload->create_proposal_substructure_iterator(sa_payload, TRUE);
while (proposals->has_next(proposals))
{
proposal_substructure_t *proposal;
proposals->current(proposals, (void**)&proposal);
chunk_t spi;
u_int8_t spi_should[] = {0x01, 0x02, 0x03, 0x04};
tester->assert_true(tester,(proposal->get_proposal_number(proposal) == 1),"proposal number");
tester->assert_true(tester,(proposal->get_protocol_id(proposal) == 2),"proposal id");
spi = proposal->get_spi(proposal);
tester->assert_false(tester,(memcmp(&spi_should, spi.ptr, spi.len)),"proposal spi");
transforms = proposal->create_transform_substructure_iterator(proposal, TRUE);
while(transforms->has_next(transforms))
{
transform_substructure_t *transform;
int loopi;
transforms->current(transforms, (void**)&transform);
tester->assert_true(tester,(transform->get_transform_type(transform) == 7),"transform type");
tester->assert_true(tester,(transform->get_transform_id(transform) == 3),"transform id");
attributes = transform->create_transform_attribute_iterator(transform, TRUE);
loopi = 0;
while (attributes->has_next(attributes))
{
transform_attribute_t *attribute;
attributes->current(attributes, (void**)&attribute);
if (loopi == 0)
{
u_int8_t value[] = {0x05, 0x00};
chunk_t attribute_value;
tester->assert_true(tester,(attribute->get_attribute_type(attribute) == 1),"attribute 1 type");
attribute_value = attribute->get_value_chunk(attribute);
tester->assert_false(tester,(memcmp(&value, attribute_value.ptr, attribute_value.len)),"attribute 1 value");
}
if (loopi == 1)
{
u_int8_t value[] = {0x01, 0x02, 0x03, 0x04};
chunk_t attribute_value;
tester->assert_true(tester,(attribute->get_attribute_type(attribute) == 3),"attribute 2 type");
attribute_value = attribute->get_value_chunk(attribute);
tester->assert_false(tester,(memcmp(&value, attribute_value.ptr, attribute_value.len)),"attribute 2 value");
}
loopi++;
}
attributes->destroy(attributes);
}
transforms->destroy(transforms);
}
proposals->destroy(proposals);
sa_payload->destroy(sa_payload);
/* now test SA functionality after parsing an SA payload*/
u_int8_t sa_bytes2[] = {
0x00,0x00,0x00,0x6C, /* payload header*/
0x02,0x00,0x00,0x34, /* a proposal */
0x01,0x01,0x00,0x04,
0x03,0x00,0x00,0x0C, /* transform 1 */
0x01,0x00,0x00,0x01,
0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
0x03,0x00,0x00,0x0C, /* transform 2 */
0x02,0x00,0x00,0x01,
0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
0x03,0x00,0x00,0x0C, /* transform 3 */
0x03,0x00,0x00,0x01,
0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
0x00,0x00,0x00,0x08, /* transform 4 */
0x04,0x00,0x00,0x01,
0x00,0x00,0x00,0x34, /* a proposal */
0x01,0x01,0x00,0x04,
0x03,0x00,0x00,0x0C, /* transform 1 */
0x01,0x00,0x00,0x02,
0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
0x03,0x00,0x00,0x0C, /* transform 2 */
0x02,0x00,0x00,0x02,
0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
0x03,0x00,0x00,0x0C, /* transform 3 */
0x03,0x00,0x00,0x02,
0x80,0x0E,0x00,0x10, /* keylength attribute with 16 bytes length */
0x00,0x00,0x00,0x08, /* transform 4 */
0x04,0x00,0x00,0x02,
};
sa_chunk2.ptr = sa_bytes2;
sa_chunk2.len = sizeof(sa_bytes2);
parser = parser_create(sa_chunk2);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, SECURITY_ASSOCIATION, (payload_t**)&sa_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
status = sa_payload->payload_interface.verify(&(sa_payload->payload_interface));
tester->assert_true(tester,(status == SUCCESS),"verify call check");
/*
status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals, &ike_proposal_count);
tester->assert_true(tester,(status == SUCCESS),"get ike proposals call check");
tester->assert_true(tester,(ike_proposal_count == 2),"ike proposal count check");
tester->assert_true(tester,(ike_proposals[0].encryption_algorithm == 1),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[0].encryption_algorithm_key_length == 20),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[0].integrity_algorithm == 1),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[0].integrity_algorithm_key_length == 20),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[0].pseudo_random_function == 1),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[0].pseudo_random_function_key_length == 20),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[0].diffie_hellman_group == 1),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].encryption_algorithm == 2),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].encryption_algorithm_key_length == 16),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].integrity_algorithm == 2),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].integrity_algorithm_key_length == 16),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].pseudo_random_function == 2),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].pseudo_random_function_key_length == 16),"ike proposal content check");
tester->assert_true(tester,(ike_proposals[1].diffie_hellman_group == 2),"ike proposal content check");
if (status == SUCCESS)
{
allocator_free(ike_proposals);
}
*/
sa_payload->destroy(sa_payload);
/* now test SA functionality after parsing an SA payload with child sa proposals*/
u_int8_t sa_bytes3[] = {
0x00,0x00,0x00,0xA0, /* payload header*/
/* suite 1 */
0x02,0x00,0x00,0x28, /* a proposal */
0x01,0x02,0x04,0x03,
0x01,0x01,0x01,0x01,
0x03,0x00,0x00,0x0C, /* transform 1 */
0x03,0x00,0x00,0x01,
0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
0x03,0x00,0x00,0x08, /* transform 2 */
0x04,0x00,0x00,0x0E,
0x00,0x00,0x00,0x08, /* transform 3 */
0x05,0x00,0x00,0x01,
0x02,0x00,0x00,0x20, /* a proposal */
0x01,0x03,0x04,0x02,
0x02,0x02,0x02,0x02,
0x03,0x00,0x00,0x0C, /* transform 1 */
0x01,0x00,0x00,0x0C,
0x80,0x0E,0x00,0x20, /* keylength attribute with 32 bytes length */
0x00,0x00,0x00,0x08, /* transform 2 */
0x04,0x00,0x00,0x02,
/* suite 2 */
0x02,0x00,0x00,0x28, /* a proposal */
0x02,0x02,0x04,0x03,
0x01,0x01,0x01,0x01,
0x03,0x00,0x00,0x0C, /* transform 1 */
0x03,0x00,0x00,0x01,
0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
0x03,0x00,0x00,0x08, /* transform 2 */
0x04,0x00,0x00,0x0E,
0x00,0x00,0x00,0x08, /* transform 3 */
0x05,0x00,0x00,0x01,
0x00,0x00,0x00,0x2C, /* a proposal */
0x02,0x03,0x04,0x03,
0x02,0x02,0x02,0x02,
0x03,0x00,0x00,0x0C, /* transform 1 */
0x01,0x00,0x00,0x0C,
0x80,0x0E,0x00,0x20, /* keylength attribute with 32 bytes length */
0x03,0x00,0x00,0x0C, /* transform 2 */
0x03,0x00,0x00,0x01,
0x80,0x0E,0x00,0x14, /* keylength attribute with 20 bytes length */
0x00,0x00,0x00,0x08, /* transform 3 */
0x04,0x00,0x00,0x02,
};
sa_chunk3.ptr = sa_bytes3;
sa_chunk3.len = sizeof(sa_bytes3);
parser = parser_create(sa_chunk3);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, SECURITY_ASSOCIATION, (payload_t**)&sa_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
status = sa_payload->payload_interface.verify(&(sa_payload->payload_interface));
tester->assert_true(tester,(status == SUCCESS),"verify call check");
/*
status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals, &ike_proposal_count);
tester->assert_false(tester,(status == SUCCESS),"get ike proposals call check");
status = sa_payload->get_proposals (sa_payload, &proposals, &proposal_count);
tester->assert_true(tester,(status == SUCCESS),"get child proposals call check");
tester->assert_true(tester,(proposal_count == 2),"child proposal count check");
tester->assert_true(tester,(proposals[0].ah.is_set == TRUE),"is ah set check");
tester->assert_true(tester,(proposals[0].ah.integrity_algorithm == AUTH_HMAC_MD5_96),"integrity_algorithm check");
tester->assert_true(tester,(proposals[0].ah.integrity_algorithm_key_size == 20),"integrity_algorithm_key_size check");
tester->assert_true(tester,(proposals[0].ah.diffie_hellman_group == MODP_2048_BIT),"diffie_hellman_group check");
tester->assert_true(tester,(proposals[0].ah.extended_sequence_numbers == EXT_SEQ_NUMBERS),"extended_sequence_numbers check");
tester->assert_true(tester,(proposals[0].ah.spi[0] == 1),"spi check");
tester->assert_true(tester,(proposals[0].ah.spi[1] == 1),"spi check");
tester->assert_true(tester,(proposals[0].ah.spi[2] == 1),"spi check");
tester->assert_true(tester,(proposals[0].ah.spi[3] == 1),"spi check");
tester->assert_true(tester,(proposals[0].esp.is_set == TRUE),"is ah set check");
tester->assert_true(tester,(proposals[0].esp.encryption_algorithm == ENCR_AES_CBC),"integrity_algorithm check");
tester->assert_true(tester,(proposals[0].esp.encryption_algorithm_key_size == 32),"integrity_algorithm_key_size check");
tester->assert_true(tester,(proposals[0].esp.diffie_hellman_group == MODP_1024_BIT),"diffie_hellman_group check");
tester->assert_true(tester,(proposals[0].esp.integrity_algorithm == AUTH_UNDEFINED),"integrity_algorithm check");
tester->assert_true(tester,(proposals[0].esp.spi[0] == 2),"spi check");
tester->assert_true(tester,(proposals[0].esp.spi[1] == 2),"spi check");
tester->assert_true(tester,(proposals[0].esp.spi[2] == 2),"spi check");
tester->assert_true(tester,(proposals[0].esp.spi[3] == 2),"spi check");
tester->assert_true(tester,(proposals[1].ah.is_set == TRUE),"is ah set check");
tester->assert_true(tester,(proposals[1].ah.integrity_algorithm == AUTH_HMAC_MD5_96),"integrity_algorithm check");
tester->assert_true(tester,(proposals[1].ah.integrity_algorithm_key_size == 20),"integrity_algorithm_key_size check");
tester->assert_true(tester,(proposals[1].ah.diffie_hellman_group == MODP_2048_BIT),"diffie_hellman_group check");
tester->assert_true(tester,(proposals[1].ah.extended_sequence_numbers == EXT_SEQ_NUMBERS),"extended_sequence_numbers check");
tester->assert_true(tester,(proposals[1].ah.spi[0] == 1),"spi check");
tester->assert_true(tester,(proposals[1].ah.spi[1] == 1),"spi check");
tester->assert_true(tester,(proposals[1].ah.spi[2] == 1),"spi check");
tester->assert_true(tester,(proposals[1].ah.spi[3] == 1),"spi check");
tester->assert_true(tester,(proposals[1].esp.is_set == TRUE),"is ah set check");
tester->assert_true(tester,(proposals[1].esp.encryption_algorithm == ENCR_AES_CBC),"integrity_algorithm check");
tester->assert_true(tester,(proposals[1].esp.encryption_algorithm_key_size == 32),"integrity_algorithm_key_size check");
tester->assert_true(tester,(proposals[1].esp.diffie_hellman_group == MODP_1024_BIT),"diffie_hellman_group check");
tester->assert_true(tester,(proposals[1].esp.integrity_algorithm == AUTH_HMAC_MD5_96),"integrity_algorithm check");
tester->assert_true(tester,(proposals[1].esp.integrity_algorithm_key_size == 20),"integrity_algorithm check");
tester->assert_true(tester,(proposals[1].esp.spi[0] == 2),"spi check");
tester->assert_true(tester,(proposals[1].esp.spi[1] == 2),"spi check");
tester->assert_true(tester,(proposals[1].esp.spi[2] == 2),"spi check");
tester->assert_true(tester,(proposals[1].esp.spi[3] == 2),"spi check");
if (status == SUCCESS)
{
allocator_free(proposals);
}
*/
sa_payload->destroy(sa_payload);
}
/*
* Described in Header
*/
void test_parser_with_nonce_payload(protected_tester_t *tester)
{
parser_t *parser;
nonce_payload_t *nonce_payload;
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 */
0x04,0x05,0x06,0x07,
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F
};
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);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
result = nonce_payload->get_nonce(nonce_payload);
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);
allocator_free_chunk(&result);
}
/*
* Described in Header
*/
void test_parser_with_id_payload(protected_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_clone(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(protected_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);
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");
parser->destroy(parser);
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);
}
/*
* Described in Header
*/
void test_parser_with_notify_payload(protected_tester_t *tester)
{
parser_t *parser;
notify_payload_t *notify_payload;
status_t status;
chunk_t notify_chunk, result;
u_int8_t notify_bytes[] = {
0x00,0x00,0x00,0x1C, /* payload header */
0x03,0x04,0x00,0x01,
0x01,0x02,0x03,0x03, /* spi */
0x04,0x05,0x06,0x07, /* noti dati */
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F,
0x0C,0x0D,0x0E,0x0F
};
notify_chunk.ptr = notify_bytes;
notify_chunk.len = sizeof(notify_bytes);
parser = parser_create(notify_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, NOTIFY, (payload_t**)&notify_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
tester->assert_true(tester,(notify_payload->get_protocol_id(notify_payload) == 3), "Protocol id");
tester->assert_true(tester,(notify_payload->get_notify_message_type(notify_payload) == 1), "notify message type");
result = notify_payload->get_spi(notify_payload);
tester->assert_false(tester,(memcmp(notify_bytes + 8, result.ptr, result.len)), "parsed spi");
result = notify_payload->get_notification_data(notify_payload);
tester->assert_false(tester,(memcmp(notify_bytes + 12, result.ptr, result.len)), "parsed notification data");
notify_payload->destroy(notify_payload);
}
/*
* Described in Header
*/
void test_parser_with_auth_payload(protected_tester_t *tester)
{
parser_t *parser;
auth_payload_t *auth_payload;
status_t status;
chunk_t auth_chunk, result;
u_int8_t auth_bytes[] = {
0x00,0x00,0x00,0x14, /* payload header */
0x03,0x01,0x02,0x03,
0x04,0x05,0x06,0x07,/* 12 Byte nonce */
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F
};
auth_chunk.ptr = auth_bytes;
auth_chunk.len = sizeof(auth_bytes);
parser = parser_create(auth_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, AUTHENTICATION, (payload_t**)&auth_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
result = auth_payload->get_data_clone(auth_payload);
tester->assert_true(tester,(auth_payload->get_auth_method(auth_payload) == DSS_DIGITAL_SIGNATURE), "is DSS_DIGITAL_SIGNATURE method");
tester->assert_true(tester,(result.len == 12), "parsed data lenght");
tester->assert_false(tester,(memcmp(auth_bytes + 8, result.ptr, result.len)), "parsed nonce data");
auth_payload->destroy(auth_payload);
allocator_free_chunk(&result);
}
/*
* Described in Header
*/
void test_parser_with_ts_payload(protected_tester_t *tester)
{
parser_t *parser;
ts_payload_t *ts_payload;
status_t status;
chunk_t ts_chunk;
traffic_selector_substructure_t *ts1, *ts2;
host_t *start_host1, *start_host2, *end_host1, *end_host2;
iterator_t *iterator;
u_int8_t ts_bytes[] = {
/* payload header */
0x00,0x00,0x00,0x28,
0x02,0x00,0x00,0x00,
/* traffic selector 1 */
0x07,0x00,0x00,0x10,
0x01,0xF4,0x01,0xF4,
0xC0,0xA8,0x01,0x00,
0xC0,0xA8,0x01,0xFF,
/* traffic selector 2 */
0x07,0x03,0x00,0x10,
0x00,0x00,0xFF,0xFF,
0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0xFF,
};
ts_chunk.ptr = ts_bytes;
ts_chunk.len = sizeof(ts_bytes);
parser = parser_create(ts_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, TRAFFIC_SELECTOR_RESPONDER, (payload_t**)&ts_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
iterator = ts_payload->create_traffic_selector_substructure_iterator(ts_payload,TRUE);
tester->assert_true(tester,(iterator->has_next(iterator)), "has next check");
/* check first ts */
iterator->current(iterator,(void **)&ts1);
tester->assert_true(tester,(ts1->get_protocol_id(ts1) == 0), "ip protocol id check");
start_host1 = ts1->get_start_host(ts1);
end_host1 = ts1->get_end_host(ts1);
tester->assert_true(tester,(start_host1->get_port(start_host1) == 500), "start port check");
tester->assert_true(tester,(end_host1->get_port(end_host1) == 500), "start port check");
tester->assert_true(tester,(memcmp(start_host1->get_address(start_host1),"192.168.1.0",strlen("192.168.1.0")) == 0), "start address check");
tester->assert_true(tester,(memcmp(end_host1->get_address(end_host1),"192.168.1.255",strlen("192.168.1.255")) == 0), "end address check");
start_host1->destroy(start_host1);
end_host1->destroy(end_host1);
tester->assert_true(tester,(iterator->has_next(iterator)), "has next check");
/* check second ts */
iterator->current(iterator,(void **)&ts2);
tester->assert_true(tester,(ts2->get_protocol_id(ts2) == 3), "ip protocol id check");
start_host2 = ts2->get_start_host(ts2);
end_host2 = ts2->get_end_host(ts2);
tester->assert_true(tester,(start_host2->get_port(start_host2) == 0), "start port check");
tester->assert_true(tester,(end_host2->get_port(end_host2) == 65535), "start port check");
tester->assert_true(tester,(memcmp(start_host2->get_address(start_host2),"0.0.0.0",strlen("0.0.0.0")) == 0), "start address check");
tester->assert_true(tester,(memcmp(end_host2->get_address(end_host2),"255.255.255.255",strlen("255.255.255.255")) == 0), "end address check");
start_host2->destroy(start_host2);
end_host2->destroy(end_host2);
tester->assert_false(tester,(iterator->has_next(iterator)), "has next check");
iterator->destroy(iterator);
ts_payload->destroy(ts_payload);
}
/*
* Described in Header
*/
void test_parser_with_cert_payload(protected_tester_t *tester)
{
parser_t *parser;
cert_payload_t *cert_payload;
status_t status;
chunk_t cert_chunk, result;
u_int8_t cert_bytes[] = {
0x00,0x00,0x00,0x11, /* payload header */
0x03,
0x04,0x05,0x06,0x07,/* 12 Byte nonce */
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F
};
cert_chunk.ptr = cert_bytes;
cert_chunk.len = sizeof(cert_bytes);
parser = parser_create(cert_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, CERTIFICATE, (payload_t**)&cert_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
result = cert_payload->get_data_clone(cert_payload);
tester->assert_true(tester,(cert_payload->get_cert_encoding(cert_payload) == DNS_SIGNED_KEY), "is DNS_SIGNED_KEY encoding");
tester->assert_true(tester,(result.len == 12), "parsed data lenght");
tester->assert_false(tester,(memcmp(cert_bytes + 5, result.ptr, result.len)), "parsed data");
cert_payload->destroy(cert_payload);
allocator_free_chunk(&result);
}
/*
* Described in Header
*/
void test_parser_with_certreq_payload(protected_tester_t *tester)
{
parser_t *parser;
certreq_payload_t *certreq_payload;
status_t status;
chunk_t certreq_chunk, result;
u_int8_t certreq_bytes[] = {
0x00,0x00,0x00,0x11, /* payload header */
0x03,
0x04,0x05,0x06,0x07,/* 12 Byte data */
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F
};
certreq_chunk.ptr = certreq_bytes;
certreq_chunk.len = sizeof(certreq_bytes);
parser = parser_create(certreq_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, CERTIFICATE_REQUEST, (payload_t**)&certreq_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
result = certreq_payload->get_data_clone(certreq_payload);
tester->assert_true(tester,(certreq_payload->get_cert_encoding(certreq_payload) == DNS_SIGNED_KEY), "is DNS_SIGNED_KEY encoding");
tester->assert_true(tester,(result.len == 12), "parsed data lenght");
tester->assert_false(tester,(memcmp(certreq_bytes + 5, result.ptr, result.len)), "parsed data");
certreq_payload->destroy(certreq_payload);
allocator_free_chunk(&result);
}
/*
* Described in Header
*/
void test_parser_with_delete_payload(protected_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) == PROTO_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);
}
/*
* Described in Header
*/
void test_parser_with_vendor_id_payload(protected_tester_t *tester)
{
parser_t *parser;
vendor_id_payload_t *vendor_id_payload;
status_t status;
chunk_t vendor_id_chunk, result;
u_int8_t vendor_id_bytes[] = {
0x00,0x00,0x00,0x10, /* payload header */
0x04,0x05,0x06,0x07,/* 12 Byte data */
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F
};
vendor_id_chunk.ptr = vendor_id_bytes;
vendor_id_chunk.len = sizeof(vendor_id_bytes);
parser = parser_create(vendor_id_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, VENDOR_ID, (payload_t**)&vendor_id_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
result = vendor_id_payload->get_data(vendor_id_payload);
tester->assert_true(tester,(result.len == 12), "parsed data lenght");
tester->assert_false(tester,(memcmp(vendor_id_bytes + 4, result.ptr, result.len)), "parsed data");
tester->assert_true(tester,(((payload_t *)vendor_id_payload)->verify((payload_t *)vendor_id_payload) == SUCCESS), "verify check");
vendor_id_payload->destroy(vendor_id_payload);
}
/*
* Described in Header
*/
void test_parser_with_cp_payload(protected_tester_t *tester)
{
parser_t *parser;
cp_payload_t *cp_payload;
configuration_attribute_t *attribute;
status_t status;
chunk_t cp_chunk;
iterator_t *iterator;
/* first test generic parsing functionality */
u_int8_t cp_bytes[] = {
/* cp payload header */
0x00,0x00,0x00,0x18,
0x05,0x00,0x00,0x00,
/* configuration attribute 1*/
0x00,0x03,0x00,0x04,
0x61,0x62,0x63,0x64,
/* configuration attribute 2*/
0x00,0x04,0x00,0x04,
0x65,0x66,0x67,0x68,
};
cp_chunk.ptr = cp_bytes;
cp_chunk.len = sizeof(cp_bytes);
parser = parser_create(cp_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, CONFIGURATION, (payload_t**)&cp_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
iterator = cp_payload->create_configuration_attribute_iterator(cp_payload,TRUE);
tester->assert_true(tester,(iterator->has_next(iterator)),"has_next call check");
iterator->current(iterator,(void **)&attribute);
tester->assert_true(tester,(attribute->get_attribute_type(attribute) == 3),"get type check");
tester->assert_true(tester,(attribute->get_attribute_length(attribute) == 4),"get type check");
tester->assert_true(tester,(iterator->has_next(iterator)),"has_next call check");
iterator->current(iterator,(void **)&attribute);
tester->assert_true(tester,(attribute->get_attribute_type(attribute) == 4),"get type check");
tester->assert_true(tester,(attribute->get_attribute_length(attribute) == 4),"get type check");
iterator->current(iterator,(void **)&attribute);
tester->assert_false(tester,(iterator->has_next(iterator)),"has_next call check");
iterator->destroy(iterator);
if (status != SUCCESS)
{
return;
}
cp_payload->destroy(cp_payload);
parser->destroy(parser);
}
/*
* Described in Header
*/
void test_parser_with_eap_payload(protected_tester_t *tester)
{
parser_t *parser;
eap_payload_t *eap_payload;
status_t status;
chunk_t eap_chunk, result;
u_int8_t eap_bytes[] = {
0x00,0x00,0x00,0x10, /* payload header */
0x04,0x05,0x06,0x07,/* 12 Byte data */
0x08,0x09,0x0A,0x2B,
0x0C,0x0D,0x0E,0x0F
};
eap_chunk.ptr = eap_bytes;
eap_chunk.len = sizeof(eap_bytes);
parser = parser_create(eap_chunk);
tester->assert_true(tester,(parser != NULL), "parser create check");
status = parser->parse_payload(parser, VENDOR_ID, (payload_t**)&eap_payload);
tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
parser->destroy(parser);
if (status != SUCCESS)
{
return;
}
result = eap_payload->get_message(eap_payload);
tester->assert_true(tester,(result.len == 12), "parsed data lenght");
tester->assert_false(tester,(memcmp(eap_bytes + 4, result.ptr, result.len)), "parsed data");
tester->assert_true(tester,(((payload_t *)eap_payload)->verify((payload_t *)eap_payload) == SUCCESS), "verify check");
eap_payload->destroy(eap_payload);
}
-170
View File
@@ -1,170 +0,0 @@
/**
* @file parser_test.h
*
* @brief Tests for the parser_t class.
*
*/
/*
* 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 PARSER_TEST_H_
#define PARSER_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the parser_t functionality when
* parsing a header payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_header_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a sa payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_sa_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a nonce payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_nonce_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a ID payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_id_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a ke payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_ke_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a notify payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_notify_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a AUTH payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_auth_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a TS payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_ts_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a CERT payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_cert_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a CERTREQ payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_certreq_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a CERTREQ payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_delete_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a VENDOR ID payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_vendor_id_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a CP payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_cp_payload(protected_tester_t *tester);
/**
* @brief Test function used to test the parser_t functionality when
* parsing a EAP payload.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_parser_with_eap_payload(protected_tester_t *tester);
#endif /*PARSER_TEST_H_*/
-247
View File
@@ -1,247 +0,0 @@
/**
* @file policy_test.c
*
* @brief Tests for the policy_t class.
*
*/
/*
* 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 "policy_test.h"
#include <daemon.h>
#include <config/policy.h>
#include <config/traffic_selector.h>
#include <utils/allocator.h>
#include <utils/logger.h>
#include <encoding/payloads/ts_payload.h>
/**
* Described in header.
*/
void test_policy(protected_tester_t *tester)
{
policy_t *policy;
// traffic_selector_t *ts;
// linked_list_t *ts_stored, *ts_supplied, *ts_selected, *ts_expected;
proposal_t *proposal1, *proposal2, *proposal3, *proposal_sel;
linked_list_t *proposals_list;
iterator_t *iterator;
logger_t *logger;
identification_t *alice, *bob;
logger = charon->logger_manager->get_logger(charon->logger_manager, TESTER);
logger->disable_level(logger, FULL);
alice = identification_create_from_string(ID_IPV4_ADDR, "152.96.193.131");
bob = identification_create_from_string(ID_IPV4_ADDR, "152.96.193.130");
policy = policy_create(alice, bob);
tester->assert_true(tester, (policy != NULL), "policy construction");
/*
* test proposal getting and selection
*
*/
/* esp only prop */
proposal1 = proposal_create(1);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
/* ah only prop */
proposal2 = proposal_create(2);
proposal2->add_algorithm(proposal2, PROTO_AH, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
/* ah and esp prop */
proposal3 = proposal_create(3);
proposal3->add_algorithm(proposal3, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 16);
proposal3->add_algorithm(proposal3, PROTO_AH, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
policy->add_proposal(policy, proposal1);
policy->add_proposal(policy, proposal2);
policy->add_proposal(policy, proposal3);
proposals_list = policy->get_proposals(policy);
tester->assert_true(tester, (proposals_list->get_count(proposals_list) == 3), "proposal count");
proposals_list = linked_list_create();
proposal1 = proposal_create(1);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32);
proposal2 = proposal_create(2);
proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 16);
proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 0);
proposal2->add_algorithm(proposal2, PROTO_AH, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
proposal2->add_algorithm(proposal2, PROTO_AH, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
proposals_list->insert_last(proposals_list, proposal1);
proposals_list->insert_last(proposals_list, proposal2);
proposal_sel = policy->select_proposal(policy, proposals_list);
tester->assert_false(tester, proposal_sel == NULL, "proposal select");
/* check ESP encryption algo */
iterator = proposal_sel->create_algorithm_iterator(proposal_sel, PROTO_ESP, ENCRYPTION_ALGORITHM);
tester->assert_false(tester, iterator == NULL, "algorithm select ESP");
while (iterator->has_next(iterator))
{
algorithm_t *algo;
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == ENCR_3DES, "ESP encryption algo");
tester->assert_true(tester, algo->key_size == 16, "ESP encryption keysize");
}
iterator->destroy(iterator);
iterator = proposal_sel->create_algorithm_iterator(proposal_sel, PROTO_AH, INTEGRITY_ALGORITHM);
/* check AH integrity algo */
tester->assert_false(tester, iterator == NULL, "algorithm select AH");
while (iterator->has_next(iterator))
{
algorithm_t *algo;
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "ESP encryption algo");
tester->assert_true(tester, algo->key_size == 20, "ESP encryption keysize");
}
iterator->destroy(iterator);
proposal_sel->destroy(proposal_sel);
/* cleanup */
proposal1->destroy(proposal1);
proposal1->destroy(proposal2);
proposals_list->destroy(proposals_list);
// /*
// * test traffic selection getting and matching
// *
// */
//
// ts_stored = linked_list_create();
//
// /* allow any tcp */
// ts = traffic_selector_create_from_string(6, TS_IPV4_ADDR_RANGE, "0.0.0.0", 0, "255.255.255.255", 65535);
// ts_stored->insert_last(ts_stored, (void*)ts);
// /* allow udp on port 123 to ".122" */
// ts = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.122", 123, "152.96.193.122", 123);
// ts_stored->insert_last(ts_stored, (void*)ts);
// /* allow udp on ports > 2000 in subnet ... */
// ts = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.0", 2000, "152.96.193.255", 65535);
// ts_stored->insert_last(ts_stored, (void*)ts);
//
//
//
// /* define request and result */
//
// /* udp on subnet:123, should be reduced to ".122" */
// ts = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.0", 123, "152.96.193.255", 123);
// ts_supplied->insert_last(ts_supplied, (void*)ts);
// ts_reference[0] = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.122", 123, "152.96.193.122", 123);
//
// /* should be granted. */
// ts_request[1] = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.0", 2000, "152.96.193.255", 2000);
// ts_reference[1] = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.0", 2000, "152.96.193.255", 2000);
//
// /* should be reduced to port 2000 - 3000. and range ".193.*" */
// ts_request[2] = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.191.0", 1000, "152.96.194.255", 3000);
// ts_reference[2] = traffic_selector_create_from_string(7, TS_IPV4_ADDR_RANGE, "152.96.193.0", 2000, "152.96.193.255", 3000);
//
// /* icmp request, should be discarded */
// ts_request[3] = traffic_selector_create_from_string(1, TS_IPV4_ADDR_RANGE, "0.0.0.0", 0, "255.255.255.255", 65535);
//
// policy->add_my_traffic_selector(policy, ts_policy[0]);
// policy->add_my_traffic_selector(policy, ts_policy[1]);
// policy->add_my_traffic_selector(policy, ts_policy[2]);
//
// count = policy->get_my_traffic_selectors(policy, &ts_result);
// tester->assert_true(tester, (count == 3), "ts get count");
// ts_result[0]->destroy(ts_result[0]);
// ts_result[0]->destroy(ts_result[1]);
// ts_result[0]->destroy(ts_result[2]);
// allocator_free(ts_result);
//
// count = policy->select_my_traffic_selectors(policy, &ts_request[0], 4, &ts_result);
// tester->assert_true(tester, (count == 3), "ts select count");
//
//
// /* store and restore into ts payload, tricky tricky */
// ts_payload = ts_payload_create_from_traffic_selectors(TRUE, ts_result, count);
//
// /* destroy */
// ts_result[0]->destroy(ts_result[0]);
// ts_result[0]->destroy(ts_result[1]);
// ts_result[0]->destroy(ts_result[2]);
// allocator_free(ts_result);
//
// /* get them again out of the payload */
// count = ts_payload->get_traffic_selectors(ts_payload, &ts_result);
// ts_payload->destroy(ts_payload);
//
//
//
// int i;
// for (i = 0; i<count; i++)
// {
// chunk_t fa_res = ts_result[i]->get_from_address(ts_result[i]);
// chunk_t fa_ref = ts_reference[i]->get_from_address(ts_reference[i]);
// chunk_t ta_res = ts_result[i]->get_to_address(ts_result[i]);
// chunk_t ta_ref = ts_reference[i]->get_to_address(ts_reference[i]);
// u_int16_t fp_res = ts_result[i]->get_from_port(ts_result[i]);
// u_int16_t fp_ref = ts_reference[i]->get_from_port(ts_reference[i]);
// u_int16_t tp_res = ts_result[i]->get_to_port(ts_result[i]);
// u_int16_t tp_ref = ts_reference[i]->get_to_port(ts_reference[i]);
//
//
// logger->log_chunk(logger, RAW, "from address result", fa_res);
// logger->log_chunk(logger, RAW, "from address reference", fa_ref);
// logger->log_chunk(logger, RAW, "to address result", ta_res);
// logger->log_chunk(logger, RAW, "to address reference", ta_ref);
// tester->assert_true(tester, fa_res.len == fa_ref.len, "from address len");
// tester->assert_false(tester, memcmp(fa_res.ptr, fa_ref.ptr,fa_res.len), "from address value");
// tester->assert_true(tester, ta_res.len == ta_ref.len, "to address len");
// tester->assert_false(tester, memcmp(ta_res.ptr, ta_ref.ptr,ta_res.len), "to address value");
//
// tester->assert_true(tester, fp_res == fp_ref, "from port");
// tester->assert_true(tester, tp_res == tp_ref, "to port");
//
// allocator_free(fa_res.ptr);
// allocator_free(fa_ref.ptr);
// allocator_free(ta_res.ptr);
// allocator_free(ta_ref.ptr);
// }
//
//
// /* destroy */
// ts_result[0]->destroy(ts_result[0]);
// ts_result[0]->destroy(ts_result[1]);
// ts_result[0]->destroy(ts_result[2]);
// allocator_free(ts_result);
//
// ts_policy[0]->destroy(ts_policy[0]);
// ts_policy[1]->destroy(ts_policy[1]);
// ts_policy[2]->destroy(ts_policy[2]);
// ts_request[0]->destroy(ts_request[0]);
// ts_reference[0]->destroy(ts_reference[0]);
// ts_request[1]->destroy(ts_request[1]);
// ts_reference[1]->destroy(ts_reference[1]);
// ts_request[2]->destroy(ts_request[2]);
// ts_reference[2]->destroy(ts_reference[2]);
// ts_request[3]->destroy(ts_request[3]);
policy->destroy(policy);
}
-42
View File
@@ -1,42 +0,0 @@
/**
* @file policy_test.h
*
* @brief Tests for the policy_t class.
*
*/
/*
* 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 SA_CONFIG_TEST_H_
#define SA_CONFIG_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the policy_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_policy(protected_tester_t *tester);
#endif /* SA_CONFIG_TEST_H_ */
-146
View File
@@ -1,146 +0,0 @@
/**
* @file prf_plus_test.h
*
* @brief Tests for the prf_plus_t class.
*
*/
/*
* 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 <string.h>
#include "prf_plus_test.h"
#include <transforms/prf_plus.h>
#include <utils/allocator.h>
/*
* described in Header-File
*/
void test_prf_plus(protected_tester_t *tester)
{
prf_plus_t *prf_plus;
prf_t *prf;
chunk_t key, seed;
u_int8_t buffer[10000];
int i;
u_int8_t key_bytes[] = {
0x01,0x02,0x03,0x04
};
u_int8_t seed_bytes[] = {
0x01,0x02,0x03,0x04
};
key.ptr = key_bytes;
key.len = sizeof(key_bytes);
seed.ptr = seed_bytes;
seed.len = sizeof(seed_bytes);
prf = prf_create(PRF_HMAC_SHA1);
prf->set_key(prf, key);
prf_plus = prf_plus_create(prf, seed);
for (i=0; i<100; i++)
{
prf_plus->get_bytes(prf_plus, i*i, buffer);
}
//tester->assert_true(tester, digest[3].len == 20, "chunk len append mode");
//tester->assert_false(tester, memcmp(digest[3].ptr, reference[3].ptr, 20), "prf_plus value append mode");
prf_plus->destroy(prf_plus);
prf->destroy(prf);
}
void test_prf_plus_md5(protected_tester_t *tester)
{
/* md5 test data
u_int8_t nonce[] = {
0x58,0xCC,0x4C,0xA3,0x81,0x81,0xDA,0x7D,
0x19,0xA6,0x9F,0xB1,0xE8,0xD3,0xE7,0x96,
0xC2,0x2A,0x6E,0xCB,0x09,0x43,0xDC,0x6E,
0x75,0x22,0x34,0xAE,0xF8,0x53,0x7F,0xEC,
0x00,0xC9,0xF6,0x1C,0x4A,0x39,0xB4,0x29,
0x23,0xD8,0x24,0x22,0x95,0x52,0x77,0x29
};
u_int8_t shared_key[] = {
0xC0,0xDB,0x75,0x0A,0x40,0xBE,0xE2,0x8C,0x68,0x3C,0xB4,0xAA,0xE7,0xA7,0x6E,0xCC,
0x2A,0x4B,0x9C,0x8E,0xC6,0x71,0xAD,0xF4,0xB7,0xC4,0xD6,0x53,0x41,0xB3,0x4A,0xE4,
0x0D,0xC2,0x0C,0x60,0x9F,0x93,0x9E,0x87,0x30,0xCC,0xDC,0x51,0x9F,0x94,0x91,0x5D,
0x31,0xE0,0x6E,0x22,0x3A,0x66,0x53,0xA6,0xD4,0x54,0x5E,0x71,0x61,0xA6,0x64,0x3B,
0x19,0x40,0x6E,0x6F,0x3B,0xE3,0x64,0x3F,0x3B,0x68,0xEB,0x8E,0x4B,0x2A,0x53,0xEC,
0xB0,0xB6,0x8E,0x5C,0x42,0xA1,0xC2,0x7F,0x4F,0x0B,0x7D,0xFC,0xF6,0x7E,0xF5,0xC0,
0xBA,0xA8,0xFB,0x13,0xEF,0xA8,0xBD,0x90,0x95,0x08,0x2C,0x81,0xA9,0xDA,0x7D,0x45,
0xDC,0x35,0x33,0x75,0xA8,0x4D,0xE2,0x34,0xA9,0x66,0x7F,0xAD,0x04,0x3A,0xE5,0x21
};
u_int8_t skeyseed[] = {
0xCD,0xC6,0xC0,0x68,
0x60,0xDF,0x0C,0xC2,
0x10,0xDB,0x0E,0xF7,
0x20,0x6E,0x6C,0xB1
};
u_int8_t sk_d[] = {
0xE1,0x74,0xA8,0x50,
0x14,0xDB,0x79,0x64,
0x92,0x3E,0x82,0x28,
0x48,0x75,0x64,0xE7
};
u_int8_t sk_ai[] = {
0xCA,0x19,0x73,0x69,
0x38,0x35,0x40,0xA6,
0xB1,0x98,0x4F,0x63,
0xE6,0xF9,0x66,0xFF
};
u_int8_t sk_ar[] = {
0x14,0x1D,0x0A,0xC2,
0x7B,0x1C,0x87,0xD2,
0x65,0xA5,0xEF,0x0C,
0x47,0xF4,0xCE,0xE2
};
u_int8_t sk_ei[] = {
0x52,0x50,0x7E,0xDA,
0x02,0x1D,0x8E,0xCF,
0x20,0xA3,0x67,0xA6,
0x4D,0xA0,0xAB,0x61
};
u_int8_t sk_er[] = {
0xB9,0x65,0x0A,0x3C,
0x30,0xA8,0x26,0x78,
0x60,0x5A,0x74,0xBB,
0x5C,0xC4,0xF8,0x71
};
u_int8_t sk_pi[] = {
0xDD,0x61,0xAB,0x53,
0xC8,0xDD,0x3A,0x44,
0xDA,0x47,0x09,0x9B,
0x3B,0xD2,0xBB,0xB6
};
u_int8_t sk_pr[] = {
0x18,0x75,0xE4,0xC6,
0x57,0xC4,0xDE,0x65,
0x10,0xEB,0xA7,0xB6,
0x24,0x0D,0xEC,0xB4
};*/
}
-38
View File
@@ -1,38 +0,0 @@
/**
* @file prf_plus_test.h
*
* @brief Tests for the prf_plus_t class.
*
*/
/*
* 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 PRF_PLUS_TEST_H_
#define PRF_PLUS_TEST_H_
#include <transforms/prf_plus.h>
#include <utils/tester.h>
/**
* @brief Test function used to test the prf_plus class.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_prf_plus(protected_tester_t *tester);
#endif /*PRF_PLUS_TEST_H_*/
-99
View File
@@ -1,99 +0,0 @@
/**
* @file proposal_test.c
*
* @brief Tests for the proposal_t class.
*
*/
/*
* 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 "proposal_test.h"
#include <daemon.h>
#include <config/proposal.h>
#include <utils/allocator.h>
#include <utils/logger.h>
/**
* Described in header.
*/
void test_proposal(protected_tester_t *tester)
{
proposal_t *proposal1, *proposal2, *proposal3;
iterator_t *iterator;
algorithm_t *algo;
bool result;
proposal1 = proposal_create(1);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3DES, 0);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 32);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
proposal1->add_algorithm(proposal1, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_BLOWFISH, 0);
proposal1->add_algorithm(proposal1, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 20);
proposal1->add_algorithm(proposal1, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
proposal1->add_algorithm(proposal1, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
proposal1->add_algorithm(proposal1, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_2048_BIT, 0);
proposal2 = proposal_create(2);
proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_3IDEA, 0);
proposal2->add_algorithm(proposal2, PROTO_ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
proposal2->add_algorithm(proposal2, PROTO_ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_MD5_96, 20);
proposal1->add_algorithm(proposal2, PROTO_AH, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
/* ah and esp prop */
proposal3 = proposal1->select(proposal1, proposal2);
tester->assert_false(tester, proposal3 == NULL, "proposal select");
if (proposal3)
{
result = proposal3->get_algorithm(proposal3, PROTO_ESP, ENCRYPTION_ALGORITHM, &algo);
tester->assert_true(tester, result, "encryption algo select");
tester->assert_true(tester, algo->algorithm == ENCR_AES_CBC, "encryption algo");
tester->assert_true(tester, algo->key_size == 16, "encryption keylen");
result = proposal3->get_algorithm(proposal3, PROTO_ESP, INTEGRITY_ALGORITHM, &algo);
tester->assert_true(tester, result, "integrity algo select");
tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo");
tester->assert_true(tester, algo->key_size == 20, "integrity keylen");
iterator = proposal3->create_algorithm_iterator(proposal3, PROTO_ESP, INTEGRITY_ALGORITHM);
tester->assert_false(tester, iterator == NULL, "integrity algo select");
while(iterator->has_next(iterator))
{
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == AUTH_HMAC_MD5_96, "integrity algo");
tester->assert_true(tester, algo->key_size == 20, "integrity keylen");
}
iterator->destroy(iterator);
iterator = proposal3->create_algorithm_iterator(proposal3, PROTO_AH, DIFFIE_HELLMAN_GROUP );
tester->assert_false(tester, iterator == NULL, "dh group algo select");
while(iterator->has_next(iterator))
{
iterator->current(iterator, (void**)&algo);
tester->assert_true(tester, algo->algorithm == MODP_1024_BIT, "dh group algo");
tester->assert_true(tester, algo->key_size == 0, "dh gorup keylen");
}
iterator->destroy(iterator);
proposal3->destroy(proposal3);
}
proposal1->destroy(proposal1);
proposal2->destroy(proposal2);
return;
}
-42
View File
@@ -1,42 +0,0 @@
/**
* @file proposal_test.h
*
* @brief Tests for the proposal_t class.
*
*/
/*
* 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 CHILD_PROPOSAL_TEST_H_
#define CHILD_PROPOSAL_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function used to test the proposal_t functionality.
*
* @param tester associated protected_tester_t object
*
* @ingroup testcases
*/
void test_proposal(protected_tester_t *tester);
#endif /* CHILD_PROPOSAL_TEST_H_ */
-90
View File
@@ -1,90 +0,0 @@
/**
* @file receiver_test.c
*
* @brief Tests for the receiver_t class.
*
*/
/*
* 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 <string.h>
#include <unistd.h>
#include "receiver_test.h"
#include <daemon.h>
#include <threads/receiver.h>
#include <network/packet.h>
#include <network/socket.h>
#include <queues/send_queue.h>
#include <queues/job_queue.h>
#include <queues/jobs/incoming_packet_job.h>
#include <encoding/payloads/encodings.h>
#include <utils/allocator.h>
/**
* Number of packets to send by sender-thread
*/
#define NUMBER_OF_PACKETS_TO_SEND 100
/**
* Port to send the packets to
*/
#define PORT_TO_SEND 4600
/**
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
void test_receiver(protected_tester_t *tester)
{
int i;
receiver_t *receiver;
packet_t *packet;
job_t *job;
packet_t *received_packet;
receiver = receiver_create();
chunk_t test_data;
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create();
packet->set_destination(packet, host_create(AF_INET,DESTINATION_IP,PORT_TO_SEND));
test_data.ptr = allocator_alloc_thing(int);
test_data.len = ( sizeof(int));
*((int *) (test_data.ptr)) = i;
packet->set_data(packet, test_data);
charon->socket->send(charon->socket, packet);
packet->destroy(packet);
}
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
job = charon->job_queue->get(charon->job_queue);
tester->assert_true(tester, (job->get_type(job) == INCOMING_PACKET), "job type check");
received_packet = ((incoming_packet_job_t *)(job))->get_packet((incoming_packet_job_t *)(job));
test_data = received_packet->get_data(received_packet);
tester->assert_true(tester, (test_data.len == (sizeof(int))), "received data length check");
tester->assert_true(tester, (i == *((int *)(test_data.ptr))), "received data value check");
received_packet->destroy(received_packet);
job->destroy(job);
}
receiver->destroy(receiver);
}
-37
View File
@@ -1,37 +0,0 @@
/**
* @file receiver_test.h
*
* @brief Tests for the receiver_t class.
*
*/
/*
* 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 RECEIVER_TEST_H_
#define RECEIVER_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function for the type receiver_t.
*
* @param tester tester object
*
* @ingroup testcases
*/
void test_receiver(protected_tester_t *tester);
#endif /*RECEIVER_TEST_H_*/
-227
View File
@@ -1,227 +0,0 @@
/**
* @file rsa_test.h
*
* @brief Tests for the hasher_t classes.
*
*/
/*
* 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 <string.h>
#include "rsa_test.h"
#include <daemon.h>
#include <utils/allocator.h>
#include <utils/logger.h>
#include <transforms/certificate.h>
char private_key_buffer[] = {
0x30,0x82,0x04,0xa2,0x02,0x00,0x02,0x82,0x01,0x00,0x6f,0x25,0x74,0x63,0x2a,0x2f,
0x5d,0xd4,0x54,0x03,0xbe,0xd5,0x34,0x71,0xe0,0x30,0x37,0xe5,0x2e,0x39,0xda,0xe7,
0x04,0xd4,0xe2,0x5b,0x43,0xc3,0x6a,0x50,0x61,0xe8,0x4b,0x5d,0x58,0x30,0xa4,0xcc,
0x6d,0xab,0xdf,0x8b,0x75,0x8c,0x22,0x43,0xd4,0xd0,0x18,0x5e,0x32,0x24,0xba,0x38,
0x6f,0xab,0x64,0x86,0x8f,0x54,0x40,0x77,0xcb,0x3a,0xb5,0x30,0xde,0xb4,0xcd,0x98,
0xbb,0xb1,0xdb,0x7a,0xd4,0xc7,0x0e,0xc7,0x99,0xc4,0x05,0xd5,0xa4,0x96,0x2a,0x3c,
0x71,0x0f,0x31,0xa4,0xcd,0xc2,0x15,0x28,0xec,0x16,0x02,0x28,0x61,0x5e,0x8e,0xcf,
0xb6,0x0b,0x8c,0x81,0x79,0x58,0xfc,0x9b,0x5b,0x32,0x26,0xcb,0xbc,0xf2,0xc9,0x8a,
0x76,0x26,0x4e,0x87,0xaa,0x1b,0xd4,0xa7,0xb3,0xcf,0x96,0x99,0x86,0xcc,0xcb,0x5e,
0xb2,0x66,0xc9,0xe0,0x10,0xbe,0xf7,0xd9,0x99,0xa3,0x49,0x5c,0x41,0x1f,0xa4,0xd0,
0xd0,0x48,0x77,0xad,0x0f,0xbc,0x2c,0x2a,0x29,0x34,0x3f,0x20,0xb5,0x15,0xa1,0xa7,
0x22,0xda,0x15,0xf3,0xf1,0x51,0x83,0x1f,0x3d,0x49,0x26,0x81,0x6d,0x65,0xa6,0x9c,
0x09,0x01,0xfa,0x10,0x26,0x76,0xec,0x46,0x77,0xa6,0xc1,0xf5,0xc7,0xa3,0x2d,0xf9,
0x60,0xa1,0x8f,0x94,0x17,0x58,0x0d,0xc9,0x55,0x50,0x2a,0xeb,0x44,0x5e,0xea,0x69,
0xc9,0x76,0x67,0x9c,0x8e,0xd1,0x9c,0x4f,0x9d,0x9e,0x0a,0xec,0x44,0x6b,0x7e,0x01,
0x2d,0x53,0xf2,0xd6,0x7c,0x27,0x30,0x3d,0x40,0x6c,0x3c,0xef,0x82,0xd1,0x7f,0xe2,
0xd2,0x9b,0xb6,0x96,0x08,0xd2,0xe0,0x8a,0x28,0xeb,0x02,0x03,0x01,0x00,0x01,0x02,
0x82,0x01,0x00,0x0b,0x89,0xcc,0x5c,0xd5,0x0e,0xc8,0xc3,0x57,0x9b,0x71,0xee,0xa9,
0x3c,0x9f,0x24,0xf2,0x50,0x88,0xed,0x79,0xa3,0x9c,0xf5,0x4a,0xb0,0x65,0xc6,0xfe,
0x1c,0xed,0x25,0x13,0xd9,0xd3,0x63,0x6d,0x60,0x49,0x8c,0x5b,0xaf,0x1b,0x1b,0x5a,
0x9d,0x47,0x14,0xf9,0x4a,0xa2,0x12,0xfd,0x00,0x09,0xdb,0xb5,0x9a,0x60,0x7b,0xc3,
0x1b,0x8c,0x8e,0x02,0x2c,0x5a,0x1a,0x53,0xf3,0xa4,0x9c,0x90,0xa7,0xde,0x39,0xf1,
0xf7,0x57,0xa7,0xa9,0x61,0x65,0xee,0x2e,0xe1,0x4a,0x6d,0x64,0xde,0x72,0x7b,0xd0,
0xfd,0x88,0x10,0xba,0xd5,0x9d,0x52,0x17,0x2a,0x4a,0x00,0x45,0xec,0x55,0x00,0x1f,
0x6d,0x33,0x58,0xef,0xfd,0x1b,0x96,0xea,0xc4,0x44,0x82,0xb2,0x89,0x53,0xe8,0x02,
0xba,0x0c,0x28,0xff,0xd1,0xda,0xdc,0xea,0xae,0x80,0xbe,0x33,0x86,0xbc,0x38,0xe9,
0x1c,0xa9,0x39,0xc5,0x28,0x14,0x53,0x5a,0x52,0x3e,0xff,0xb8,0xc6,0x77,0x7c,0xe2,
0xf9,0x50,0x9a,0x58,0x46,0x4e,0xdf,0x11,0x0f,0x4d,0x70,0xf3,0xe7,0xe7,0x9a,0x8a,
0x9f,0x58,0x05,0x54,0xda,0x60,0x52,0xec,0xa8,0x10,0x60,0x9c,0x83,0xf0,0xd7,0x15,
0xaf,0xf9,0x44,0xe8,0x3e,0x68,0xb2,0x06,0xa5,0x6d,0x6d,0xc1,0x8d,0x55,0xa3,0x6e,
0x7e,0xe4,0x86,0x2a,0x6e,0x23,0xe0,0xf5,0xe6,0x08,0x05,0xb5,0x1a,0x6d,0x9c,0xf4,
0xbd,0x18,0x20,0x58,0x43,0x67,0x72,0xde,0x47,0x56,0xee,0x94,0xc6,0x70,0xc1,0xda,
0x15,0x2a,0xb9,0xb7,0x6a,0x10,0xc4,0x02,0x6e,0xae,0x93,0xe8,0x5e,0x8f,0x55,0x80,
0x4e,0x9a,0x75,0x02,0x81,0x81,0x00,0xc4,0x25,0x05,0xab,0x8d,0x6b,0xa0,0xac,0x82,
0x44,0xe2,0x13,0x06,0x2e,0x1c,0x7b,0x6b,0x37,0x69,0x93,0x9e,0x33,0x41,0xb1,0xf0,
0x54,0x6e,0xe1,0x52,0x98,0x83,0x36,0x2b,0xe4,0x86,0x85,0x19,0x53,0x1f,0xd7,0x2f,
0xbb,0x76,0xef,0x8d,0xb1,0x42,0xd3,0xfc,0xba,0xc7,0xb6,0xe4,0x73,0x42,0x83,0x1d,
0x08,0xf9,0x17,0x83,0xd3,0xb7,0xe7,0xb4,0x26,0x74,0x59,0xb6,0x07,0xe1,0x1f,0x97,
0x1e,0x66,0x77,0xe2,0x7a,0x3e,0xb2,0x43,0x2a,0x60,0x34,0xa6,0x2e,0x4a,0x13,0xb9,
0x4f,0xc3,0x64,0xc5,0xee,0x04,0x40,0xf4,0xa5,0x01,0x45,0xba,0x9e,0x09,0x22,0xd9,
0x99,0x0c,0x0e,0x23,0xd9,0x43,0x8b,0x01,0x1a,0x3f,0xd4,0xa8,0x8d,0x9a,0xfc,0x9c,
0x05,0x1d,0x6d,0x7b,0x18,0xe0,0x95,0x02,0x81,0x81,0x00,0x91,0x10,0x4b,0x84,0xdc,
0x10,0x67,0x22,0x84,0x60,0x96,0x2e,0x11,0x1a,0xe9,0x1c,0xb7,0x2f,0xa4,0x4c,0xf4,
0xd0,0x57,0xa2,0x4b,0xbc,0xa2,0x02,0x0f,0x33,0x1b,0x1f,0x19,0x19,0x68,0x8d,0xb6,
0x8a,0x36,0xe3,0xeb,0x2c,0x8c,0xba,0x69,0xb4,0x17,0x97,0xfe,0x0b,0x76,0x2a,0x97,
0x87,0x0c,0xdf,0x1e,0x7a,0xbc,0xc0,0x86,0x27,0x31,0xb9,0x9d,0xc2,0xf2,0xb7,0xcc,
0x83,0x6a,0x5a,0xa1,0xab,0x05,0x60,0xa0,0x04,0x90,0xe2,0xc4,0x03,0xb4,0xd8,0x30,
0xaa,0x93,0xd8,0x90,0x4e,0x3c,0x33,0x1f,0x43,0xa2,0x3a,0x2c,0x34,0xb9,0x01,0x89,
0xbb,0xdc,0x0b,0x2e,0x4f,0x89,0x1b,0xf8,0x77,0x4c,0x4c,0x25,0xc5,0xca,0x38,0x00,
0xd4,0x3a,0xaa,0x7c,0xf6,0xb6,0xad,0x69,0x0d,0x03,0x7f,0x02,0x81,0x81,0x00,0xa3,
0xcc,0xef,0x21,0x46,0xe6,0xdc,0xb5,0x73,0xcc,0xa6,0xa7,0x90,0x7f,0xad,0x95,0x7c,
0x02,0x38,0x8e,0xe8,0x8c,0x91,0x8e,0x51,0xcf,0x91,0x11,0x66,0x72,0xab,0x10,0xf0,
0x32,0xd6,0x0c,0x0d,0x0c,0x18,0x09,0x12,0x79,0x91,0x67,0x98,0x82,0xb1,0xf6,0x6a,
0x96,0x68,0xf6,0x59,0x6d,0xcf,0xdb,0xc2,0xc1,0x9d,0x93,0x7f,0xa9,0xad,0x69,0x38,
0x4e,0xec,0xd7,0x86,0x66,0xaa,0x20,0x41,0x89,0x47,0xb5,0x52,0x53,0x18,0x4c,0xb2,
0x3e,0x8f,0x3d,0x28,0x92,0x7b,0x96,0x61,0x29,0x35,0x59,0xd0,0xd9,0x66,0x80,0x00,
0x4e,0x53,0xf3,0xb1,0x57,0x0c,0xf6,0x27,0x95,0xe2,0x35,0x64,0xc6,0xa9,0xdb,0x49,
0xbe,0x6c,0x13,0xe1,0xf6,0xef,0xb9,0x89,0x69,0xd4,0x1b,0x7b,0xb3,0x58,0xc9,0x02,
0x81,0x80,0x40,0x28,0x3d,0xce,0x37,0xea,0x05,0x43,0x2d,0xda,0xed,0xf0,0xd7,0xdd,
0xd8,0x05,0xbc,0x3b,0x14,0xe6,0x78,0x4c,0x00,0xc6,0x25,0xca,0xfa,0xb8,0x00,0x72,
0xf0,0xe6,0xd3,0x19,0xfa,0xb4,0xda,0x6b,0xcc,0x95,0x06,0xf9,0x00,0x10,0x9e,0x19,
0x69,0x69,0xee,0x90,0xb1,0x25,0x6b,0x38,0xee,0x87,0x6b,0x9a,0x8b,0x0a,0x77,0x0a,
0xb4,0xa2,0x4c,0x54,0xe1,0x36,0x4a,0xfc,0x40,0x38,0x6f,0x52,0x0d,0x21,0xcc,0x03,
0xd8,0xf4,0x82,0x0e,0xc5,0x97,0xec,0x06,0x35,0x37,0x4d,0xb3,0x5c,0x4a,0x9b,0xe4,
0x34,0xc6,0x97,0xb0,0x85,0xb6,0x59,0x6d,0x3d,0x87,0xb0,0x66,0xba,0xd4,0x25,0x12,
0xd6,0x2a,0xc3,0x75,0xf3,0xd6,0xca,0xff,0x12,0x27,0x3e,0xf7,0x7a,0x99,0xbd,0x61,
0x65,0x0f,0x02,0x81,0x81,0x00,0xb2,0xcb,0x21,0xf9,0x77,0x44,0x20,0xee,0xe9,0x60,
0xf2,0x32,0x7e,0xd0,0xb2,0x8b,0xa7,0x96,0x20,0x20,0xf2,0x88,0xbd,0xbe,0x1f,0x92,
0x59,0x26,0x7c,0x26,0x64,0x13,0xfc,0x9a,0x1c,0xd6,0x48,0xbf,0xe3,0xad,0x2d,0x89,
0xd4,0x11,0x9b,0xed,0x38,0x99,0x3e,0xf4,0xe3,0x54,0xa3,0x0c,0x2a,0x91,0xdc,0xf9,
0x38,0x94,0xbe,0xd7,0x90,0xc2,0x8d,0xcc,0x5a,0x28,0xbd,0x46,0x4e,0xd7,0x86,0x52,
0x95,0xb1,0x39,0xb9,0x30,0x33,0x1f,0xe8,0xe7,0x37,0xfe,0x37,0xa5,0x20,0x82,0x1a,
0xfd,0xc3,0x30,0xd0,0xdc,0x8d,0x71,0x66,0x30,0xb4,0x9a,0xb2,0xd6,0x03,0xfe,0xc5,
0x4b,0xfd,0xd2,0x1b,0x3e,0x4e,0xc6,0xb0,0xe8,0x6c,0x83,0x44,0x6b,0xaa,0x05,0x51,
0xd3,0xb2,0x04,0xca,0xf6,0xf3,
};
char public_key_buffer[] = {
// 0x30,0x82,0x01,0x21,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,
// 0x01,0x05,0x00,0x03,0x82,0x01,0x0e,0x00,
0x30,0x82,0x01,0x09,0x02,0x82,0x01,0x00,
0x6f,0x25,0x74,0x63,0x2a,0x2f,0x5d,0xd4,0x54,0x03,0xbe,0xd5,0x34,0x71,0xe0,0x30,
0x37,0xe5,0x2e,0x39,0xda,0xe7,0x04,0xd4,0xe2,0x5b,0x43,0xc3,0x6a,0x50,0x61,0xe8,
0x4b,0x5d,0x58,0x30,0xa4,0xcc,0x6d,0xab,0xdf,0x8b,0x75,0x8c,0x22,0x43,0xd4,0xd0,
0x18,0x5e,0x32,0x24,0xba,0x38,0x6f,0xab,0x64,0x86,0x8f,0x54,0x40,0x77,0xcb,0x3a,
0xb5,0x30,0xde,0xb4,0xcd,0x98,0xbb,0xb1,0xdb,0x7a,0xd4,0xc7,0x0e,0xc7,0x99,0xc4,
0x05,0xd5,0xa4,0x96,0x2a,0x3c,0x71,0x0f,0x31,0xa4,0xcd,0xc2,0x15,0x28,0xec,0x16,
0x02,0x28,0x61,0x5e,0x8e,0xcf,0xb6,0x0b,0x8c,0x81,0x79,0x58,0xfc,0x9b,0x5b,0x32,
0x26,0xcb,0xbc,0xf2,0xc9,0x8a,0x76,0x26,0x4e,0x87,0xaa,0x1b,0xd4,0xa7,0xb3,0xcf,
0x96,0x99,0x86,0xcc,0xcb,0x5e,0xb2,0x66,0xc9,0xe0,0x10,0xbe,0xf7,0xd9,0x99,0xa3,
0x49,0x5c,0x41,0x1f,0xa4,0xd0,0xd0,0x48,0x77,0xad,0x0f,0xbc,0x2c,0x2a,0x29,0x34,
0x3f,0x20,0xb5,0x15,0xa1,0xa7,0x22,0xda,0x15,0xf3,0xf1,0x51,0x83,0x1f,0x3d,0x49,
0x26,0x81,0x6d,0x65,0xa6,0x9c,0x09,0x01,0xfa,0x10,0x26,0x76,0xec,0x46,0x77,0xa6,
0xc1,0xf5,0xc7,0xa3,0x2d,0xf9,0x60,0xa1,0x8f,0x94,0x17,0x58,0x0d,0xc9,0x55,0x50,
0x2a,0xeb,0x44,0x5e,0xea,0x69,0xc9,0x76,0x67,0x9c,0x8e,0xd1,0x9c,0x4f,0x9d,0x9e,
0x0a,0xec,0x44,0x6b,0x7e,0x01,0x2d,0x53,0xf2,0xd6,0x7c,0x27,0x30,0x3d,0x40,0x6c,
0x3c,0xef,0x82,0xd1,0x7f,0xe2,0xd2,0x9b,0xb6,0x96,0x08,0xd2,0xe0,0x8a,0x28,0xeb,
0x02,0x03,0x01,0x00,0x01
};
/*
* described in Header-File
*/
void test_rsa(protected_tester_t *tester)
{
rsa_private_key_t *private_key;
rsa_public_key_t *public_key;
certificate_t *certificate;
chunk_t data, signature;
chunk_t der_private_key = {private_key_buffer, sizeof(private_key_buffer)};
chunk_t der_public_key = {public_key_buffer, sizeof(public_key_buffer)};
logger_t *logger;
status_t status;
u_int8_t test_data[] = {
0x01,0x02,0x03,0x04,
0x11,0x12,0x13,0x14,
0x21,0x22,0x23,0x24,
0x31,0x32,0x33,0x34,
0x41,0x42,0x43,0x44,
0x51,0x52,0x53,0x54,
0x61,0x62,0x63,0x64,
0x71,0x72,0x73,0x74,
0x81,0x82,0x83,0x84,
};
data.ptr = test_data;
data.len = sizeof(test_data);
logger = charon->logger_manager->get_logger(charon->logger_manager, TESTER);
logger->disable_level(logger, FULL);
/* key generation and signing */
// private_key = rsa_private_key_create(512);
// tester->assert_true(tester, private_key != NULL, "generating private key");
//
// status = private_key->build_emsa_pkcs1_signature(private_key, HASH_MD5, data, &signature);
// tester->assert_true(tester, status == SUCCESS, "build emsa_pkcs1_signature (genkey)");
//
// public_key = private_key->get_public_key(private_key);
// tester->assert_true(tester, public_key != NULL, "extracting public key");
//
// status = public_key->verify_emsa_pkcs1_signature(public_key, data, signature);
// tester->assert_true(tester, status == SUCCESS, "verify emsa_pkcs1_signature (genkey)");
//
// allocator_free(signature.ptr);
//
// private_key->destroy(private_key);
// public_key->destroy(public_key);
/* key setting */
private_key = rsa_private_key_create_from_chunk(der_private_key);
tester->assert_true(tester, private_key != NULL, "loading private key from chunk");
public_key = rsa_public_key_create_from_chunk(der_public_key);
tester->assert_true(tester, public_key != NULL, "loading public key from chunk");
status = private_key->build_emsa_pkcs1_signature(private_key, HASH_MD5, data, &signature);
tester->assert_true(tester, status == SUCCESS, "build emsa_pkcs1_signature (setkey)");
status = public_key->verify_emsa_pkcs1_signature(public_key, data, signature);
tester->assert_true(tester, status == SUCCESS, "verify emsa_pkcs1_signature (setkey)");
allocator_free(signature.ptr);
/* key comparison */
tester->assert_true(tester, private_key->belongs_to(private_key, public_key), "key belongs to");
private_key->destroy(private_key);
private_key = rsa_private_key_create(512);
tester->assert_false(tester, private_key->belongs_to(private_key, public_key), "key belongs not to");
public_key->destroy(public_key);
private_key->destroy(private_key);
/* key loading */
private_key = rsa_private_key_create_from_file("alice.der", NULL);
tester->assert_true(tester, private_key != NULL, "loading private key from file");
certificate = certificate_create_from_file("alice-cert.der");
tester->assert_true(tester, public_key != NULL, "loading certificate from file");
public_key = certificate->get_public_key(certificate);
tester->assert_true(tester, public_key != NULL, "loading public key from certificate");
tester->assert_true(tester, private_key->belongs_to(private_key, public_key), "key belongs to");
status = private_key->build_emsa_pkcs1_signature(private_key, HASH_SHA1, data, &signature);
tester->assert_true(tester, status == SUCCESS, "build emsa_pkcs1_signature (loadkey)");
status = public_key->verify_emsa_pkcs1_signature(public_key, data, signature);
tester->assert_true(tester, status == SUCCESS, "verify emsa_pkcs1_signature (loadkey)");
allocator_free(signature.ptr);
certificate->destroy(certificate);
public_key->destroy(public_key);
private_key->destroy(private_key);
}
-41
View File
@@ -1,41 +0,0 @@
/**
* @file rsa_test.h
*
* @brief Tests for the rsa_public_key_t and rsa_private_key classes.
*
*/
/*
* 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 RSA_TEST_H
#define RSA_TEST_H
#include <transforms/rsa/rsa_public_key.h>
#include <transforms/rsa/rsa_private_key.h>
#include <utils/tester.h>
/**
* @brief Test function used to test the rsa functionality.
*
* @param tester associated tester object
*
* @ingroup testcases
*/
void test_rsa(protected_tester_t *tester);
#endif /*RSA_TEST_H*/
-92
View File
@@ -1,92 +0,0 @@
/**
* @file scheduler_test.c
*
* @brief Tests for the scheduler_t class.
*
*/
/*
* 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 <string.h>
#include <unistd.h>
#include "scheduler_test.h"
#include <daemon.h>
#include <threads/scheduler.h>
#include <queues/event_queue.h>
#include <queues/job_queue.h>
#include <queues/jobs/incoming_packet_job.h>
/**
* @brief implementation of a scheduler test
*
* This one uses relative time events, which are not that exact.
* Test may fail on too slow machines.
*/
void test_scheduler(protected_tester_t *tester)
{
int job_count = 5;
job_t *jobs[job_count];
int current;
scheduler_t *scheduler = scheduler_create();
/* schedule 5 jobs */
for (current = 0; current < job_count; current++)
{
/* misusing for testing only */
jobs[current] = (job_t *) incoming_packet_job_create((packet_t*)(current+1));
charon->event_queue->add_relative(charon->event_queue, jobs[current], (current+1) * 500);
}
for (current = 0; current < job_count; current++)
{
jobs[current] = NULL;
}
usleep(50 * 1000);
/* check if times are correct */
for (current = 0; current < job_count; current++)
{
usleep(400 * 1000);
tester->assert_true(tester, (charon->job_queue->get_count(charon->job_queue) == current ), "job-queue size before event");
tester->assert_true(tester, (charon->event_queue->get_count(charon->event_queue) == job_count - current), "event-queue size before event");
usleep(100 * 1000);
tester->assert_true(tester, (charon->job_queue->get_count(charon->job_queue) == current + 1), "job-queue size after event");
tester->assert_true(tester, (charon->event_queue->get_count(charon->event_queue) == job_count - current - 1), "event-queue size after event");
}
/* check job order */
for (current = 0; current < job_count; current++)
{
jobs[current] = charon->job_queue->get(charon->job_queue);
incoming_packet_job_t *current_job;
current_job = (incoming_packet_job_t*) jobs[current];
packet_t *packet;
packet = current_job->get_packet(current_job);
tester->assert_true(tester, (((int)packet) == current+1), "job order");
jobs[current]->destroy(jobs[current]);
}
/* destruction test */
scheduler->destroy(scheduler);
}
-37
View File
@@ -1,37 +0,0 @@
/**
* @file scheduler_test.h
*
* @brief Tests for the scheduler_t class.
*
*/
/*
* 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 SCHEDULER_TEST_H_
#define SCHEDULER_TEST_H_
#include <utils/tester.h>
/**
* @brief Test function for the type scheduler_t.
*
* @param tester tester object
*
* @ingroup testcases
*/
void test_scheduler(protected_tester_t *tester);
#endif /*SCHEDULER_TEST_H_*/

Some files were not shown because too many files have changed in this diff Show More