start.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #!/bin/sh
  2. DIR="$( cd "$( dirname "$0" )" && pwd )"
  3. WPAS=$DIR/../../wpa_supplicant/wpa_supplicant
  4. WPACLI=$DIR/../../wpa_supplicant/wpa_cli
  5. HAPD=$DIR/../../hostapd/hostapd
  6. HAPD_AS=$DIR/../../hostapd/hostapd
  7. HAPDCLI=$DIR/../../hostapd/hostapd_cli
  8. WLANTEST=$DIR/../../wlantest/wlantest
  9. HLR_AUC_GW=$DIR/../../hostapd/hlr_auc_gw
  10. DATE="$(date +%s)"
  11. if [ -z "$LOGDIR" ] ; then
  12. LOGDIR="$DIR/logs/$DATE"
  13. mkdir -p $LOGDIR
  14. else
  15. if [ -e $LOGDIR/alt-wpa_supplicant/wpa_supplicant/wpa_supplicant ]; then
  16. WPAS=$LOGDIR/alt-wpa_supplicant/wpa_supplicant/wpa_supplicant
  17. WPACLI=$LOGDIR/alt-wpa_supplicant/wpa_supplicant/wpa_cli
  18. # extra code coverage
  19. $WPAS > /dev/null 2>&1
  20. $WPAS -efoo -Ifoo -mfoo -ofoo -Ofoo -pfoo -Pfoo -h > /dev/null 2>&1
  21. $WPAS -bfoo -B -Cfoo -q -W -N -L > /dev/null 2>&1
  22. $WPAS -T -v > /dev/null 2>&1
  23. $WPAS -u -z > /dev/null 2>&1
  24. fi
  25. if [ -e $LOGDIR/alt-hostapd/hostapd/hostapd ]; then
  26. HAPD=$LOGDIR/alt-hostapd/hostapd/hostapd
  27. HAPDCLI=$LOGDIR/alt-hostapd/hostapd/hostapd_cli
  28. # extra code coverage
  29. $HAPD > /dev/null 2>&1
  30. $HAPD -v > /dev/null 2>&1
  31. $HAPD -B -efoo -Pfoo -T -bfoo -h > /dev/null 2>&1
  32. $HAPD -ufoo > /dev/null 2>&1
  33. $HAPD -u00:11:22:33:44:55 > /dev/null 2>&1
  34. $HAPD -gfoo > /dev/null 2>&1
  35. $HAPD -Gfoo-not-exists > /dev/null 2>&1
  36. $HAPD -z > /dev/null 2>&1
  37. $HAPD -i foo1,foo2,foo3 > /dev/null 2>&1
  38. fi
  39. if [ -e $LOGDIR/alt-hostapd-as/hostapd/hostapd ]; then
  40. HAPD_AS=$LOGDIR/alt-hostapd-as/hostapd/hostapd
  41. fi
  42. if [ -e $LOGDIR/alt-hlr_auc_gw/hostapd/hlr_auc_gw ]; then
  43. HLR_AUC_GW=$LOGDIR/alt-hlr_auc_gw/hostapd/hlr_auc_gw
  44. # extra code coverage
  45. $HLR_AUC_GW > /dev/null 2>&1
  46. $HLR_AUC_GW -Dfoo -i7 -sfoo -h > /dev/null 2>&1
  47. $HLR_AUC_GW -i100 > /dev/null 2>&1
  48. $HLR_AUC_GW -z > /dev/null 2>&1
  49. fi
  50. fi
  51. if test -w "$DIR/logs" ; then
  52. rm -rf $DIR/logs/current
  53. ln -sf $DATE $DIR/logs/current
  54. fi
  55. if groups | tr ' ' "\n" | grep -q ^admin$; then
  56. GROUP=admin
  57. else
  58. GROUP=adm
  59. fi
  60. for i in 0 1 2; do
  61. sed "s/ GROUP=.*$/ GROUP=$GROUP/" "$DIR/p2p$i.conf" > "$LOGDIR/p2p$i.conf"
  62. done
  63. sed "s/group=admin/group=$GROUP/;s%LOGDIR%$LOGDIR%g" "$DIR/auth_serv/as.conf" > "$LOGDIR/as.conf"
  64. sed "s/group=admin/group=$GROUP/;s%LOGDIR%$LOGDIR%g" "$DIR/auth_serv/as2.conf" > "$LOGDIR/as2.conf"
  65. if [ "$1" = "valgrind" ]; then
  66. VALGRIND=y
  67. VALGRIND_WPAS="valgrind --log-file=$LOGDIR/valgrind-wlan%d"
  68. VALGRIND_HAPD="valgrind --log-file=$LOGDIR/valgrind-hostapd"
  69. chmod -f a+rx $WPAS
  70. chmod -f a+rx $HAPD
  71. chmod -f a+rx $HAPD_AS
  72. HAPD_AS="valgrind --log-file=$LOGDIR/valgrind-auth-serv $HAPD_AS"
  73. shift
  74. else
  75. unset VALGRIND
  76. VALGRIND_WPAS=
  77. VALGRIND_HAPD=
  78. fi
  79. if [ "$1" = "trace" ]; then
  80. TRACE="T"
  81. shift
  82. else
  83. TRACE=""
  84. fi
  85. $DIR/stop.sh
  86. TMP=$1
  87. if [ x${TMP%=[0-9]*} = "xchannels" ]; then
  88. NUM_CH=${TMP#channels=}
  89. shift
  90. else
  91. NUM_CH=1
  92. fi
  93. test -f /proc/modules && sudo modprobe mac80211_hwsim radios=7 channels=$NUM_CH support_p2p_device=0
  94. sudo ifconfig hwsim0 up
  95. sudo $WLANTEST -i hwsim0 -n $LOGDIR/hwsim0.pcapng -c -dtN -L $LOGDIR/hwsim0 &
  96. for i in 0 1 2; do
  97. DBUSARG=""
  98. if [ $i = "0" ] && ([ -r /var/run/dbus/pid ] || [ -r /var/run/dbus/system_bus_socket ]); then
  99. if $WPAS | grep -q -- -u; then
  100. DBUSARG="-u"
  101. fi
  102. fi
  103. sudo $(printf -- "$VALGRIND_WPAS" $i) $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $LOGDIR/p2p$i.conf \
  104. -ddKt$TRACE -f $LOGDIR/log$i $DBUSARG &
  105. done
  106. sudo $(printf -- "$VALGRIND_WPAS" 5) $WPAS -g /tmp/wpas-wlan5 -G$GROUP \
  107. -ddKt$TRACE -f $LOGDIR/log5 &
  108. sudo $VALGRIND_HAPD $HAPD -ddKt$TRACE -g /var/run/hostapd-global -G $GROUP -f $LOGDIR/hostapd &
  109. HPID=$!
  110. echo $HPID > $LOGDIR/hostapd-test.pid
  111. if [ -x $HLR_AUC_GW ]; then
  112. cp $DIR/auth_serv/hlr_auc_gw.milenage_db $LOGDIR/hlr_auc_gw.milenage_db
  113. sudo $HLR_AUC_GW -u -m $LOGDIR/hlr_auc_gw.milenage_db -g $DIR/auth_serv/hlr_auc_gw.gsm > $LOGDIR/hlr_auc_gw &
  114. fi
  115. openssl ocsp -index $DIR/auth_serv/index.txt \
  116. -rsigner $DIR/auth_serv/ocsp-responder.pem \
  117. -rkey $DIR/auth_serv/ocsp-responder.key \
  118. -CA $DIR/auth_serv/ca.pem \
  119. -issuer $DIR/auth_serv/ca.pem \
  120. -verify_other $DIR/auth_serv/ca.pem -trust_other \
  121. -ndays 7 \
  122. -reqin $DIR/auth_serv/ocsp-req.der \
  123. -respout $LOGDIR/ocsp-server-cache.der > $LOGDIR/ocsp.log 2>&1
  124. if [ ! -r $LOGDIR/ocsp-server-cache.der ]; then
  125. cp $DIR/auth_serv/ocsp-server-cache.der $LOGDIR/ocsp-server-cache.der
  126. fi
  127. cp $DIR/auth_serv/ocsp-multi-server-cache.der $LOGDIR/ocsp-multi-server-cache.der
  128. openssl ocsp -index $DIR/auth_serv/index.txt \
  129. -rsigner $DIR/auth_serv/ocsp-responder.pem \
  130. -rkey $DIR/auth_serv/ocsp-responder.key \
  131. -resp_key_id \
  132. -CA $DIR/auth_serv/ca.pem \
  133. -issuer $DIR/auth_serv/ca.pem \
  134. -verify_other $DIR/auth_serv/ca.pem -trust_other \
  135. -ndays 7 \
  136. -reqin $DIR/auth_serv/ocsp-req.der \
  137. -respout $LOGDIR/ocsp-server-cache-key-id.der > $LOGDIR/ocsp.log 2>&1
  138. for i in unknown revoked; do
  139. openssl ocsp -index $DIR/auth_serv/index-$i.txt \
  140. -rsigner $DIR/auth_serv/ocsp-responder.pem \
  141. -rkey $DIR/auth_serv/ocsp-responder.key \
  142. -CA $DIR/auth_serv/ca.pem \
  143. -issuer $DIR/auth_serv/ca.pem \
  144. -verify_other $DIR/auth_serv/ca.pem -trust_other \
  145. -ndays 7 \
  146. -reqin $DIR/auth_serv/ocsp-req.der \
  147. -respout $LOGDIR/ocsp-server-cache-$i.der >> $LOGDIR/ocsp.log 2>&1
  148. done
  149. openssl ocsp -reqout $LOGDIR/ocsp-req.der -issuer $DIR/auth_serv/ca.pem \
  150. -serial 0xD8D3E3A6CBE3CCE9 -no_nonce -sha256 >> $LOGDIR/ocsp.log 2>&1
  151. for i in "" "-unknown" "-revoked"; do
  152. openssl ocsp -index $DIR/auth_serv/index$i.txt \
  153. -rsigner $DIR/auth_serv/ca.pem \
  154. -rkey $DIR/auth_serv/ca-key.pem \
  155. -CA $DIR/auth_serv/ca.pem \
  156. -ndays 7 \
  157. -reqin $LOGDIR/ocsp-req.der \
  158. -resp_no_certs \
  159. -respout $LOGDIR/ocsp-resp-ca-signed$i.der >> $LOGDIR/ocsp.log 2>&1
  160. done
  161. openssl ocsp -index $DIR/auth_serv/index.txt \
  162. -rsigner $DIR/auth_serv/server.pem \
  163. -rkey $DIR/auth_serv/server.key \
  164. -CA $DIR/auth_serv/ca.pem \
  165. -ndays 7 \
  166. -reqin $LOGDIR/ocsp-req.der \
  167. -respout $LOGDIR/ocsp-resp-server-signed.der >> $LOGDIR/ocsp.log 2>&1
  168. touch $LOGDIR/hostapd.db
  169. sudo $HAPD_AS -ddKt $LOGDIR/as.conf $LOGDIR/as2.conf > $LOGDIR/auth_serv &
  170. # wait for programs to be fully initialized
  171. for i in 0 1 2 3 4 5 6 7 8 9; do
  172. if [ -e /tmp/wpas-wlan0 ]; then
  173. break
  174. fi
  175. sleep 0.05
  176. done
  177. for i in 0 1 2; do
  178. for j in `seq 1 10`; do
  179. if $WPACLI -g /tmp/wpas-wlan$i ping | grep -q PONG; then
  180. break
  181. fi
  182. if [ $j = "10" ]; then
  183. echo "Could not connect to /tmp/wpas-wlan$i"
  184. exit 1
  185. fi
  186. sleep 1
  187. done
  188. done
  189. for j in `seq 1 10`; do
  190. if $WPACLI -g /var/run/hostapd-global ping | grep -q PONG; then
  191. break
  192. fi
  193. if [ $j = "10" ]; then
  194. echo "Could not connect to /var/run/hostapd-global"
  195. exit 1
  196. fi
  197. sleep 1
  198. done
  199. for j in `seq 1 10`; do
  200. if $HAPDCLI -i as ping | grep -q PONG; then
  201. break
  202. fi
  203. if [ $j = "10" ]; then
  204. echo "Could not connect to hostapd-as-RADIUS-server"
  205. exit 1
  206. fi
  207. sleep 1
  208. done
  209. if [ $USER = "0" -o $USER = "root" ]; then
  210. exit 0
  211. fi
  212. sleep 0.75
  213. sudo chown -f $USER $LOGDIR/hwsim0.pcapng $LOGDIR/hwsim0 $LOGDIR/log* $LOGDIR/hostapd
  214. if [ "x$VALGRIND" = "xy" ]; then
  215. sudo chown -f $USER $LOGDIR/*valgrind*
  216. fi
  217. exit 0