You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.0 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=49
  3. USE_PROCD=1
  4. setup_ca() {
  5. [ -e /etc/hs20/AS/Key/server.pem ] && return 0
  6. local company friendly_name rootsubject logo_sha1 logo_sha256 logo_url domain osu_client_subject ocsp_server_subject key_passphrase osu_server_name ocsp_uri revoked_subject
  7. config_load hs20
  8. config_get company ca company
  9. config_get friendly_name ca friendly_name
  10. config_get rootsubject ca rootsubject
  11. config_get logo_sha1 ca logo_sha1
  12. config_get logo_sha256 ca logo_sha256
  13. config_get logo_url ca logo_url
  14. config_get domain ca domain
  15. config_get osu_client_subject ca osu_client_subject
  16. config_get ocsp_server_subject ca ocsp_server_subject
  17. config_get key_passphrase ca key_passphrase
  18. config_get osu_server_name ca osu_server_name
  19. config_get ocsp_uri ca ocsp_uri
  20. mkdir -p /etc/hs20/ca
  21. (
  22. cd /etc/hs20/ca
  23. /bin/busybox sh /usr/share/hs20/ca/setup.sh -c "$company" -C "$friendly_name" -g "$logo_sha1" -G "$logo_sha256" -l "$logo_url" -m "$domain" -o "$osu_client_subject" -O "$ocsp_server_subject" -p "$key_passphrase" -S "$osu_server_name" -u "$ocsp_uri" -V "$revoked_subject"
  24. )
  25. mkdir -p /etc/hs20/AS/Key
  26. cp /etc/hs20/ca/server.* /etc/hs20/ca/ca.pem /etc/hs20/AS/Key
  27. return 0
  28. }
  29. sql_set() {
  30. echo "DELETE FROM osu_config WHERE realm='$1' AND field='$2';"
  31. echo "INSERT INTO osu_config(realm,field,value) VALUES('$1','$2','$3');"
  32. }
  33. setup_dbconf() {
  34. local domain spp_http_auth_url trust_root_cert_url
  35. config_load hs20
  36. config_get realm ca domain
  37. config_get spp_http_auth_url server spp_http_auth_url
  38. config_get trust_root_cert_url server trust_root_cert_url
  39. config_get trust_root_cert_fingerprint server trust_root_cert_fingerprint
  40. config_get aaa_trust_root_cert_url server aaa_trust_root_cert_url
  41. config_get aaa_trust_root_cert_fingerprint server aaa_trust_root_cert_fingerprint
  42. config_get free_account server free_account
  43. config_get policy_url server policy_url
  44. config_get remediation_url server remediation_url
  45. config_get free_remediation_url server free_remediation_url
  46. config_get signup_url server signup_url
  47. (
  48. sql_set $realm spp_http_auth_url "$spp_http_auth_url"
  49. sql_set $realm trust_root_cert_url "$trust_root_cert_url"
  50. sql_set $realm trust_root_cert_fingerprint "$trust_root_cert_fingerprint"
  51. sql_set $realm aaa_trust_root_cert_url "$aaa_trust_root_cert_url"
  52. sql_set $realm aaa_trust_root_cert_fingerprint "$aaa_trust_root_cert_fingerprint"
  53. sql_set $realm free_account "$free_account"
  54. sql_set $realm policy_url "$policy_url"
  55. sql_set $realm remediation_url "$remediation_url"
  56. sql_set $realm free_remediation_url "$free_remediation_url"
  57. sql_set $realm signup_url "$signup_url"
  58. ) | sqlite3 /etc/hs20/AS/DB/eap_user.db
  59. return 0
  60. }
  61. setup_policy() {
  62. local update_interval update_method restriction uri
  63. config_load hs20
  64. config_get update_interval policy update_interval
  65. config_get update_method policy update_method
  66. config_get restriction policy restriction
  67. config_get uri policy uri
  68. if [ ! -e "/etc/hs20/spp/policy/default.xml" ]; then
  69. mkdir -p /etc/hs20/spp/policy
  70. ln -s /tmp/run/spp-default-policy.xml /etc/hs20/spp/policy/default.xml
  71. fi
  72. cat > /tmp/run/spp-default-policy.xml <<EOF
  73. <Policy>
  74. <PolicyUpdate>
  75. <UpdateInterval>$update_interval</UpdateInterval>
  76. <UpdateMethod>$update_method</UpdateMethod>
  77. <Restriction>$restriction</Restriction>
  78. <URI>$uri</URI>
  79. </PolicyUpdate>
  80. </Policy>
  81. EOF
  82. return 0
  83. }
  84. prepare_config() {
  85. local key_passphrase subscr_remediation_url osu_nai as_passphrase radius_passphrase
  86. config_load hs20
  87. config_get key_passphrase ca key_passphrase
  88. config_get subscr_remediation_url policy uri
  89. config_get osu_nai server osu_nai
  90. config_get as_passphrase server as_passphrase
  91. config_get radius_passphrase server radius_passphrase
  92. cat > /tmp/run/as-sql.conf <<EOF
  93. driver=none
  94. radius_server_clients=/etc/hs20/AS/as.radius_clients
  95. eap_server=1
  96. eap_user_file=sqlite:/etc/hs20/AS/DB/eap_user.db
  97. ca_cert=/etc/hs20/AS/Key/ca.pem
  98. server_cert=/etc/hs20/AS/Key/server.pem
  99. private_key=/etc/hs20/AS/Key/server.key
  100. private_key_passwd=$key_passphrase
  101. eap_sim_db=unix:/tmp/hlr_auc_gw.sock db=/etc/hs20/AS/DB/eap_sim.db
  102. subscr_remediation_url=$subscr_remediation_url
  103. EOF
  104. mkdir -p /var/run/hostapd/hs20-radius
  105. cat > /tmp/run/radius-sql.conf <<EOF
  106. # hostapd-radius config for the radius used by the OSEN AP
  107. interface=lo
  108. driver=none
  109. logger_syslog=-1
  110. logger_syslog_level=2
  111. logger_stdout=-1
  112. logger_stdout_level=2
  113. ctrl_interface=/var/run/hostapd/hs20-radius
  114. ctrl_interface_group=0
  115. eap_server=1
  116. eap_user_file=/etc/hs20/AS/hostapd-osen.eap_user
  117. server_id=ben-ota-2-osen
  118. radius_server_auth_port=1811
  119. radius_server_clients=/etc/hs20/AS/hostap.radius_clients
  120. ca_cert=/etc/hs20/ca/ca.pem
  121. server_cert=/etc/hs20/ca/server.pem
  122. private_key=/etc/hs20/ca/server.key
  123. private_key_passwd=$key_passphrase
  124. ocsp_stapling_response=/etc/hs20/ca/ocsp-server-cache.der
  125. EOF
  126. cat > /etc/hs20/AS/hostapd-osen.eap_user <<EOF
  127. # For OSEN authentication (Hotspot 2.0 Release 2)
  128. "$osu_nai" WFA-UNAUTH-TLS
  129. EOF
  130. cat > /etc/hs20/AS/hostap.radius_clients <<EOF
  131. 0.0.0.0/0 $radius_passphrase
  132. EOF
  133. cat > /etc/hs20/AS/as.radius_clients <<EOF
  134. 0.0.0.0/0 $as_passphrase
  135. EOF
  136. return 0
  137. }
  138. start_service() {
  139. local enabled
  140. config_load hs20
  141. config_get enabled server enabled
  142. [ "$enabled" != "1" ] && [ "$enabled" != "true" ] && exit 0
  143. echo "starting"
  144. setup_ca
  145. setup_policy
  146. setup_dbconf
  147. prepare_config
  148. procd_open_instance ocsp-responder
  149. procd_set_param command /usr/bin/openssl ocsp -index /etc/hs20/ca/demoCA/index.txt -port 8888 -nmin 5 -rsigner /etc/hs20/ca/ocsp.pem -rkey /etc/hs20/ca/ocsp.key -CA /etc/hs20/ca/demoCA/cacert.pem -text -ignore_err
  150. procd_set_param stdout 1
  151. procd_set_param stderr 1
  152. procd_set_param respawn
  153. procd_close_instance
  154. procd_open_instance hs20-ac
  155. procd_set_param command /usr/sbin/hostapd-hs20-radius-server /tmp/run/as-sql.conf
  156. procd_set_param stdout 1
  157. procd_set_param stderr 1
  158. procd_set_param respawn
  159. procd_close_instance
  160. procd_open_instance hs20-radius
  161. procd_set_param command /usr/sbin/hostapd-hs20-radius-server /tmp/run/radius-sql.conf
  162. procd_set_param stdout 1
  163. procd_set_param stderr 1
  164. procd_set_param respawn
  165. procd_close_instance
  166. }