diff options
Diffstat (limited to 'Source/charon/encoding')
4 files changed, 106 insertions, 3 deletions
diff --git a/Source/charon/encoding/payloads/proposal_substructure.c b/Source/charon/encoding/payloads/proposal_substructure.c index ab575d425..b16fb9a85 100644 --- a/Source/charon/encoding/payloads/proposal_substructure.c +++ b/Source/charon/encoding/payloads/proposal_substructure.c @@ -327,6 +327,41 @@ static chunk_t get_spi (private_proposal_substructure_t *this) return spi; } +static status_t get_info_for_transform_type (private_proposal_substructure_t *this,transform_type_t type, u_int16_t *transform_id, u_int16_t *key_length) +{ + iterator_t *iterator; + status_t status; + u_int16_t found_transform_id; + u_int16_t found_key_length; + + status = this->transforms->create_iterator(this->transforms,&iterator,TRUE); + if (status != SUCCESS) + { + return status; + } + while (iterator->has_next(iterator)) + { + transform_substructure_t *current_transform; + status = iterator->current(iterator,(void **) ¤t_transform); + if (status != SUCCESS) + { + break; + } + if (current_transform->get_transform_type(current_transform) == type) + { + /* now get data for specific type */ + found_transform_id = current_transform->get_transform_id(current_transform); + status = current_transform->get_key_length(current_transform,&found_key_length); + *transform_id = found_transform_id; + *key_length = found_key_length; + iterator->destroy(iterator); + return status; + } + } + iterator->destroy(iterator); + return FAILED; +} + /** * Implements private_proposal_substructure_t's compute_length function. * See #private_proposal_substructure_s.compute_length for description. @@ -483,11 +518,13 @@ proposal_substructure_t *proposal_substructure_create() this->public.get_proposal_number = (u_int8_t (*) (proposal_substructure_t *)) get_proposal_number; this->public.set_protocol_id = (status_t (*) (proposal_substructure_t *,u_int8_t))set_protocol_id; this->public.get_protocol_id = (u_int8_t (*) (proposal_substructure_t *)) get_protocol_id; + this->public.get_info_for_transform_type = (status_t (*) (proposal_substructure_t *,transform_type_t,u_int16_t *, u_int16_t *))get_info_for_transform_type; this->public.set_spi = (status_t (*) (proposal_substructure_t *,chunk_t))set_spi; this->public.get_spi = (chunk_t (*) (proposal_substructure_t *)) get_spi; this->public.clone = (status_t (*) (proposal_substructure_t *, proposal_substructure_t **)) clone; this->public.destroy = (status_t (*) (proposal_substructure_t *)) destroy; + /* private functions */ this->compute_length = compute_length; diff --git a/Source/charon/encoding/payloads/proposal_substructure.h b/Source/charon/encoding/payloads/proposal_substructure.h index d6f90e403..ae54ef1d1 100644 --- a/Source/charon/encoding/payloads/proposal_substructure.h +++ b/Source/charon/encoding/payloads/proposal_substructure.h @@ -125,6 +125,21 @@ struct proposal_substructure_t { * @return protocol id of current proposal substructure. */ u_int8_t (*get_protocol_id) (proposal_substructure_t *this); + + /** + * @brief Get informations for a specific transform type. + * + * @param this calling proposal_substructure_t object + * @param type type to get informations for + * @param transform_id transform id of the specific type + * @param key_length key length of the specific key length transform attribute + * @return + * - SUCCESS if transform type is part of this proposal and + * all data (incl. key length) could be fetched + * - FAILED if transform type is not part of this proposal + * - OUT_OF_RES + */ + status_t (*get_info_for_transform_type) (proposal_substructure_t *this,transform_type_t type, u_int16_t *transform_id, u_int16_t *key_length); /** diff --git a/Source/charon/encoding/payloads/transform_substructure.c b/Source/charon/encoding/payloads/transform_substructure.c index 586ce2867..ff08f6c00 100644 --- a/Source/charon/encoding/payloads/transform_substructure.c +++ b/Source/charon/encoding/payloads/transform_substructure.c @@ -91,7 +91,7 @@ mapping_t transform_type_m[] = { {UNDEFINED_TRANSFORM_TYPE, "UNDEFINED_TRANSFORM_TYPE"}, {ENCRYPTION_ALGORITHM, "ENCRYPTION_ALGORITHM"}, {PSEUDO_RANDOM_FUNCTION, "PSEUDO_RANDOM_FUNCTION"}, - {INTEGRITIY_ALGORITHM, "INTEGRITIY_ALGORITHM"}, + {INTEGRITY_ALGORITHM, "INTEGRITY_ALGORITHM"}, {DIFFIE_HELLMAN_GROUP, "DIFFIE_HELLMAN_GROUP"}, {EXTENDED_SEQUENCE_NUNBERS, "EXTENDED_SEQUENCE_NUNBERS"}, {MAPPING_END, NULL} @@ -177,7 +177,7 @@ static status_t verify(private_transform_substructure_t *this) } break; } - case INTEGRITIY_ALGORITHM: + case INTEGRITY_ALGORITHM: { if ((this->transform_id < AUTH_HMAC_MD5_96) || (this->transform_id > AUTH_AES_XCBC_96)) { @@ -443,6 +443,43 @@ static status_t clone(private_transform_substructure_t *this,transform_substruct /** + * Implementation of transform_substructure_t.get_key_length. + */ +static status_t get_key_length(private_transform_substructure_t *this, u_int16_t *key_length) +{ + iterator_t *attributes; + status_t status; + + status = this->attributes->create_iterator(this->attributes,&attributes,TRUE); + if (status != SUCCESS) + { + return status; + } + + while (attributes->has_next(attributes)) + { + transform_attribute_t *current_attribute; + status = attributes->current(attributes,(void **) ¤t_attribute); + if (status != SUCCESS) + { + attributes->destroy(attributes); + return status; + } + if (current_attribute->get_attribute_type(current_attribute) == KEY_LENGTH) + { + *key_length = current_attribute->get_value(current_attribute); + attributes->destroy(attributes); + return SUCCESS; + } + + } + attributes->destroy(attributes); + + return FAILED; +} + + +/** * Implements payload_t's and transform_substructure_t's destroy function. * See #payload_s.destroy or transform_substructure_s.destroy for description. */ @@ -494,6 +531,7 @@ transform_substructure_t *transform_substructure_create() this->public.get_transform_type = (u_int8_t (*) (transform_substructure_t *)) get_transform_type; this->public.set_transform_id = (status_t (*) (transform_substructure_t *,u_int16_t)) set_transform_id; this->public.get_transform_id = (u_int16_t (*) (transform_substructure_t *)) get_transform_id; + this->public.get_key_length = (status_t (*) (transform_substructure_t *,u_int16_t *)) get_key_length; this->public.clone = (status_t (*) (transform_substructure_t *,transform_substructure_t **)) clone; this->public.destroy = (status_t (*) (transform_substructure_t *)) destroy; diff --git a/Source/charon/encoding/payloads/transform_substructure.h b/Source/charon/encoding/payloads/transform_substructure.h index 8d49874db..51119d275 100644 --- a/Source/charon/encoding/payloads/transform_substructure.h +++ b/Source/charon/encoding/payloads/transform_substructure.h @@ -56,7 +56,7 @@ enum transform_type_t { UNDEFINED_TRANSFORM_TYPE = 241, ENCRYPTION_ALGORITHM = 1, PSEUDO_RANDOM_FUNCTION = 2, - INTEGRITIY_ALGORITHM = 3, + INTEGRITY_ALGORITHM = 3, DIFFIE_HELLMAN_GROUP = 4, EXTENDED_SEQUENCE_NUNBERS = 5 }; @@ -180,6 +180,19 @@ struct transform_substructure_t { * @return Transform id of current transform substructure. */ u_int16_t (*get_transform_id) (transform_substructure_t *this); + + /** + * @brief get transform id of the current transform. + * + * @param this calling transform_substructure_t object + * @param key_length The key length is written to this location + * @return + * - SUCCESS if a key length attribute is contained + * - FAILED if no key length attribute is part of this + * transform or key length uses more then 16 bit! + * - OUT_OF_RES + */ + status_t (*get_key_length) (transform_substructure_t *this,u_int16_t *key_length); /** * @brief Clones an transform_substructure_t object. |