| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "crypto/s2n_pq.h" |
| 17 |
#include "s2n_test.h" |
| 18 |
#include "testlib/s2n_testlib.h" |
| 19 |
#include "tests/s2n_test.h" |
| 20 |
#include "tls/s2n_kem.h" |
| 21 |
#include "tls/s2n_security_policies.h" |
| 22 |
#include "tls/s2n_supported_group_preferences.h" |
| 23 |
#include "tls/s2n_tls.h" |
| 24 |
|
| 25 |
int main(int argc, char **argv) |
| 26 |
{ |
| 27 |
BEGIN_TEST(); |
| 28 |
|
| 29 |
|
| 30 |
for (size_t policy_index = 0; security_policy_selection[policy_index].version != NULL; policy_index++) { |
| 31 |
const struct s2n_security_policy_selection selection = security_policy_selection[policy_index]; |
| 32 |
const char *policy_name = selection.version; |
| 33 |
const struct s2n_security_policy *security_policy = selection.security_policy; |
| 34 |
POSIX_ENSURE_REF(security_policy); |
| 35 |
|
| 36 |
if (security_policy->strongly_preferred_groups == NULL || security_policy->strongly_preferred_groups->count == 0) { |
| 37 |
continue; |
| 38 |
} |
| 39 |
|
| 40 |
POSIX_ENSURE_REF(security_policy->strongly_preferred_groups); |
| 41 |
|
| 42 |
uint16_t ordered_supported_groups[S2N_KEM_GROUPS_COUNT + S2N_ECC_EVP_SUPPORTED_CURVES_COUNT] = { 0 }; |
| 43 |
uint16_t ordered_supported_group_count = 0; |
| 44 |
|
| 45 |
POSIX_ENSURE_REF(security_policy->kem_preferences); |
| 46 |
|
| 47 |
|
| 48 |
EXPECT_EQUAL(0, security_policy->kem_preferences->tls13_kem_group_count); |
| 49 |
|
| 50 |
POSIX_ENSURE_REF(security_policy->ecc_preferences); |
| 51 |
for (size_t i = 0; i < security_policy->ecc_preferences->count; i++) { |
| 52 |
const struct s2n_ecc_named_curve *ecc_curve = security_policy->ecc_preferences->ecc_curves[i]; |
| 53 |
POSIX_ENSURE_REF(ecc_curve); |
| 54 |
|
| 55 |
ordered_supported_groups[ordered_supported_group_count++] = ecc_curve->iana_id; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
for (size_t i = 0; i < security_policy->strongly_preferred_groups->count; i++) { |
| 60 |
const uint16_t strongly_preferred_iana = security_policy->strongly_preferred_groups->iana_ids[i]; |
| 61 |
const uint16_t standard_preferred_iana = ordered_supported_groups[i]; |
| 62 |
|
| 63 |
|
| 64 |
if (strongly_preferred_iana != standard_preferred_iana) { |
| 65 |
fprintf(stderr, "Error with Security Policy: %s\n", policy_name); |
| 66 |
FAIL_MSG("The strongly preferred groups should be a prefix of the standard SupportedGroup preference list."); |
| 67 |
} |
| 68 |
|
| 69 |
EXPECT_EQUAL(strongly_preferred_iana, standard_preferred_iana); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
END_TEST(); |
| 74 |
} |