start.sh 6.9 KB

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