1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#!/bin/sh
# 20181112
# Jan Mojzis
# Public domain.
# change directory to $AUTOPKGTEST_TMP
cd "${AUTOPKGTEST_TMP}"
# we need tools from /usr/sbin
PATH="/usr/sbin:${PATH}"
export PATH
# backup ~/.ssh
rm -rf ~/.ssh.tinysshtest.bk
[ -d ~/.ssh ] && mv ~/.ssh ~/.ssh.tinysshtest.bk
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# run tinysshd on port 10000
rm -rf sshkeydir
tinysshd-makekey -q sshkeydir
tcpserver -HRDl0 127.0.0.1 10000 tinysshd -- sshkeydir &
tcpserverpid=$!
cleanup() {
ex=$?
rm -rf ~/.ssh sshkeydir testfile1 ~/testfile2 testfile3
[ -d ~/.ssh.tinysshtest.bk ] && mv ~/.ssh.tinysshtest.bk ~/.ssh
#kill tcpserver
kill -TERM "${tcpserverpid}" 1>/dev/null 2>/dev/null || :
kill -KILL "${tcpserverpid}" 1>/dev/null 2>/dev/null || :
exit "${ex}"
}
trap "cleanup" EXIT TERM INT
# create authorization keys
ssh-keygen -t ed25519 -q -N '' -f ~/.ssh/id_ed25519 || exit 2
cp -pr ~/.ssh/id_ed25519.pub ~/.ssh/authorized_keys || exit 3
# create random file
dd if=/dev/urandom of=testfile1 bs=1 count=1048576
# runs remote dd command and checks sha256 checksum
ssh -o StrictHostKeyChecking=no -p 10000 127.0.0.1 "cat >testfile2" < testfile1
ssh -o StrictHostKeyChecking=no -p 10000 127.0.0.1 "cat testfile2" > testfile3
if [ x"`sha256sum < testfile1`" = x"`sha256sum < testfile3`" ]; then
echo "ssh transfer ok" >&2
else
echo "ssh transfer failed" >&2
exit 1
fi
exit 0
|