Skip to content

Commit 0619dce

Browse files
padelsbachpaul
authored andcommitted
Allow empty passwords in sshd when PermitEmptyPasswords is set
1 parent 162dd7f commit 0619dce

4 files changed

Lines changed: 83 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ examples/scpclient/wolfscp
6868
apps/wolfssh/wolfssh
6969
apps/wolfsshd/wolfsshd
7070
apps/wolfsshd/test/test_configuration
71+
apps/wolfsshd/test/log.txt
72+
apps/wolfsshd/test/sshd_config_*
7173

7274
# test output
7375
tests/*.test

apps/wolfsshd/auth.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ static int CheckPasswordUnix(const char* usr, const byte* pw, word32 pwSz, WOLFS
363363
char* storedHash;
364364
char* storedHashCpy = NULL;
365365

366-
if (usr == NULL || pw == NULL) {
366+
/* Allow zero length passwords, but not NULL pointers. */
367+
if (usr == NULL || (pw == NULL && pwSz != 0)) {
367368
ret = WS_BAD_ARGUMENT;
368369
}
369370

@@ -373,7 +374,9 @@ static int CheckPasswordUnix(const char* usr, const byte* pw, word32 pwSz, WOLFS
373374
ret = WS_MEMORY_E;
374375
}
375376
else {
376-
XMEMCPY(pwStr, pw, pwSz);
377+
if (pwSz > 0) {
378+
XMEMCPY(pwStr, pw, pwSz);
379+
}
377380
pwStr[pwSz] = 0;
378381
}
379382
}

apps/wolfsshd/test/run_all_sshd_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ else
146146
if [ "$USING_LOCAL_HOST" == 1 ]; then
147147
run_test "sshd_forcedcmd_test.sh"
148148
run_test "sshd_window_full_test.sh"
149+
run_test "sshd_empty_password_test.sh"
149150
else
150151
printf "Skipping tests that need to setup local SSHD\n"
151-
SKIPPED=$((SKIPPED+2))
152+
SKIPPED=$((SKIPPED+3))
152153
fi
153154

154155
# these tests run with X509 sshd-config loaded
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Test for empty-password handling.
4+
5+
if [ -z "$1" ] || [ -z "$2" ]; then
6+
echo "expecting host and port as arguments"
7+
echo "$0 127.0.0.1 22222"
8+
exit 1
9+
fi
10+
11+
TEST_HOST="$1"
12+
TEST_PORT="$2"
13+
if [ ! -z "$3" ]; then
14+
USER="$3"
15+
else
16+
USER=`whoami`
17+
fi
18+
PWD=`pwd`
19+
20+
source ./start_sshd.sh
21+
22+
cat <<EOF > sshd_config_test_emptypw
23+
Port $TEST_PORT
24+
Protocol 2
25+
LoginGraceTime 600
26+
PermitRootLogin yes
27+
PasswordAuthentication yes
28+
PermitEmptyPasswords yes
29+
UsePrivilegeSeparation no
30+
UseDNS no
31+
HostKey $PWD/../../../keys/server-key.pem
32+
EOF
33+
34+
# Fresh log so we only see this run's output.
35+
sudo rm -f ./log.txt
36+
37+
start_wolfsshd "sshd_config_test_emptypw"
38+
if [ -z "$PID" ]; then
39+
echo "Failed to start wolfsshd"
40+
exit 1
41+
fi
42+
43+
TEST_CLIENT="../../../examples/client/client"
44+
45+
# Send an empty password
46+
timeout 10 $TEST_CLIENT -u "$USER" -P "" -c 'true' \
47+
-h "$TEST_HOST" -p "$TEST_PORT" > /dev/null 2>&1
48+
49+
# Let wolfsshd flush the log before we stop it.
50+
sleep 1
51+
stop_wolfsshd
52+
53+
# log.txt is owned by root (wolfsshd ran via sudo); use sudo to read it.
54+
if sudo grep -q "No compiled in password check" ./log.txt; then
55+
echo "SKIP: wolfsshd built without libcrypt/liblogin support"
56+
exit 77
57+
fi
58+
59+
if sudo grep -q "Error checking password" ./log.txt; then
60+
echo "FAIL: empty-password NULL-guard regression detected"
61+
echo "----- log.txt -----"
62+
sudo cat ./log.txt
63+
exit 1
64+
fi
65+
66+
if ! sudo grep -q "Password incorrect" ./log.txt; then
67+
echo "FAIL: empty-password code path was not exercised"
68+
echo "(expected '[SSHD] Password incorrect.' in log)"
69+
echo "----- log.txt -----"
70+
sudo cat ./log.txt
71+
exit 1
72+
fi
73+
74+
exit 0

0 commit comments

Comments
 (0)