1 /* $OpenBSD: test_proposal.c,v 1.2 2023/03/06 12:15:47 dtucker Exp $ */
5 * Placed in the public domain
10 #include <sys/types.h>
19 #include "../test_helper/test_helper.h"
26 #include "myproposal.h"
30 void kex_proposal_tests(void);
31 void kex_proposal_populate_tests(void);
33 #define CURVE25519 "curve25519-sha256@libssh.org"
34 #define DHGEX1 "diffie-hellman-group-exchange-sha1"
35 #define DHGEX256 "diffie-hellman-group-exchange-sha256"
36 #define KEXALGOS CURVE25519","DHGEX256","DHGEX1
38 kex_proposal_tests(void)
42 char *result, *out, *in;
44 char *in; /* TODO: make this const */
48 { KEXALGOS, KEXALGOS, 0},
49 { KEXALGOS, DHGEX256","DHGEX1, SSH_BUG_CURVE25519PAD },
50 { KEXALGOS, CURVE25519, SSH_OLD_DHGEX },
51 { "a,"KEXALGOS, "a", SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX },
52 /* TODO: enable once compat_kex_proposal doesn't fatal() */
53 /* { KEXALGOS, "", SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX }, */
56 TEST_START("compat_kex_proposal");
57 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
58 ssh.compat = tests[i].compat;
59 /* match entire string */
60 result = compat_kex_proposal(&ssh, tests[i].in);
61 ASSERT_STRING_EQ(result, tests[i].out);
64 in = kex_names_cat("a", tests[i].in);
65 out = kex_names_cat("a", tests[i].out);
66 result = compat_kex_proposal(&ssh, in);
67 ASSERT_STRING_EQ(result, out);
68 free(result); free(in); free(out);
70 in = kex_names_cat(tests[i].in, "a");
71 out = kex_names_cat(tests[i].out, "a");
72 result = compat_kex_proposal(&ssh, in);
73 ASSERT_STRING_EQ(result, out);
74 free(result); free(in); free(out);
76 xasprintf(&in, "a,%s,b", tests[i].in);
77 if (*(tests[i].out) == '\0')
80 xasprintf(&out, "a,%s,b", tests[i].out);
81 result = compat_kex_proposal(&ssh, in);
82 ASSERT_STRING_EQ(result, out);
83 free(result); free(in); free(out);
89 kex_proposal_populate_tests(void)
91 char *prop[PROPOSAL_MAX], *kexalgs, *ciphers, *macs, *hkalgs;
92 const char *comp = compression_alg_list(0);
97 kexalgs = kex_alg_list(',');
98 ciphers = cipher_alg_list(',', 0);
99 macs = mac_alg_list(',');
100 hkalgs = kex_alg_list(',');
103 TEST_START("compat_kex_proposal_populate");
104 for (i = 0; i <= 1; i++) {
106 for (ssh.compat = 0; ssh.compat < 0x40000000; ) {
107 kex_proposal_populate_entries(&ssh, prop, NULL, NULL,
109 kex_proposal_free_entries(prop);
110 kex_proposal_populate_entries(&ssh, prop, kexalgs,
111 ciphers, macs, hkalgs, comp);
112 kex_proposal_free_entries(prop);