proposal: Print all algorithms even those with currently unknown transform types
This commit is contained in:
@@ -73,13 +73,31 @@ struct private_proposal_t {
|
|||||||
u_int number;
|
u_int number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a hack to not change the previous order when printing proposals
|
||||||
|
*/
|
||||||
|
static transform_type_t type_for_sort(const void *type)
|
||||||
|
{
|
||||||
|
const transform_type_t *t = type;
|
||||||
|
|
||||||
|
switch (*t)
|
||||||
|
{
|
||||||
|
case PSEUDO_RANDOM_FUNCTION:
|
||||||
|
return INTEGRITY_ALGORITHM;
|
||||||
|
case INTEGRITY_ALGORITHM:
|
||||||
|
return PSEUDO_RANDOM_FUNCTION;
|
||||||
|
default:
|
||||||
|
return *t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort transform types
|
* Sort transform types
|
||||||
*/
|
*/
|
||||||
static int type_sort(const void *a, const void *b, void *user)
|
static int type_sort(const void *a, const void *b, void *user)
|
||||||
{
|
{
|
||||||
const transform_type_t *ta = a, *tb = b;
|
transform_type_t ta = type_for_sort(a), tb = type_for_sort(b);
|
||||||
return *ta - *tb;
|
return ta - tb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -724,30 +742,44 @@ static bool add_string_algo(private_proposal_t *this, const char *alg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print all algorithms of a kind to buffer
|
* Print all algorithms of the given type
|
||||||
*/
|
*/
|
||||||
static int print_alg(private_proposal_t *this, printf_hook_data_t *data,
|
static int print_alg(private_proposal_t *this, printf_hook_data_t *data,
|
||||||
u_int kind, void *names, bool *first)
|
transform_type_t type, bool *first)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
uint16_t alg, size;
|
entry_t *entry;
|
||||||
|
enum_name_t *names;
|
||||||
|
|
||||||
enumerator = create_enumerator(this, kind);
|
names = transform_get_enum_names(type);
|
||||||
while (enumerator->enumerate(enumerator, &alg, &size))
|
|
||||||
|
enumerator = array_create_enumerator(this->transforms);
|
||||||
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
|
char *prefix = "/";
|
||||||
|
|
||||||
|
if (type != entry->type)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (*first)
|
if (*first)
|
||||||
{
|
{
|
||||||
written += print_in_hook(data, "%N", names, alg);
|
prefix = "";
|
||||||
*first = FALSE;
|
*first = FALSE;
|
||||||
}
|
}
|
||||||
|
if (names)
|
||||||
|
{
|
||||||
|
written += print_in_hook(data, "%s%N", prefix, names, entry->alg);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
written += print_in_hook(data, "/%N", names, alg);
|
written += print_in_hook(data, "%sUNKNOWN_%u_%u", prefix,
|
||||||
|
entry->type, entry->alg);
|
||||||
}
|
}
|
||||||
if (size)
|
if (entry->key_size)
|
||||||
{
|
{
|
||||||
written += print_in_hook(data, "_%u", size);
|
written += print_in_hook(data, "_%u", entry->key_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
@@ -763,6 +795,7 @@ int proposal_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
|||||||
private_proposal_t *this = *((private_proposal_t**)(args[0]));
|
private_proposal_t *this = *((private_proposal_t**)(args[0]));
|
||||||
linked_list_t *list = *((linked_list_t**)(args[0]));
|
linked_list_t *list = *((linked_list_t**)(args[0]));
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
transform_type_t *type;
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
bool first = TRUE;
|
bool first = TRUE;
|
||||||
|
|
||||||
@@ -791,16 +824,12 @@ int proposal_printf_hook(printf_hook_data_t *data, printf_hook_spec_t *spec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
written = print_in_hook(data, "%N:", protocol_id_names, this->protocol);
|
written = print_in_hook(data, "%N:", protocol_id_names, this->protocol);
|
||||||
written += print_alg(this, data, ENCRYPTION_ALGORITHM,
|
enumerator = array_create_enumerator(this->types);
|
||||||
encryption_algorithm_names, &first);
|
while (enumerator->enumerate(enumerator, &type))
|
||||||
written += print_alg(this, data, INTEGRITY_ALGORITHM,
|
{
|
||||||
integrity_algorithm_names, &first);
|
written += print_alg(this, data, *type, &first);
|
||||||
written += print_alg(this, data, PSEUDO_RANDOM_FUNCTION,
|
}
|
||||||
pseudo_random_function_names, &first);
|
enumerator->destroy(enumerator);
|
||||||
written += print_alg(this, data, DIFFIE_HELLMAN_GROUP,
|
|
||||||
diffie_hellman_group_names, &first);
|
|
||||||
written += print_alg(this, data, EXTENDED_SEQUENCE_NUMBERS,
|
|
||||||
extended_sequence_numbers_names, &first);
|
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,24 @@ START_TEST(test_promote_dh_group_not_contained)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(test_unknown_transform_types_print)
|
||||||
|
{
|
||||||
|
proposal_t *proposal;
|
||||||
|
|
||||||
|
proposal = proposal_create(PROTO_IKE, 0);
|
||||||
|
proposal->add_algorithm(proposal, 242, 42, 128);
|
||||||
|
assert_proposal_eq(proposal, "IKE:UNKNOWN_242_42_128");
|
||||||
|
proposal->destroy(proposal);
|
||||||
|
|
||||||
|
proposal = proposal_create_from_string(PROTO_IKE,
|
||||||
|
"aes128-sha256-modp3072-ecp256");
|
||||||
|
proposal->add_algorithm(proposal, 242, 42, 128);
|
||||||
|
proposal->add_algorithm(proposal, 243, 1, 0);
|
||||||
|
assert_proposal_eq(proposal, "IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072/ECP_256/UNKNOWN_242_42_128/UNKNOWN_243_1");
|
||||||
|
proposal->destroy(proposal);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
Suite *proposal_suite_create()
|
Suite *proposal_suite_create()
|
||||||
{
|
{
|
||||||
Suite *s;
|
Suite *s;
|
||||||
@@ -216,5 +234,9 @@ Suite *proposal_suite_create()
|
|||||||
tcase_add_test(tc, test_promote_dh_group_not_contained);
|
tcase_add_test(tc, test_promote_dh_group_not_contained);
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
|
tc = tcase_create("unknown transform types");
|
||||||
|
tcase_add_test(tc, test_unknown_transform_types_print);
|
||||||
|
suite_add_tcase(s, tc);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user