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
*/
static int type_sort(const void *a, const void *b, void *user)
{
- const transform_type_t *ta = a, *tb = b;
- return *ta - *tb;
+ transform_type_t ta = type_for_sort(a), tb = type_for_sort(b);
+ return ta - tb;
}
/**
}
/**
- * 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,
- u_int kind, void *names, bool *first)
+ transform_type_t type, bool *first)
{
enumerator_t *enumerator;
size_t written = 0;
- uint16_t alg, size;
+ entry_t *entry;
+ enum_name_t *names;
- enumerator = create_enumerator(this, kind);
- while (enumerator->enumerate(enumerator, &alg, &size))
+ names = transform_get_enum_names(type);
+
+ enumerator = array_create_enumerator(this->transforms);
+ while (enumerator->enumerate(enumerator, &entry))
{
+ char *prefix = "/";
+
+ if (type != entry->type)
+ {
+ continue;
+ }
if (*first)
{
- written += print_in_hook(data, "%N", names, alg);
+ prefix = "";
*first = FALSE;
}
+ if (names)
+ {
+ written += print_in_hook(data, "%s%N", prefix, names, entry->alg);
+ }
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);
private_proposal_t *this = *((private_proposal_t**)(args[0]));
linked_list_t *list = *((linked_list_t**)(args[0]));
enumerator_t *enumerator;
+ transform_type_t *type;
size_t written = 0;
bool first = TRUE;
}
written = print_in_hook(data, "%N:", protocol_id_names, this->protocol);
- written += print_alg(this, data, ENCRYPTION_ALGORITHM,
- encryption_algorithm_names, &first);
- written += print_alg(this, data, INTEGRITY_ALGORITHM,
- integrity_algorithm_names, &first);
- written += print_alg(this, data, PSEUDO_RANDOM_FUNCTION,
- pseudo_random_function_names, &first);
- 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);
+ enumerator = array_create_enumerator(this->types);
+ while (enumerator->enumerate(enumerator, &type))
+ {
+ written += print_alg(this, data, *type, &first);
+ }
+ enumerator->destroy(enumerator);
return written;
}
}
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 *s;
tcase_add_test(tc, test_promote_dh_group_not_contained);
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;
}