Skip to content

Commit 7e33e9f

Browse files
LinuxJediejohnstown
authored andcommitted
Add tests and fix issues
1 parent 1aebe60 commit 7e33e9f

6 files changed

Lines changed: 446 additions & 43 deletions

File tree

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
bin_PROGRAMS =
33
noinst_HEADERS =
44
lib_LTLIBRARIES =
5+
noinst_LTLIBRARIES =
56
noinst_PROGRAMS =
67
nobase_include_HEADERS =
78
check_PROGRAMS =

src/include.am

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,42 @@ src_libwolfssh_la_SOURCES = src/ssh.c \
1111
src_libwolfssh_la_CPPFLAGS = -DBUILDING_WOLFSSH ${AM_CPPFLAGS}
1212
src_libwolfssh_la_LDFLAGS = -no-undefined -version-info ${WOLFSSH_LIBRARY_VERSION}
1313

14+
noinst_LTLIBRARIES += src/libwolfssh_test.la
15+
src_libwolfssh_test_la_SOURCES = $(src_libwolfssh_la_SOURCES)
16+
src_libwolfssh_test_la_CPPFLAGS = -DBUILDING_WOLFSSH -DWOLFSSH_TEST_INTERNAL ${AM_CPPFLAGS}
17+
src_libwolfssh_test_la_LDFLAGS = -no-undefined
18+
1419
if !BUILD_INLINE
1520
src_libwolfssh_la_SOURCES += src/misc.c
21+
src_libwolfssh_test_la_SOURCES += src/misc.c
1622
endif
1723

1824
if BUILD_KEYGEN
1925
src_libwolfssh_la_SOURCES += src/keygen.c
26+
src_libwolfssh_test_la_SOURCES += src/keygen.c
2027
endif
2128

2229
if BUILD_SCP
2330
src_libwolfssh_la_SOURCES += src/wolfscp.c
31+
src_libwolfssh_test_la_SOURCES += src/wolfscp.c
2432
endif
2533

2634
if BUILD_SFTP
2735
src_libwolfssh_la_SOURCES += src/wolfsftp.c
36+
src_libwolfssh_test_la_SOURCES += src/wolfsftp.c
2837
endif
2938

3039
if BUILD_TERM
3140
src_libwolfssh_la_SOURCES += src/wolfterm.c
41+
src_libwolfssh_test_la_SOURCES += src/wolfterm.c
3242
endif
3343

3444
if BUILD_AGENT
3545
src_libwolfssh_la_SOURCES += src/agent.c
46+
src_libwolfssh_test_la_SOURCES += src/agent.c
3647
endif
3748

3849
if BUILD_CERTS
3950
src_libwolfssh_la_SOURCES += src/certman.c
51+
src_libwolfssh_test_la_SOURCES += src/certman.c
4052
endif

src/internal.c

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -595,42 +595,6 @@ static void HandshakeInfoFree(HandshakeInfo* hs, void* heap)
595595
}
596596

597597

598-
#if 0
599-
/* RFC 4253 section 7.1, Once having sent SSH_MSG_KEXINIT the only messages
600-
* that can be sent are 1-19 (except SSH_MSG_SERVICE_REQUEST and
601-
* SSH_MSG_SERVICE_ACCEPT), 20-29 (except SSH_MSG_KEXINIT again), and 30-49
602-
*/
603-
INLINE static int IsMessageAllowedKeying(WOLFSSH *ssh, byte msg)
604-
{
605-
if (ssh->isKeying == 0) {
606-
return 1;
607-
}
608-
609-
/* case of service request or accept in 1-19 */
610-
if (msg == MSGID_SERVICE_REQUEST || msg == MSGID_SERVICE_ACCEPT) {
611-
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by during rekeying", msg);
612-
ssh->error = WS_REKEYING;
613-
return 0;
614-
}
615-
616-
/* case of peer resending SSH_MSG_KEXINIT */
617-
if ((ssh->isKeying & WOLFSSH_PEER_IS_KEYING) && msg == MSGID_KEXINIT) {
618-
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by during rekeying", msg);
619-
ssh->error = WS_REKEYING;
620-
return 0;
621-
}
622-
623-
/* case where message id greater than 49 */
624-
if (msg >= MSGID_USERAUTH_REQUEST) {
625-
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by during rekeying", msg);
626-
ssh->error = WS_REKEYING;
627-
return 0;
628-
}
629-
return 1;
630-
}
631-
#endif
632-
633-
634598
#ifndef NO_WOLFSSH_SERVER
635599
INLINE static int IsMessageAllowedServer(WOLFSSH *ssh, byte msg)
636600
{
@@ -694,6 +658,7 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
694658
if (msg == MSGID_SERVICE_REQUEST || msg == MSGID_USERAUTH_REQUEST) {
695659
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
696660
msg, "client", "ever");
661+
ssh->error = WS_MSGID_NOT_ALLOWED_E;
697662
return 0;
698663
}
699664

@@ -720,6 +685,7 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
720685
if (msg == MSGID_KEXINIT) {
721686
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
722687
msg, "client", "when keying");
688+
ssh->error = WS_REKEYING;
723689
return 0;
724690
}
725691

@@ -729,6 +695,7 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
729695
WLOG(WS_LOG_DEBUG,
730696
"Message ID %u not the expected message %u",
731697
msg, ssh->handshake->expectMsgId);
698+
ssh->error = WS_REKEYING;
732699
return 0;
733700
}
734701
else {
@@ -748,6 +715,7 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
748715
* when not keying. */
749716
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
750717
msg, "client", "when not keying");
718+
ssh->error = WS_MSGID_NOT_ALLOWED_E;
751719
return 0;
752720
}
753721
}
@@ -761,9 +729,17 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
761729
if (MSGIDLIMIT_POST_USERAUTH(msg)) {
762730
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
763731
msg, "client", "before user authentication is complete");
732+
ssh->error = WS_MSGID_NOT_ALLOWED_E;
764733
return 0;
765734
}
766735
else if (MSGIDLIMIT_AUTH(msg)) {
736+
/* Do not accept any userauth messages until we've asked for auth. */
737+
if (ssh->connectState < CONNECT_CLIENT_USERAUTH_REQUEST_SENT) {
738+
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
739+
msg, "client", "before sending userauth request");
740+
ssh->error = WS_MSGID_NOT_ALLOWED_E;
741+
return 0;
742+
}
767743
return 1;
768744
}
769745
}
@@ -774,6 +750,7 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
774750
else if (MSGIDLIMIT_AUTH(msg)) {
775751
WLOG(WS_LOG_DEBUG, "Message ID %u not allowed by %s %s",
776752
msg, "client", "after user authentication");
753+
ssh->error = WS_MSGID_NOT_ALLOWED_E;
777754
return 0;
778755
}
779756
}
@@ -787,12 +764,6 @@ INLINE static int IsMessageAllowedClient(WOLFSSH *ssh, byte msg)
787764
* Returns 1 if allowed 0 if not allowed. */
788765
INLINE static int IsMessageAllowed(WOLFSSH *ssh, byte msg, byte state)
789766
{
790-
#if 0
791-
if (!IsMessageAllowedKeying(ssh, msg)) {
792-
return 0;
793-
}
794-
#endif
795-
796767
#ifndef NO_WOLFSSH_SERVER
797768
if (ssh->ctx->side == WOLFSSH_ENDPOINT_SERVER) {
798769
return IsMessageAllowedServer(ssh, msg);
@@ -807,6 +778,13 @@ INLINE static int IsMessageAllowed(WOLFSSH *ssh, byte msg, byte state)
807778
return 0;
808779
}
809780

781+
#ifdef WOLFSSH_TEST_INTERNAL
782+
int wolfSSH_TestIsMessageAllowed(WOLFSSH* ssh, byte msg, byte state)
783+
{
784+
return IsMessageAllowed(ssh, msg, state);
785+
}
786+
#endif
787+
810788

811789
static const char cannedKexAlgoNames[] =
812790
#if !defined(WOLFSSH_NO_NISTP256_MLKEM768_SHA256)

tests/include.am

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# All paths should be given relative to the root
44

55
check_PROGRAMS += tests/unit.test tests/api.test \
6-
tests/testsuite.test tests/kex.test
6+
tests/testsuite.test tests/kex.test \
7+
tests/regress.test
78

89
tests_unit_test_SOURCES = tests/unit.c tests/unit.h
910
tests_unit_test_CPPFLAGS = -DNO_MAIN_DRIVER $(AM_CPPFLAGS)
@@ -43,3 +44,8 @@ tests_kex_test_SOURCES = tests/kex.c tests/kex.h \
4344
tests_kex_test_CPPFLAGS = -DNO_MAIN_DRIVER $(AM_CPPFLAGS)
4445
tests_kex_test_LDADD = src/libwolfssh.la
4546
tests_kex_test_DEPENDENCIES = src/libwolfssh.la
47+
48+
tests_regress_test_SOURCES = tests/regress.c
49+
tests_regress_test_CPPFLAGS = -DNO_MAIN_DRIVER -DWOLFSSH_TEST_INTERNAL $(AM_CPPFLAGS)
50+
tests_regress_test_LDADD = src/libwolfssh_test.la
51+
tests_regress_test_DEPENDENCIES = src/libwolfssh_test.la

0 commit comments

Comments
 (0)