|
| 1 | +/* $OpenBSD: test_proposal.c,v 1.1 2023/02/02 12:12:52 djm Exp $ */ |
| 2 | +/* |
| 3 | + * Regress test KEX |
| 4 | + * |
| 5 | + * Placed in the public domain |
| 6 | + */ |
| 7 | + |
| 8 | +#include <sys/types.h> |
| 9 | +#include <signal.h> |
| 10 | +#include <stdio.h> |
| 11 | +#include <stdint.h> |
| 12 | +#include <stdlib.h> |
| 13 | +#include <string.h> |
| 14 | + |
| 15 | +#include "test_helper.h" |
| 16 | + |
| 17 | +#include "compat.h" |
| 18 | +#include "ssherr.h" |
| 19 | +#include "sshbuf.h" |
| 20 | +#include "kex.h" |
| 21 | +#include "packet.h" |
| 22 | +#include "xmalloc.h" |
| 23 | + |
| 24 | +void kex_proposal(void); |
| 25 | + |
| 26 | +#define CURVE25519 " [email protected]" |
| 27 | +#define DHGEX1 "diffie-hellman-group-exchange-sha1" |
| 28 | +#define DHGEX256 "diffie-hellman-group-exchange-sha256" |
| 29 | +#define KEXALGOS CURVE25519","DHGEX256","DHGEX1 |
| 30 | +void |
| 31 | +kex_proposal(void) |
| 32 | +{ |
| 33 | + size_t i; |
| 34 | + struct ssh ssh; |
| 35 | + char *result, *out, *in; |
| 36 | + struct { |
| 37 | + char *in; /* TODO: make this const */ |
| 38 | + char *out; |
| 39 | + int compat; |
| 40 | + } tests[] = { |
| 41 | + { KEXALGOS, KEXALGOS, 0}, |
| 42 | + { KEXALGOS, DHGEX256","DHGEX1, SSH_BUG_CURVE25519PAD }, |
| 43 | + { KEXALGOS, CURVE25519, SSH_OLD_DHGEX }, |
| 44 | + { "a,"KEXALGOS, "a", SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX }, |
| 45 | + /* TODO: enable once compat_kex_proposal doesn't fatal() */ |
| 46 | + /* { KEXALGOS, "", SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX }, */ |
| 47 | + }; |
| 48 | + |
| 49 | + TEST_START("compat_kex_proposal"); |
| 50 | + for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { |
| 51 | + ssh.compat = tests[i].compat; |
| 52 | + /* match entire string */ |
| 53 | + result = compat_kex_proposal(&ssh, tests[i].in); |
| 54 | + ASSERT_STRING_EQ(result, tests[i].out); |
| 55 | + free(result); |
| 56 | + /* match at end */ |
| 57 | + in = kex_names_cat("a", tests[i].in); |
| 58 | + out = kex_names_cat("a", tests[i].out); |
| 59 | + result = compat_kex_proposal(&ssh, in); |
| 60 | + ASSERT_STRING_EQ(result, out); |
| 61 | + free(result); free(in); free(out); |
| 62 | + /* match at start */ |
| 63 | + in = kex_names_cat(tests[i].in, "a"); |
| 64 | + out = kex_names_cat(tests[i].out, "a"); |
| 65 | + result = compat_kex_proposal(&ssh, in); |
| 66 | + ASSERT_STRING_EQ(result, out); |
| 67 | + free(result); free(in); free(out); |
| 68 | + /* match in middle */ |
| 69 | + xasprintf(&in, "a,%s,b", tests[i].in); |
| 70 | + if (*(tests[i].out) == '\0') |
| 71 | + out = xstrdup("a,b"); |
| 72 | + else |
| 73 | + xasprintf(&out, "a,%s,b", tests[i].out); |
| 74 | + result = compat_kex_proposal(&ssh, in); |
| 75 | + ASSERT_STRING_EQ(result, out); |
| 76 | + free(result); free(in); free(out); |
| 77 | + } |
| 78 | + TEST_DONE(); |
| 79 | +} |
0 commit comments