start.sh 7.1 KB

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