proposal: Move proposal_t from libcharon to libstrongswan
This allows us to use it without having to initialize libcharon, which was required for the logging (we probably could have included debug.h instead of daemon.h to workaround that but this seems more correct).
This commit is contained in:
@@ -16,7 +16,6 @@ config/backend_manager.c config/backend_manager.h config/backend.h \
|
||||
config/child_cfg.c config/child_cfg.h \
|
||||
config/ike_cfg.c config/ike_cfg.h \
|
||||
config/peer_cfg.c config/peer_cfg.h \
|
||||
config/proposal.c config/proposal.h \
|
||||
control/controller.c control/controller.h \
|
||||
daemon.c daemon.h \
|
||||
encoding/generator.c encoding/generator.h \
|
||||
|
||||
@@ -14,7 +14,6 @@ config/backend_manager.c config/backend_manager.h config/backend.h \
|
||||
config/child_cfg.c config/child_cfg.h \
|
||||
config/ike_cfg.c config/ike_cfg.h \
|
||||
config/peer_cfg.c config/peer_cfg.h \
|
||||
config/proposal.c config/proposal.h \
|
||||
control/controller.c control/controller.h \
|
||||
daemon.c daemon.h \
|
||||
encoding/generator.c encoding/generator.h \
|
||||
|
||||
@@ -31,7 +31,7 @@ typedef struct child_cfg_create_t child_cfg_create_t;
|
||||
|
||||
#include <library.h>
|
||||
#include <selectors/traffic_selector.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
#include <kernel/kernel_ipsec.h>
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ typedef struct ike_cfg_t ike_cfg_t;
|
||||
#include <networking/host.h>
|
||||
#include <collections/linked_list.h>
|
||||
#include <utils/identification.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
#include <crypto/diffie_hellman.h>
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,7 @@ typedef struct peer_cfg_create_t peer_cfg_create_t;
|
||||
#include <utils/identification.h>
|
||||
#include <collections/enumerator.h>
|
||||
#include <selectors/traffic_selector.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
#include <config/ike_cfg.h>
|
||||
#include <config/child_cfg.h>
|
||||
#include <credentials/auth_cfg.h>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2016 Tobias Brunner
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* HSR 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup proposal proposal
|
||||
* @{ @ingroup config
|
||||
*/
|
||||
|
||||
#ifndef PROPOSAL_H_
|
||||
#define PROPOSAL_H_
|
||||
|
||||
typedef enum protocol_id_t protocol_id_t;
|
||||
typedef enum extended_sequence_numbers_t extended_sequence_numbers_t;
|
||||
typedef struct proposal_t proposal_t;
|
||||
|
||||
#include <library.h>
|
||||
#include <utils/identification.h>
|
||||
#include <collections/linked_list.h>
|
||||
#include <networking/host.h>
|
||||
#include <crypto/transform.h>
|
||||
#include <crypto/crypters/crypter.h>
|
||||
#include <crypto/signers/signer.h>
|
||||
#include <crypto/diffie_hellman.h>
|
||||
#include <selectors/traffic_selector.h>
|
||||
|
||||
/**
|
||||
* Protocol ID of a proposal.
|
||||
*/
|
||||
enum protocol_id_t {
|
||||
PROTO_NONE = 0,
|
||||
PROTO_IKE = 1,
|
||||
PROTO_AH = 2,
|
||||
PROTO_ESP = 3,
|
||||
PROTO_IPCOMP = 4, /* IKEv1 only */
|
||||
};
|
||||
|
||||
/**
|
||||
* enum names for protocol_id_t
|
||||
*/
|
||||
extern enum_name_t *protocol_id_names;
|
||||
|
||||
/**
|
||||
* Stores a set of algorithms used for an SA.
|
||||
*
|
||||
* A proposal stores algorithms for a specific
|
||||
* protocol. It can store algorithms for one protocol.
|
||||
* Proposals with multiple protocols are not supported,
|
||||
* as it's not specified in RFC4301 anymore.
|
||||
*/
|
||||
struct proposal_t {
|
||||
|
||||
/**
|
||||
* Add an algorithm to the proposal.
|
||||
*
|
||||
* The algorithms are stored by priority, first added
|
||||
* is the most preferred.
|
||||
* Key size is only needed for encryption algorithms
|
||||
* with variable key size (such as AES). Must be set
|
||||
* to zero if key size is not specified.
|
||||
* The alg parameter accepts encryption_algorithm_t,
|
||||
* integrity_algorithm_t, dh_group_number_t and
|
||||
* extended_sequence_numbers_t.
|
||||
*
|
||||
* @param type kind of algorithm
|
||||
* @param alg identifier for algorithm
|
||||
* @param key_size key size to use
|
||||
*/
|
||||
void (*add_algorithm) (proposal_t *this, transform_type_t type,
|
||||
uint16_t alg, uint16_t key_size);
|
||||
|
||||
/**
|
||||
* Get an enumerator over algorithms for a specific algo type.
|
||||
*
|
||||
* @param type kind of algorithm
|
||||
* @return enumerator over uint16_t alg, uint16_t key_size
|
||||
*/
|
||||
enumerator_t *(*create_enumerator) (proposal_t *this, transform_type_t type);
|
||||
|
||||
/**
|
||||
* Get the algorithm for a type to use.
|
||||
*
|
||||
* If there are multiple algorithms, only the first is returned.
|
||||
*
|
||||
* @param type kind of algorithm
|
||||
* @param alg pointer which receives algorithm
|
||||
* @param key_size pointer which receives the key size
|
||||
* @return TRUE if algorithm of this kind available
|
||||
*/
|
||||
bool (*get_algorithm) (proposal_t *this, transform_type_t type,
|
||||
uint16_t *alg, uint16_t *key_size);
|
||||
|
||||
/**
|
||||
* Check if the proposal has a specific DH group.
|
||||
*
|
||||
* @param group group to check for
|
||||
* @return TRUE if algorithm included
|
||||
*/
|
||||
bool (*has_dh_group) (proposal_t *this, diffie_hellman_group_t group);
|
||||
|
||||
/**
|
||||
* Strip DH groups from proposal to use it without PFS.
|
||||
*
|
||||
* @param keep group to keep (MODP_NONE to remove all)
|
||||
*/
|
||||
void (*strip_dh)(proposal_t *this, diffie_hellman_group_t keep);
|
||||
|
||||
/**
|
||||
* Compare two proposal, and select a matching subset.
|
||||
*
|
||||
* If the proposals are for the same protocols (AH/ESP), they are
|
||||
* compared. If they have at least one algorithm of each type
|
||||
* in common, a resulting proposal of this kind is created.
|
||||
*
|
||||
* @param other proposal to compare against
|
||||
* @param other_remote whether other is the remote proposal from which to
|
||||
* copy SPI and proposal number to the result,
|
||||
* otherwise copy from this proposal
|
||||
* @param private accepts algorithms allocated in a private range
|
||||
* @return selected proposal, NULL if proposals don't match
|
||||
*/
|
||||
proposal_t *(*select)(proposal_t *this, proposal_t *other,
|
||||
bool other_remote, bool private);
|
||||
|
||||
/**
|
||||
* Get the protocol ID of the proposal.
|
||||
*
|
||||
* @return protocol of the proposal
|
||||
*/
|
||||
protocol_id_t (*get_protocol) (proposal_t *this);
|
||||
|
||||
/**
|
||||
* Get the SPI of the proposal.
|
||||
*
|
||||
* @return spi for proto
|
||||
*/
|
||||
uint64_t (*get_spi) (proposal_t *this);
|
||||
|
||||
/**
|
||||
* Set the SPI of the proposal.
|
||||
*
|
||||
* @param spi spi to set for proto
|
||||
*/
|
||||
void (*set_spi) (proposal_t *this, uint64_t spi);
|
||||
|
||||
/**
|
||||
* Get the proposal number, as encoded in SA payload
|
||||
*
|
||||
* @return proposal number
|
||||
*/
|
||||
u_int (*get_number)(proposal_t *this);
|
||||
|
||||
/**
|
||||
* Check for the eqality of two proposals.
|
||||
*
|
||||
* @param other other proposal to check for equality
|
||||
* @return TRUE if other equal to this
|
||||
*/
|
||||
bool (*equals)(proposal_t *this, proposal_t *other);
|
||||
|
||||
/**
|
||||
* Clone a proposal.
|
||||
*
|
||||
* @return clone of proposal
|
||||
*/
|
||||
proposal_t *(*clone) (proposal_t *this);
|
||||
|
||||
/**
|
||||
* Destroys the proposal object.
|
||||
*/
|
||||
void (*destroy) (proposal_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a child proposal for AH, ESP or IKE.
|
||||
*
|
||||
* @param protocol protocol, such as PROTO_ESP
|
||||
* @param number proposal number, as encoded in SA payload
|
||||
* @return proposal_t object
|
||||
*/
|
||||
proposal_t *proposal_create(protocol_id_t protocol, u_int number);
|
||||
|
||||
/**
|
||||
* Create a default proposal if nothing further specified.
|
||||
*
|
||||
* @param protocol protocol, such as PROTO_ESP
|
||||
* @return proposal_t object
|
||||
*/
|
||||
proposal_t *proposal_create_default(protocol_id_t protocol);
|
||||
|
||||
/**
|
||||
* Create a default proposal for supported AEAD algorithms
|
||||
*
|
||||
* @param protocol protocol, such as PROTO_ESP
|
||||
* @return proposal_t object, NULL if none supported
|
||||
*/
|
||||
proposal_t *proposal_create_default_aead(protocol_id_t protocol);
|
||||
|
||||
/**
|
||||
* Create a proposal from a string identifying the algorithms.
|
||||
*
|
||||
* The string is in the same form as a in the ipsec.conf file.
|
||||
* E.g.: aes128-sha2_256-modp2048
|
||||
* 3des-md5
|
||||
* An additional '!' at the end of the string forces this proposal,
|
||||
* without it the peer may choose another algorithm we support.
|
||||
*
|
||||
* @param protocol protocol, such as PROTO_ESP
|
||||
* @param algs algorithms as string
|
||||
* @return proposal_t object
|
||||
*/
|
||||
proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs);
|
||||
|
||||
/**
|
||||
* printf hook function for proposal_t.
|
||||
*
|
||||
* Arguments are:
|
||||
* proposal_t *proposal
|
||||
* With the #-specifier, arguments are:
|
||||
* linked_list_t *list containing proposal_t*
|
||||
*/
|
||||
int proposal_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
||||
const void *const *args);
|
||||
|
||||
#endif /** PROPOSAL_H_ @}*/
|
||||
@@ -55,7 +55,6 @@
|
||||
#include <bus/listeners/sys_logger.h>
|
||||
#include <bus/listeners/file_logger.h>
|
||||
#include <collections/array.h>
|
||||
#include <config/proposal.h>
|
||||
#include <plugins/plugin_feature.h>
|
||||
#include <kernel/kernel_handler.h>
|
||||
#include <processing/jobs/start_action_job.h>
|
||||
@@ -989,11 +988,6 @@ bool libcharon_init()
|
||||
dbg_old = dbg;
|
||||
dbg = dbg_bus;
|
||||
|
||||
lib->printf_hook->add_handler(lib->printf_hook, 'P',
|
||||
proposal_printf_hook,
|
||||
PRINTF_HOOK_ARGTYPE_POINTER,
|
||||
PRINTF_HOOK_ARGTYPE_END);
|
||||
|
||||
if (lib->integrity &&
|
||||
!lib->integrity->check(lib->integrity, "libcharon", libcharon_init))
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct proposal_substructure_t proposal_substructure_t;
|
||||
#include <library.h>
|
||||
#include <encoding/payloads/payload.h>
|
||||
#include <encoding/payloads/transform_substructure.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
#include <collections/linked_list.h>
|
||||
#include <kernel/kernel_ipsec.h>
|
||||
#include <sa/authenticator.h>
|
||||
|
||||
@@ -32,7 +32,7 @@ typedef struct transform_substructure_t transform_substructure_t;
|
||||
#include <crypto/signers/signer.h>
|
||||
#include <crypto/prfs/prf.h>
|
||||
#include <crypto/crypters/crypter.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
|
||||
/**
|
||||
* IKEv1 Value for a transform payload.
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef struct delete_child_sa_job_t delete_child_sa_job_t;
|
||||
#include <library.h>
|
||||
#include <sa/ike_sa_id.h>
|
||||
#include <processing/jobs/job.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef struct rekey_child_sa_job_t rekey_child_sa_job_t;
|
||||
#include <library.h>
|
||||
#include <sa/ike_sa_id.h>
|
||||
#include <processing/jobs/job.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
|
||||
/**
|
||||
* Class representing an REKEY_CHILD_SA Job.
|
||||
@@ -50,4 +50,5 @@ struct rekey_child_sa_job_t {
|
||||
*/
|
||||
rekey_child_sa_job_t *rekey_child_sa_job_create(protocol_id_t protocol,
|
||||
uint32_t spi, host_t *dst);
|
||||
|
||||
#endif /** REKEY_CHILD_SA_JOB_H_ @}*/
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef struct update_sa_job_t update_sa_job_t;
|
||||
#include <library.h>
|
||||
#include <networking/host.h>
|
||||
#include <processing/jobs/job.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
|
||||
/**
|
||||
* Update the addresses of an IKE and its CHILD_SAs.
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef struct child_sa_t child_sa_t;
|
||||
#include <library.h>
|
||||
#include <crypto/prf_plus.h>
|
||||
#include <encoding/payloads/proposal_substructure.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
#include <config/child_cfg.h>
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef struct keymat_t keymat_t;
|
||||
#include <utils/identification.h>
|
||||
#include <crypto/prfs/prf.h>
|
||||
#include <crypto/aead.h>
|
||||
#include <config/proposal.h>
|
||||
#include <crypto/proposal/proposal.h>
|
||||
#include <config/peer_cfg.h>
|
||||
#include <sa/ike_sa_id.h>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ TESTS = libcharon_tests exchange_tests
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
libcharon_tests_SOURCES = \
|
||||
suites/test_proposal.c \
|
||||
suites/test_ike_cfg.c \
|
||||
suites/test_mem_pool.c \
|
||||
suites/test_message_chapoly.c \
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* @ingroup libcharon-tests
|
||||
*/
|
||||
|
||||
TEST_SUITE(proposal_suite_create)
|
||||
TEST_SUITE(ike_cfg_suite_create)
|
||||
TEST_SUITE(mem_pool_suite_create)
|
||||
TEST_SUITE_DEPEND(message_chapoly_suite_create, AEAD, ENCR_CHACHA20_POLY1305, 32)
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Tobias Brunner
|
||||
* HSR 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 "test_suite.h"
|
||||
|
||||
#include <config/proposal.h>
|
||||
|
||||
static struct {
|
||||
protocol_id_t proto;
|
||||
char *proposal;
|
||||
char *expected;
|
||||
} create_data[] = {
|
||||
{ PROTO_IKE, "", NULL },
|
||||
{ PROTO_IKE, "sha256", NULL },
|
||||
{ PROTO_IKE, "sha256-modp3072", NULL },
|
||||
{ PROTO_IKE, "null-sha256-modp3072", "IKE:NULL/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072" },
|
||||
{ PROTO_IKE, "aes128", NULL },
|
||||
{ PROTO_IKE, "aes128-sha256", NULL },
|
||||
{ PROTO_IKE, "aes128-sha256-modpnone", NULL },
|
||||
{ PROTO_IKE, "aes128-sha256-modp3072", "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072" },
|
||||
{ PROTO_IKE, "aes128-sha256-prfsha384-modp3072", "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_384/MODP_3072" },
|
||||
{ PROTO_IKE, "aes128gcm16-modp3072", NULL },
|
||||
{ PROTO_IKE, "aes128gcm16-prfsha256-modp3072", "IKE:AES_GCM_16_128/PRF_HMAC_SHA2_256/MODP_3072" },
|
||||
{ PROTO_IKE, "aes128gcm16-sha256-modp3072", "IKE:AES_GCM_16_128/PRF_HMAC_SHA2_256/MODP_3072" },
|
||||
{ PROTO_IKE, "aes128gcm16-aes128-modp3072", NULL },
|
||||
{ PROTO_IKE, "aes128gcm16-aes128-sha256-modp3072", NULL },
|
||||
{ PROTO_ESP, "", NULL },
|
||||
{ PROTO_ESP, "sha256", NULL },
|
||||
{ PROTO_ESP, "aes128-sha256", "ESP:AES_CBC_128/HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_ESP, "aes128-sha256-esn", "ESP:AES_CBC_128/HMAC_SHA2_256_128/EXT_SEQ" },
|
||||
{ PROTO_ESP, "aes128-sha256-noesn", "ESP:AES_CBC_128/HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_ESP, "aes128-sha256-esn-noesn", "ESP:AES_CBC_128/HMAC_SHA2_256_128/EXT_SEQ/NO_EXT_SEQ" },
|
||||
{ PROTO_ESP, "aes128-sha256-prfsha256-modp3072", "ESP:AES_CBC_128/HMAC_SHA2_256_128/MODP_3072/NO_EXT_SEQ" },
|
||||
{ PROTO_ESP, "aes128gcm16-aes128-sha256-modp3072", NULL },
|
||||
{ PROTO_ESP, "aes128gmac", "ESP:NULL_AES_GMAC_128/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "", NULL },
|
||||
{ PROTO_AH, "aes128", NULL },
|
||||
{ PROTO_AH, "aes128-sha256", "AH:HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "sha256-sha1", "AH:HMAC_SHA2_256_128/HMAC_SHA1_96/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "aes128gmac-sha256", "AH:AES_128_GMAC/HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "aes128gmac-sha256-prfsha256", "AH:AES_128_GMAC/HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "aes128gmac-aes256gmac-aes128-sha256", "AH:AES_128_GMAC/AES_256_GMAC/HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "sha256-esn", "AH:HMAC_SHA2_256_128/EXT_SEQ" },
|
||||
{ PROTO_AH, "sha256-noesn", "AH:HMAC_SHA2_256_128/NO_EXT_SEQ" },
|
||||
{ PROTO_AH, "sha256-esn-noesn", "AH:HMAC_SHA2_256_128/EXT_SEQ/NO_EXT_SEQ" },
|
||||
};
|
||||
|
||||
START_TEST(test_create_from_string)
|
||||
{
|
||||
proposal_t *proposal;
|
||||
char str[BUF_LEN];
|
||||
|
||||
proposal = proposal_create_from_string(create_data[_i].proto,
|
||||
create_data[_i].proposal);
|
||||
if (!create_data[_i].expected)
|
||||
{
|
||||
ck_assert(!proposal);
|
||||
return;
|
||||
}
|
||||
snprintf(str, sizeof(str), "%P", proposal);
|
||||
ck_assert_str_eq(create_data[_i].expected, str);
|
||||
proposal->destroy(proposal);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static struct {
|
||||
protocol_id_t proto;
|
||||
char *self;
|
||||
char *other;
|
||||
char *expected;
|
||||
} select_data[] = {
|
||||
{ PROTO_ESP, "aes128", "aes128", "aes128" },
|
||||
{ PROTO_ESP, "aes128", "aes256", NULL },
|
||||
{ PROTO_ESP, "aes128-aes256", "aes256-aes128", "aes128" },
|
||||
{ PROTO_ESP, "aes256-aes128", "aes128-aes256", "aes256" },
|
||||
{ PROTO_ESP, "aes128-aes256-sha1-sha256", "aes256-aes128-sha256-sha1", "aes128-sha1" },
|
||||
{ PROTO_ESP, "aes256-aes128-sha256-sha1", "aes128-aes256-sha1-sha256", "aes256-sha256" },
|
||||
{ PROTO_ESP, "aes128-sha256-modp3072", "aes128-sha256", NULL },
|
||||
{ PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072", NULL },
|
||||
{ PROTO_ESP, "aes128-sha256-modp3072", "aes128-sha256-modpnone", NULL },
|
||||
{ PROTO_ESP, "aes128-sha256-modpnone", "aes128-sha256-modp3072", NULL },
|
||||
{ PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256", "aes128-sha256" },
|
||||
{ PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072-modpnone", "aes128-sha256" },
|
||||
{ PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072" },
|
||||
{ PROTO_ESP, "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone" },
|
||||
{ PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072", "aes128-sha256-modp3072" },
|
||||
{ PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072" },
|
||||
{ PROTO_IKE, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072", "aes128-sha256-modp3072" },
|
||||
};
|
||||
|
||||
START_TEST(test_select)
|
||||
{
|
||||
proposal_t *self, *other, *selected, *expected;
|
||||
|
||||
self = proposal_create_from_string(select_data[_i].proto,
|
||||
select_data[_i].self);
|
||||
other = proposal_create_from_string(select_data[_i].proto,
|
||||
select_data[_i].other);
|
||||
selected = self->select(self, other, TRUE, FALSE);
|
||||
if (select_data[_i].expected)
|
||||
{
|
||||
expected = proposal_create_from_string(select_data[_i].proto,
|
||||
select_data[_i].expected);
|
||||
ck_assert(selected);
|
||||
ck_assert_msg(expected->equals(expected, selected), "proposal %P does "
|
||||
"not match expected %P", selected, expected);
|
||||
expected->destroy(expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
ck_assert(!selected);
|
||||
}
|
||||
DESTROY_IF(selected);
|
||||
other->destroy(other);
|
||||
self->destroy(self);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_select_spi)
|
||||
{
|
||||
proposal_t *self, *other, *selected;
|
||||
|
||||
self = proposal_create_from_string(PROTO_ESP, "aes128-sha256-modp3072");
|
||||
other = proposal_create_from_string(PROTO_ESP, "aes128-sha256-modp3072");
|
||||
other->set_spi(other, 0x12345678);
|
||||
|
||||
selected = self->select(self, other, TRUE, FALSE);
|
||||
ck_assert(selected);
|
||||
ck_assert_int_eq(selected->get_spi(selected), other->get_spi(other));
|
||||
selected->destroy(selected);
|
||||
|
||||
selected = self->select(self, other, FALSE, FALSE);
|
||||
ck_assert(selected);
|
||||
ck_assert_int_eq(selected->get_spi(selected), self->get_spi(self));
|
||||
selected->destroy(selected);
|
||||
|
||||
other->destroy(other);
|
||||
self->destroy(self);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Suite *proposal_suite_create()
|
||||
{
|
||||
Suite *s;
|
||||
TCase *tc;
|
||||
|
||||
s = suite_create("proposal");
|
||||
|
||||
tc = tcase_create("create_from_string");
|
||||
tcase_add_loop_test(tc, test_create_from_string, 0, countof(create_data));
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("select");
|
||||
tcase_add_loop_test(tc, test_select, 0, countof(select_data));
|
||||
tcase_add_test(tc, test_select_spi);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user