Skip to content

Commit 903c556

Browse files
committed
upstream: test compat_kex_proposal(); by dtucker@
OpenBSD-Regress-ID: 0e404ee264db546f9fdbf53390689ab5f8d38bf2
1 parent 405fba7 commit 903c556

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

regress/unittests/kex/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# $OpenBSD: Makefile,v 1.13 2023/01/15 23:35:10 djm Exp $
1+
# $OpenBSD: Makefile,v 1.14 2023/02/02 12:12:52 djm Exp $
22

33
PROG=test_kex
4-
SRCS=tests.c test_kex.c
4+
SRCS=tests.c test_kex.c test_proposal.c
55

66
# From usr.bin/ssh
77
SRCS+=sshbuf-getput-basic.c sshbuf-getput-crypto.c sshbuf-misc.c sshbuf.c

regress/unittests/kex/test_proposal.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}

regress/unittests/kex/tests.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
/* $OpenBSD: tests.c,v 1.1 2015/01/15 23:41:29 markus Exp $ */
1+
/* $OpenBSD: tests.c,v 1.2 2023/02/02 12:12:52 djm Exp $ */
22
/*
33
* Placed in the public domain
44
*/
55

66
#include "../test_helper/test_helper.h"
77

88
void kex_tests(void);
9+
void kex_proposal(void);
910

1011
void
1112
tests(void)
1213
{
1314
kex_tests();
15+
kex_proposal();
1416
}

0 commit comments

Comments
 (0)