diff options
author | Martin Willi <martin@strongswan.org> | 2006-02-06 14:05:35 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2006-02-06 14:05:35 +0000 |
commit | 384efc76d58eea98648988045de413a6cc027dff (patch) | |
tree | 81aea82f04bde1f61c5dcfa3b3f50325dbe03ac7 /Source/charon/encoding | |
parent | 19f78a6fed6e966721e9e310099dbfa79489f9d9 (diff) | |
download | strongswan-384efc76d58eea98648988045de413a6cc027dff.tar.bz2 strongswan-384efc76d58eea98648988045de413a6cc027dff.tar.xz |
- dead end implementation
Diffstat (limited to 'Source/charon/encoding')
6 files changed, 116 insertions, 118 deletions
diff --git a/Source/charon/encoding/payloads/proposal_substructure.c b/Source/charon/encoding/payloads/proposal_substructure.c index 7ca81e3ef..00e093234 100644 --- a/Source/charon/encoding/payloads/proposal_substructure.c +++ b/Source/charon/encoding/payloads/proposal_substructure.c @@ -37,17 +37,6 @@ */ #define PROPOSAL_TYPE_VALUE 2 -/** - * String mappings for protocol_id_t. - */ -mapping_t protocol_id_m[] = { - {UNDEFINED_PROTOCOL_ID, "UNDEFINED_PROTOCOL_ID"}, - {IKE, "IKE"}, - {AH, "AH"}, - {ESP, "ESP"}, - {MAPPING_END, NULL} -}; - typedef struct private_proposal_substructure_t private_proposal_substructure_t; @@ -413,7 +402,7 @@ static size_t get_transform_count (private_proposal_substructure_t *this) */ static size_t get_spi_size (private_proposal_substructure_t *this) { - return this->spi.len; + return this->spi.len; } /** @@ -499,6 +488,7 @@ proposal_substructure_t *proposal_substructure_create() this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_type; this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; + /* public functions */ this->public.create_transform_substructure_iterator = (iterator_t* (*) (proposal_substructure_t *,bool)) create_transform_substructure_iterator; this->public.add_transform_substructure = (void (*) (proposal_substructure_t *,transform_substructure_t *)) add_transform_substructure; @@ -529,8 +519,65 @@ proposal_substructure_t *proposal_substructure_create() this->spi_size = 0; this->spi.ptr = NULL; this->spi.len = 0; - + this->transforms = linked_list_create(); - + return (&(this->public)); } + +/* + * Described in header. + */ +proposal_substructure_t *proposal_substructure_create_from_child_proposal(child_proposal_t *proposal, protocol_id_t *proto) +{ + private_proposal_substructure_t *this = (private_proposal_substructure_t*)proposal_substructure_create(); + iterator_t *iterator; + algorithm_t *algo; + transform_substructure_t *transform; + + /* encryption algorithm is only availble in ESP */ + if (proto == ESP) + { + iterator = proposal->create_algorithm_iterator(proposal, proto, ENCRYPTION_ALGORITHM); + while (iterator->has_next(iterator)) + { + iterator->current(iterator, (void**)&algo); + transform = transform_substructure_create_type(ENCRYPTION_ALGORITHM, algo->algorithm, algo->key_size); + this->public.add_transform_substructure(&(this->public), transform); + } + iterator->destroy(iterator); + } + + /* integrity algorithms */ + iterator = proposal->create_algorithm_iterator(proposal, proto, INTEGRITY_ALGORITHM); + while (iterator->has_next(iterator)) + { + algorithm_t *algo; + iterator->current(iterator, (void**)&algo); + transform = transform_substructure_create_type(INTEGRITY_ALGORITHM, algo->algorithm, algo->key_size); + this->public.add_transform_substructure(&(this->public), transform); + } + iterator->destroy(iterator); + + /* dh groups */ + iterator = proposal->create_algorithm_iterator(proposal, proto, DIFFIE_HELLMAN_GROUP); + while (iterator->has_next(iterator)) + { + algorithm_t *algo; + iterator->current(iterator, (void**)&algo); + transform = transform_substructure_create_type(DIFFIE_HELLMAN_GROUP, algo->algorithm, 0); + this->public.add_transform_substructure(&(this->public), transform); + } + iterator->destroy(iterator); + + /* extended sequence numbers */ + iterator = proposal->create_algorithm_iterator(proposal, proto, EXTENDED_SEQUENCE_NUMBERS); + while (iterator->has_next(iterator)) + { + algorithm_t *algo; + iterator->current(iterator, (void**)&algo); + transform = transform_substructure_create_type(EXTENDED_SEQUENCE_NUMBERS, algo->algorithm, 0); + this->public.add_transform_substructure(&(this->public), transform); + } + iterator->destroy(iterator); +} diff --git a/Source/charon/encoding/payloads/proposal_substructure.h b/Source/charon/encoding/payloads/proposal_substructure.h index 5380d1c65..afa58516b 100644 --- a/Source/charon/encoding/payloads/proposal_substructure.h +++ b/Source/charon/encoding/payloads/proposal_substructure.h @@ -26,6 +26,7 @@ #include <types.h> #include <encoding/payloads/payload.h> #include <encoding/payloads/transform_substructure.h> +#include <config/child_proposal.h> #include <utils/linked_list.h> @@ -37,27 +38,6 @@ #define PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH 8 -typedef enum protocol_id_t protocol_id_t; - -/** - * Protocol ID of a proposal. - * - * @ingroup payloads - */ -enum protocol_id_t { - UNDEFINED_PROTOCOL_ID = 201, - IKE = 1, - AH = 2, - ESP = 3, -}; - -/** - * String mappings for protocol_id_t. - * - * @ingroup payloads - */ -extern mapping_t protocol_id_m[]; - typedef struct proposal_substructure_t proposal_substructure_t; /** @@ -218,5 +198,22 @@ struct proposal_substructure_t { */ proposal_substructure_t *proposal_substructure_create(); +/** + * @brief Creates a proposal substructure from a child_proposal. + * + * Since a child proposal may contain data for both AH and ESP, + * the protocol must be specified. If the proposal does not contain + * data for proto, NULL is returned. Call twice, once with AH, once + * with ESP, with the same proposal to build the two substructures + * for it. + * + * @param proposal proposal to build a substruct out of it + * @param proto for which protocol the substructure should be built + * @return proposal_substructure_t object, or NULL + * + * @ingroup payloads + */ +proposal_substructure_t *proposal_substructure_create_from_child_proposal(child_proposal_t *proposal, protocol_id_t proto); + #endif /*PROPOSAL_SUBSTRUCTURE_H_*/ diff --git a/Source/charon/encoding/payloads/sa_payload.c b/Source/charon/encoding/payloads/sa_payload.c index 1ef67a2c9..b433d67ac 100644 --- a/Source/charon/encoding/payloads/sa_payload.c +++ b/Source/charon/encoding/payloads/sa_payload.c @@ -258,6 +258,34 @@ static void add_proposal_substructure (private_sa_payload_t *this,proposal_subst } /** + * Implementation of sa_payload_t.add_child_proposal. + */ +static void add_child_proposal(private_sa_payload_t *this, child_proposal_t *proposal) +{ + proposal_substructure_t *substructure; + protocol_id_t proto; + + /* watch out to build the substructures in the right order */ + proto = proposal->get_first_protocol(proposal); + if (proto != AH && proto != ESP) + { + return; + } + substructure = proposal_substructure_create_from_child_proposal(proposal, proto); + add_proposal_substructure(this, substructure); + + /* first is done, now do the (possible) other */ + proto = proposal->get_second_protocol(proposal); + if (proto != AH && proto != ESP) + { + return; + } + substructure = proposal_substructure_create_from_child_proposal(proposal, proto); + add_proposal_substructure(this, substructure); +} + + +/** * Implementation of sa_payload_t.get_ike_proposals. */ static status_t get_ike_proposals (private_sa_payload_t *this,ike_proposal_t ** proposals, size_t *proposal_count) @@ -267,7 +295,6 @@ static status_t get_ike_proposals (private_sa_payload_t *this,ike_proposal_t ** iterator_t *iterator; ike_proposal_t *tmp_proposals; - iterator = this->proposals->create_iterator(this->proposals,TRUE); /* first find out the number of ike proposals and check their number of transforms and diff --git a/Source/charon/encoding/payloads/sa_payload.h b/Source/charon/encoding/payloads/sa_payload.h index 8c4f5d530..90f57b760 100644 --- a/Source/charon/encoding/payloads/sa_payload.h +++ b/Source/charon/encoding/payloads/sa_payload.h @@ -119,7 +119,14 @@ struct sa_payload_t { * - FAILED if a proposal does not contain all needed transforms */ status_t (*get_child_proposals) (sa_payload_t *this, child_proposal_t **proposals, size_t *proposal_count); - + + /** + * @brief Add a child proposal (AH/ESP) to the payload. + * + * @param proposal child proposal to add to the payload + */ + void (*add_child_proposal) (sa_payload_t *this, child_proposal_t *proposal); + /** * @brief Destroys an sa_payload_t object. * @@ -149,20 +156,5 @@ sa_payload_t *sa_payload_create(); */ sa_payload_t *sa_payload_create_from_ike_proposals(ike_proposal_t *proposals, size_t proposal_count); -/** - * @brief Creates a sa_payload_t object from array of child_proposal_t's. - * - * @warning for proposals where AH and ESP is not set, an empty proposal is created. - * - * - * @return created sa_payload_t object - * @param proposals pointer to first proposal in array of type child_proposal_t - * @param proposal_count number of child_proposal_t's in array - * @return sa_payload_t object - * - * @ingroup payloads - */ -sa_payload_t *sa_payload_create_from_child_proposals(child_proposal_t *proposals, size_t proposal_count); - #endif /*SA_PAYLOAD_H_*/ diff --git a/Source/charon/encoding/payloads/transform_substructure.c b/Source/charon/encoding/payloads/transform_substructure.c index c519c6777..ba064c506 100644 --- a/Source/charon/encoding/payloads/transform_substructure.c +++ b/Source/charon/encoding/payloads/transform_substructure.c @@ -80,29 +80,6 @@ struct private_transform_substructure_t { }; -/** - * String mappings for transform_type_t. - */ -mapping_t transform_type_m[] = { - {UNDEFINED_TRANSFORM_TYPE, "UNDEFINED_TRANSFORM_TYPE"}, - {ENCRYPTION_ALGORITHM, "ENCRYPTION_ALGORITHM"}, - {PSEUDO_RANDOM_FUNCTION, "PSEUDO_RANDOM_FUNCTION"}, - {INTEGRITY_ALGORITHM, "INTEGRITY_ALGORITHM"}, - {DIFFIE_HELLMAN_GROUP, "DIFFIE_HELLMAN_GROUP"}, - {EXTENDED_SEQUENCE_NUMBERS, "EXTENDED_SEQUENCE_NUMBERS"}, - {MAPPING_END, NULL} -}; - - -/** - * String mappings for extended_sequence_numbers_t. - */ -mapping_t extended_sequence_numbers_m[] = { - {NO_EXT_SEQ_NUMBERS, "NO_EXT_SEQ_NUMBERS"}, - {EXT_SEQ_NUMBERS, "EXT_SEQ_NUMBERS"}, - {MAPPING_END, NULL} -}; - /** * Encoding rules to parse or generate a Transform substructure. * diff --git a/Source/charon/encoding/payloads/transform_substructure.h b/Source/charon/encoding/payloads/transform_substructure.h index cd5cffe7b..79dd101d0 100644 --- a/Source/charon/encoding/payloads/transform_substructure.h +++ b/Source/charon/encoding/payloads/transform_substructure.h @@ -32,6 +32,7 @@ #include <transforms/signers/signer.h> #include <transforms/prfs/prf.h> #include <transforms/crypters/crypter.h> +#include <config/child_proposal.h> /** @@ -49,49 +50,6 @@ #define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8 -typedef enum transform_type_t transform_type_t; - -/** - * Type of a transform, as in IKEv2 draft 3.3.2. - * - * @ingroup payloads - */ -enum transform_type_t { - UNDEFINED_TRANSFORM_TYPE = 241, - ENCRYPTION_ALGORITHM = 1, - PSEUDO_RANDOM_FUNCTION = 2, - INTEGRITY_ALGORITHM = 3, - DIFFIE_HELLMAN_GROUP = 4, - EXTENDED_SEQUENCE_NUMBERS = 5 -}; - -/** - * String mappings for transform_type_t. - * - * @ingroup payloads - */ -extern mapping_t transform_type_m[]; - - -typedef enum extended_sequence_numbers_t extended_sequence_numbers_t; - -/** - * Extended sequence numbers, as in IKEv2 draft 3.3.2. - * - * @ingroup payloads - */ -enum extended_sequence_numbers_t { - NO_EXT_SEQ_NUMBERS = 0, - EXT_SEQ_NUMBERS = 1 -}; - -/** - * String mappings for extended_sequence_numbers_t. - * - * @ingroup payloads - */ -extern mapping_t extended_sequence_numbers_m[]; - typedef struct transform_substructure_t transform_substructure_t; /** |