ci: set up our own sshd to get more control over it
Mostly this affects macOS where the current setup can leave us unable to
contact it. It is copied from the libgit2 test script.
set -ex
+echo "Starting ssh daemon..."
+TMPDIR=${TMPDIR:-/tmp}
+HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
+SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
+
+cat >"${SSHD_DIR}/sshd_config" <<-EOF
+Port 2222
+ListenAddress 0.0.0.0
+Protocol 2
+HostKey ${SSHD_DIR}/id_rsa
+PidFile ${SSHD_DIR}/pid
+AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
+LogLevel DEBUG
+RSAAuthentication yes
+PasswordAuthentication yes
+PubkeyAuthentication yes
+ChallengeResponseAuthentication no
+StrictModes no
+# Required here as sshd will simply close connection otherwise
+UsePAM no
+EOF
+ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
+/usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"
+
+# Set up keys
+mkdir "${HOME}/.ssh"
+ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
+cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
+while read algorithm key comment; do
+ echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
+done <"${SSHD_DIR}/id_rsa.pub"
+
+# Get the fingerprint for localhost and remove the colons so we can
+# parse it as a hex number. Older versions have a different output
+# format.
+if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
+ SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
+else
+ SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :)
+fi
+
# Create a test repo which we can use for the online tests
mkdir $HOME/_temp
git init --bare $HOME/_temp/test.git
@@ -10,15 +51,11 @@ git daemon --listen=localhost --export-all --enable=receive-pack --base-path=$HO
# On Actions we start with 777 which means sshd won't let us in
chmod 750 $HOME
-ssh-keygen -t rsa -f ~/.ssh/rugged_test_rsa -N "" -q
-cat ~/.ssh/rugged_test_rsa.pub >>~/.ssh/authorized_keys
-ssh-keyscan -t rsa localhost >>~/.ssh/known_hosts
-
export GITTEST_REMOTE_GIT_URL="git://localhost/test.git"
-export GITTEST_REMOTE_SSH_URL="ssh://localhost/$HOME/_temp/test.git"
+export GITTEST_REMOTE_SSH_URL="ssh://localhost:2222/$HOME/_temp/test.git"
export GITTEST_REMOTE_SSH_USER=$USER
-export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/rugged_test_rsa"
-export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/rugged_test_rsa.pub"
+export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa"
+export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub"
export GITTEST_REMOTE_SSH_PASSPHRASE=""
export GITTEST_REMOTE_REPO_PATH="$HOME/_temp/test.git"
