55# Demonstrates HTTPS server, SSH server, and MQTT broker running on
66# a bare-metal Cortex-M33 with wolfIP + wolfSSL + wolfSSH + wolfMQTT.
77#
8- # Usage: ./demo.sh [board-ip]
8+ # Usage: ./demo.sh [--auto] [board-ip]
9+ # --auto Skip pauses and interactive prompts (for automated testing)
910# board-ip defaults to 192.168.12.11
1011#
1112
12- BOARD_IP=" ${1:- 1192.168.12.11} "
13+ AUTO=0
14+ if [[ " $1 " == " --auto" ]]; then
15+ AUTO=1
16+ shift
17+ fi
18+ BOARD_IP=" ${1:- 192.168.12.11} "
19+
20+ # Validate BOARD_IP to block shell metacharacter injection via eval
21+ if ! [[ " $BOARD_IP " =~ ^[A-Za-z0-9._-]+$ ]]; then
22+ echo " Error: Invalid board IP/hostname: $BOARD_IP " >&2
23+ exit 1
24+ fi
1325
1426# Colors
1527BLD=' \033[1m'
@@ -37,7 +49,7 @@ BAMCA0gAMEUCIEUB8ArsbYI58PGtcy9KIdR6A3z5KCQblTXZWnIE7EDUAiEA8Oyi
3749LwVAHQ4M2+TcVwe4LQ+xG9F6uSmu4t/psG0IT+s=
3850-----END CERTIFICATE-----
3951CERTEOF
40- trap " rm -f $CERT_FILE " EXIT
52+ trap " rm -f $CERT_FILE /tmp/wolfip_sub.* " EXIT
4153
4254banner () {
4355 echo " "
@@ -56,6 +68,10 @@ cmd_show() {
5668}
5769
5870pause () {
71+ if [[ $AUTO -eq 1 ]]; then
72+ sleep 1
73+ return
74+ fi
5975 echo " "
6076 echo -ne " ${DIM} [Press Enter to continue]${RST} "
6177 read -r
@@ -106,7 +122,7 @@ pause
106122banner " 2. TCP Echo Server (Port 7)"
107123
108124step " Send a message to the plaintext echo server"
109- run_cmd " echo 'Hello wolfIP!' | nc -q 1 ${BOARD_IP} 7"
125+ run_cmd " echo 'Hello wolfIP!' | nc -w 2 ${BOARD_IP} 7"
110126
111127pause
112128
@@ -115,16 +131,22 @@ pause
115131# ---------------------------------------------------------------------------
116132banner " 3. HTTPS Web Server (Port 443) - TLS 1.3"
117133
118- step " Fetch the status page with curl"
119- run_cmd " curl -s -k https://${BOARD_IP} / | sed 's/<[^>]*>//g; s/^[[:space:]]*//; /^$/d'"
120-
121- echo " "
122- step " Inspect the TLS 1.3 handshake"
123- cmd_show " echo | openssl s_client -connect ${BOARD_IP} :443 -tls1_3 -brief 2>&1"
134+ step " Fetch the status page and inspect TLS 1.3 handshake"
135+ cmd_show " curl -vsk --max-time 10 https://${BOARD_IP} /"
124136echo " "
125- echo | openssl s_client -connect " ${BOARD_IP} " :443 -tls1_3 -brief 2>&1 | \
126- grep -E ' (Protocol|Ciphersuite|Peer certificate|Server certificate|subject|issuer|Verification)' | \
127- sed ' s/^/ /'
137+ CURL_OUT=$( curl -vsk --max-time 10 " https://${BOARD_IP} /" 2>&1 )
138+ RC=$?
139+ if [[ $RC -ne 0 && -z " $CURL_OUT " ]]; then
140+ echo -e " ${RED} Connection failed (curl exit $RC )${RST} "
141+ else
142+ # Show TLS handshake details (lines starting with "* ")
143+ echo " $CURL_OUT " | grep -E ' ^\* +(SSL|Server cert|subject|issuer|start date|expire)' | sed ' s/^/ /'
144+ echo " "
145+ # Show page content (lines not starting with *, >, <space, or <header)
146+ echo " $CURL_OUT " | grep -v ' ^[*><{} ]' | \
147+ sed ' s/<\/\(tr\|h1\|title\)>/\n/g; s/<[^>]*>//g; s/^[[:space:]]*//; /^$/d' | \
148+ sed ' s/^/ /'
149+ fi
128150echo " "
129151
130152pause
@@ -138,8 +160,12 @@ step "Connect and run commands (admin/wolfip)"
138160echo -e " ${DIM} NOTE: This opens an interactive SSH session.${RST} "
139161echo -e " ${DIM} Try: help, info, uptime, then exit${RST} "
140162echo " "
141- echo -ne " ${YLW} >>>${RST} Open SSH session? ${DIM} [Enter=yes, s=skip]${RST} "
142- read -r ssh_choice
163+ if [[ $AUTO -eq 1 ]]; then
164+ ssh_choice=" s"
165+ else
166+ echo -ne " ${YLW} >>>${RST} Open SSH session? ${DIM} [Enter=yes, s=skip]${RST} "
167+ read -r ssh_choice
168+ fi
143169if [[ " $ssh_choice " != " s" ]]; then
144170 cmd_show " ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null admin@${BOARD_IP} "
145171 echo " "
@@ -160,9 +186,10 @@ step "Start a subscriber in the background"
160186cmd_show " mosquitto_sub -h ${BOARD_IP} -p 8883 --cafile cert.pem --insecure -t 'demo/#' -v"
161187echo " "
162188
189+ SUB_OUT=$( mktemp /tmp/wolfip_sub.XXXXXX)
163190mosquitto_sub -h " ${BOARD_IP} " -p 8883 \
164191 --cafile " $CERT_FILE " --insecure \
165- -t " demo/#" -v 2> /dev/null &
192+ -t " demo/#" -v > " $SUB_OUT " 2> /dev/null &
166193SUB_PID=$!
167194
168195echo -e " ${DIM} Subscriber listening on demo/# (pid ${SUB_PID} )${RST} "
@@ -183,11 +210,17 @@ done
183210echo " "
184211step " Subscriber received:"
185212sleep 2
213+ if [[ -s " $SUB_OUT " ]]; then
214+ sed ' s/^/ /' " $SUB_OUT "
215+ else
216+ echo -e " ${DIM} (no messages received)${RST} "
217+ fi
186218echo " "
187219
188220# Cleanup subscriber
189221kill $SUB_PID 2> /dev/null
190222wait $SUB_PID 2> /dev/null
223+ rm -f " $SUB_OUT "
191224
192225pause
193226
0 commit comments