|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# sshd local test |
| 4 | + |
| 5 | +ROOT_PWD=$(pwd) |
| 6 | +cd ../../.. |
| 7 | + |
| 8 | +TEST_CLIENT="./apps/wolfssh/wolfssh" |
| 9 | +PRIVATE_KEY="./keys/hansel-key-ecc.der" |
| 10 | +PUBLIC_KEY="./keys/hansel-key-ecc.pub" |
| 11 | + |
| 12 | +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then |
| 13 | + echo "expecting host and port as arguments" |
| 14 | + echo "$0 127.0.0.1 22222 $USER" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | +HOST_IP="$1" |
| 18 | +HOST_PORT="$2" |
| 19 | +USER_SET="$3" |
| 20 | + |
| 21 | +# check if wolfssh app was compiled |
| 22 | +OUTPUT=$("$TEST_CLIENT" -V) |
| 23 | +RESULT=$? |
| 24 | +if [ "$RESULT" != 0 ]; then |
| 25 | + echo "wolfSSH app not compiled in"; |
| 26 | + exit 77 |
| 27 | +fi |
| 28 | + |
| 29 | +# Debug mode needs to be on to inspect the debug output |
| 30 | +printf "$OUTPUT" | grep "DEBUG" |
| 31 | +RESULT=$? |
| 32 | +if [ "$RESULT" != 0 ]; then |
| 33 | + echo "wolfSSH app not compiled with debug mode"; |
| 34 | + exit 77 |
| 35 | +fi |
| 36 | + |
| 37 | +# returns variable SUPPORTED as 1 or 0 |
| 38 | +test_if_supported() { |
| 39 | + SUPPORTED=0 |
| 40 | + TEXT=$(./examples/client/client -E -u $USER_SET | grep "$1") |
| 41 | + if [ $? = 0 ]; then |
| 42 | + SUPPORTED=1 |
| 43 | + fi |
| 44 | + printf "$1 , $SUPPORTED\n" |
| 45 | +} |
| 46 | + |
| 47 | +# test which algo's are supported |
| 48 | +printf "Algo , Supported?\n" |
| 49 | +test_if_supported "p256" |
| 50 | +HAVE_P256=$SUPPORTED |
| 51 | +test_if_supported "p384" |
| 52 | +HAVE_P384=$SUPPORTED |
| 53 | +test_if_supported "p521" |
| 54 | +HAVE_P521=$SUPPORTED |
| 55 | +printf "\n" |
| 56 | + |
| 57 | + |
| 58 | +# Looks through the variable OUTPUT for the block of text containg the server |
| 59 | +# host key algorithms sent. |
| 60 | +find_substring_of_algos() { |
| 61 | + # Extract the substring between start and end lines |
| 62 | + SUBSTRING=$(printf "$OUTPUT" | grep -A20 "Server Host Key Algorithms") |
| 63 | + SUBSTRING=$(printf "$SUBSTRING" | grep -v -A15 "DKI: Enc Algorithms") |
| 64 | +} |
| 65 | + |
| 66 | +# take input argument $1 and checks if it is in the SUBSTRING |
| 67 | +test_for_algo_name() { |
| 68 | + #printf "substring found = $substring" |
| 69 | + if echo "$SUBSTRING" | grep -q "$1"; then |
| 70 | + printf "Found $1\n" |
| 71 | + EXISTS=1 |
| 72 | + else |
| 73 | + printf "Did not find $1\n" |
| 74 | + EXISTS=0 |
| 75 | + fi |
| 76 | +} |
| 77 | + |
| 78 | +# Expecting to find the algo name $1 |
| 79 | +test_for_algo_name_success() { |
| 80 | + test_for_algo_name "$1" |
| 81 | + if [ $EXISTS != 1 ]; then |
| 82 | + printf "Error finding algo name $1\n" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +} |
| 86 | + |
| 87 | +# Expecting to not find the algo name $1 |
| 88 | +test_for_algo_name_fail() { |
| 89 | + test_for_algo_name "$1" |
| 90 | + if [ $EXISTS = 1 ]; then |
| 91 | + printf "Error expected to not find algo name $1\n" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | +} |
| 95 | + |
| 96 | +echo "$TEST_CLIENT -p $HOST_PORT $USER_SET@$HOST_IP" |
| 97 | +OUTPUT=$(timeout 1 "$TEST_CLIENT" -p "$HOST_PORT" "$USER_SET"@"$HOST_IP" 2>&1) |
| 98 | +find_substring_of_algos |
| 99 | + |
| 100 | +if [ $HAVE_P256 = 1 ]; then |
| 101 | + test_for_algo_name_success "ecdsa-sha2-nistp256" |
| 102 | +else |
| 103 | + test_for_algo_name_fail "ecdsa-sha2-nistp256" |
| 104 | +fi |
| 105 | + |
| 106 | +if [ $HAVE_P384 = 1 ]; then |
| 107 | + test_for_algo_name_success "ecdsa-sha2-nistp384" |
| 108 | +else |
| 109 | + test_for_algo_name_fail "ecdsa-sha2-nistp384" |
| 110 | +fi |
| 111 | + |
| 112 | +if [ $HAVE_P521 = 1 ]; then |
| 113 | + test_for_algo_name_success "ecdsa-sha2-nistp521" |
| 114 | +else |
| 115 | + test_for_algo_name_fail "ecdsa-sha2-nistp521" |
| 116 | +fi |
| 117 | + |
| 118 | +exit 0 |
| 119 | + |
0 commit comments