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 "includes.h" 9 10 #include <sys/types.h> 11 #include <signal.h> 12 #include <stdio.h> 13 #ifdef HAVE_STDINT_H 14 #include <stdint.h> 15 #endif 16 #include <stdlib.h> 17 #include <string.h> 18 19 #include "../test_helper/test_helper.h" 20 21 #include "compat.h" 22 #include "ssherr.h" 23 #include "sshbuf.h" 24 #include "kex.h" 25 #include "packet.h" 26 #include "xmalloc.h" 27 28 void kex_proposal(void); 29 30 #define CURVE25519 "curve25519-sha256@libssh.org" 31 #define DHGEX1 "diffie-hellman-group-exchange-sha1" 32 #define DHGEX256 "diffie-hellman-group-exchange-sha256" 33 #define KEXALGOS CURVE25519","DHGEX256","DHGEX1 34 void 35 kex_proposal(void) 36 { 37 size_t i; 38 struct ssh ssh; 39 char *result, *out, *in; 40 struct { 41 char *in; /* TODO: make this const */ 42 char *out; 43 int compat; 44 } tests[] = { 45 { KEXALGOS, KEXALGOS, 0}, 46 { KEXALGOS, DHGEX256","DHGEX1, SSH_BUG_CURVE25519PAD }, 47 { KEXALGOS, CURVE25519, SSH_OLD_DHGEX }, 48 { "a,"KEXALGOS, "a", SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX }, 49 /* TODO: enable once compat_kex_proposal doesn't fatal() */ 50 /* { KEXALGOS, "", SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX }, */ 51 }; 52 53 TEST_START("compat_kex_proposal"); 54 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { 55 ssh.compat = tests[i].compat; 56 /* match entire string */ 57 result = compat_kex_proposal(&ssh, tests[i].in); 58 ASSERT_STRING_EQ(result, tests[i].out); 59 free(result); 60 /* match at end */ 61 in = kex_names_cat("a", tests[i].in); 62 out = kex_names_cat("a", tests[i].out); 63 result = compat_kex_proposal(&ssh, in); 64 ASSERT_STRING_EQ(result, out); 65 free(result); free(in); free(out); 66 /* match at start */ 67 in = kex_names_cat(tests[i].in, "a"); 68 out = kex_names_cat(tests[i].out, "a"); 69 result = compat_kex_proposal(&ssh, in); 70 ASSERT_STRING_EQ(result, out); 71 free(result); free(in); free(out); 72 /* match in middle */ 73 xasprintf(&in, "a,%s,b", tests[i].in); 74 if (*(tests[i].out) == '\0') 75 out = xstrdup("a,b"); 76 else 77 xasprintf(&out, "a,%s,b", tests[i].out); 78 result = compat_kex_proposal(&ssh, in); 79 ASSERT_STRING_EQ(result, out); 80 free(result); free(in); free(out); 81 } 82 TEST_DONE(); 83 } 84