以前にEAP-TLSを使ったWPA2-Enterprise環境を構築したのですが、セキュリティは高いもののデジタル証明書をインストールする煩雑さがあります。
今回はユーザー/パスワード認証によるWPA2-Enterprise接続を構築してみます。EAP-PEAP/MSCHAPv2は多くのプラットフォームで広く使われている方式でセキュリティも比較的高く安心です。ユーザー管理にはブラウザから設定できるdaloRADIUSを使います。daloRADIUSはRADIUSサーバの管理用アプリケーションです。
新しいサーバを用意しても良いのですが、今回は普段ファイルサーバーとして使っているNAS(ReadyNAS 102)にインストールしてみます。このNASにはApache2サーバがすでにインストールしてあるので既存のWebサーバを使ってdaloRADIUSが使えるように設定します。
システム図
Users --(WI-FI)-- AP(Chaos Calmer 15.05.1) --(LAN)-- NAS(daloRADIUS, FreeRADIUS, MySQL)
手順
1.NASにMySQLサーバーとFreeRADIUSをインストール
2.Webサーバーの設定
3.NASにdaloRADIUSをインストール
4.ルーターのAPの設定
5.DaloRADIUSに接続
6.ユーザからのWI-FI接続環境
1.NASにMySQLサーバーとFreeRADIUSをインストール
MySQLサーバーはReadNASのコントロールパネルのAppsからインストールできますが、FreeRADIUSはないのでターミナルからsshログインしてaptを使ってインストールします。また各サーバーのモジュールもaptを使ってインストールします。(インストール詳細はdaloRADIUSパッケージのINSTALLファイルに書かれています)
apt-get install php5-common php5-gd php-pear php-db libapache2-mod-php5 php-mail php-mail-mime
apt-get install php5-mysql
apt-get install freeradius freeradius-mysql freeradius-utils
次にデーターベースを作成します。
mysqladmin create radius
パスワードを設定します。
mysql -u root
mysql> update mysql.user set password=password('password') where user = 'root';
mysql> flush privileges;
mysql> exit;
パスワード設定後、mysql入力画面に入るときは-pを指定します。
mysql -u root -p
Enter Password
次にスキーマをインストールします。
mysql -u root -p radius < /etc/freeradius/sql/mysql/schema.sql
mysql -u root -p radius < /etc/freeradius/sql/mysql/nas.sql
FreeRADIUSを設定します。証明書の作成等は以前の記事に準じます。
/etc/freeradius/eap.conf:
eap {
default_eap_type = peap
timer_expire = 60
ignore_unknown_eap_types = no
cisco_accounting_username_bug = no
max_sessions = ${max_requests}
tls {
certdir = ${confdir}/certs
cadir = ${confdir}/certs
private_key_password = whatever
private_key_file = ${certdir}/server.key
certificate_file = ${certdir}/server.pem
CA_file = ${cadir}/ca.pem
dh_file = ${certdir}/dh
random_file = /dev/urandom
CA_path = ${cadir}
cipher_list = "DEFAULT"
make_cert_command = "${certdir}/bootstrap"
ecdh_curve = "prime256v1"
cache {
enable = no
lifetime = 24 # hours
max_entries = 255
}
verify {
tmpdir = /var/tmp/radiusd
client = "/path/to/openssl verify -CApath ${..CA_path} %{TLS-Client-Cert-Filename}"
}
ocsp {
enable = no
override_cert_url = yes
url = "http://127.0.0.1/ocsp/"
}
}
peap {
default_eap_type = mschapv2
copy_request_to_tunnel = no
use_tunneled_reply = no
virtual_server = "inner-tunnel"
}
mschapv2 {
send_error = no
}
}
次のコメントを外します。
/etc/freeradius/radiusd.conf:
$INCLUDE sql.conf
$INCLUDE sql/mysql/counter.conf
mysqlのログイン/パスワードを編集します。
/etc/freeradius/sql.conf:
login = "root"
password = "password"
またreadclients = yesのコメントを外します。
sites設定を編集します。
rm /etc/freeradius/sites-enabled/*
cp /etc/freeradius/sites-available/default /etc/freeradius/sites-available/default.org
cp /etc/freeradius/sites-available/inner-tunnel /etc/freeradius/sites-available/inner-tunnel.org
ln -s /etc/freeradius/sites-available/default /etc/freeradius/sites-enabled/default
ln -s /etc/freeradius/sites-available/inner-tunnel /etc/freeradius/sites-enabled/inner-tunnel
/etc/freeradius/sites-enabled/default:
authorize {
preprocess
chap
mschap
digest
suffix
eap {
ok = return
}
sql
expiration
logintime
pap
}
authenticate {
Auth-Type PAP {
pap
}
Auth-Type CHAP {
chap
}
Auth-Type MS-CHAP {
mschap
}
digest
unix
eap
}
preacct {
preprocess
acct_unique
suffix
files
}
accounting {
detail
sql
exec
attr_filter.accounting_response
}
session {
radutmp
sql
}
post-auth {
sql
exec
Post-Auth-Type REJECT {
sql
attr_filter.access_reject
}
}
pre-proxy {
}
post-proxy {
eap
}
/etc/freeradius/sites-enabled/inner-tunnel:
セクションauthorizeのsqlのコメントを外します。
/etc/freeradius/modules/mschap:
mschap {
use_mppe = yes
require_encryption = yes
require_strong = yes
with_ntdomain_hack = yes
}
/etc/freeradius/clients.conf:(daloRADIUSでも設定できます)
client 192.168.1.0/24 {
secret = whatever
shortname = localAP
}
FreeRADUSを再起動します。
systemctl restart freeradius.service
2.Webサーバーの設定
cp /etc/apache2/sites-available/default /etc/apache2/sites-enabled/001-default
ポート80はNASの管理用に使っているので新たに001-defaultファイルを編集してポート81(もしくは使っていないポート)に変更します。
/etc/apache2/sites-enabled/001-default:
<VirtualHost *:81>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/apache2/ports.conf:
NameVirtualHost *:80
Listen 80
NameVirtualHost *:81
Listen 81
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Apache2を再起動してテストしてみます。
systemctl restart apache2.service
http://<NAS IP Address>:81でアクセスして設定が正しければ「It works!」とブラウザが表示します。
3.NASにdaloRADIUSをインストール
最新バージョンのdaloradius-0.9-9.tar.gzをダウンロードします。
https://sourceforge.net/projects/daloradius/
または
https://github.com/lirantal/daloradius
/var/wwwに展開しディレクトリ名をdaloradiusに変更します。
パーミッションを変更します。
chown -R www-data:www-data /var/www/daloradius
chmod 644 /var/www/daloradius/library/daloradius.conf.php
daloRADIUSのスキーマをインストールします。
cd /var/www
mysql -u root -p radius < daloradius/contrib/db/fr2-mysql-daloradius-and-freeradius.sql
/var/www/daloradius/library/daloradius.conf.phpのユーザー/パスワードを編集してデータベースに接続できるようにします。
$configValues['CONFIG_DB_USER'] = 'root';
$configValues['CONFIG_DB_PASS'] = 'password';
$configValues['CONFIG_DB_NAME'] = 'radius';
4.ルーターのAPの設定(OpenWrtのダッシュボードで編集します)

/etc/config/wireless:
config wifi-iface
option device 'radio0'
option mode 'ap'
option ssid 'SSID'
option network 'lan'
option encryption 'wpa2+ccmp'
option auth_server '<NAS IP Address>'
option auth_secret 'whatever'
option acct_server '<NAS IP Address>'
option acct_secret 'whatever'
5. DaloRADIUSに接続
<NAS IP Address>:81/daloradiusにアクセスします。

初期設定は次のとおりです。
Username: administrator
Password: radius
ユーザー登録します。
ManagementタブからNew User選択してユーザー名/パスワード(Password Type: Cleartext-Password)を入力します。
6.ユーザーからのWI-FI接続環境
Linux
詳細画面でユーザー名とパスワードを入れて接続します。

Windows 7、Windows 10(Windows 10はセキュリティアラート画面はなし)
ユーザー名とパスワードを入れて接続します。

警告画面がでますが、Connect(接続)ボタンを押します。

接続できない場合はプロファイルを作成します。SSIDと同じ名前をつけます。


プロパティの詳細を開きます。


Settingsボタンを押します。

configureを押しUser authenticationにします。

チェックを外します。

Chromebook(Androidもほぼ同じ)
Server CA certificateは”Do not check“、選択できない場合はそのままにします。EAPはPEAPを選択し、Identity(ユーザー名)、パスワードを入れます。

MacOS
ユーザー名とパスワードのみです。ポップアップで認証を求められたらAdmin権限で認証してください。

Windows Phone
ユーザ名とパスワードを入れ実行ボタンを押すと、”Accept certificate and connect?”というメッセージがでるので”Accept(承認)”ボタンをクリックします。

7. Counter moduleの追加
daloRADIUS Virtual Machineでデモをみていたら、期限付きアカウントをリースができるようになってたので使えるように調整してみました。dalaradiusのパッケージのcontribを参考につけ加えます。
/etc/freeradius/sites-enabled/default:
# enabling the sql counter modules (time-based)
dailycounter
monthlycounter
weeklycounter
quaterlycounter
yearlycounter
noresetcounter
accessperiod
# chillispot data/volume type counters
counterChilliSpotMaxTotalOctetsDaily
counterChilliSpotMaxTotalOctetsWeekly
counterChilliSpotMaxTotalOctetsMonthly
counterChilliSpotMaxTotalOctetsQuarterly
counterChilliSpotMaxTotalOctetsYearly
counterChilliSpotMaxTotalOctetsAll
# input octets limitation
counterChilliSpotMaxInputOctetsDaily
counterChilliSpotMaxInputOctetsWeekly
counterChilliSpotMaxInputOctetsMonthly
counterChilliSpotMaxInputOctetsQuarterly
counterChilliSpotMaxInputOctetsYearly
counterChilliSpotMaxInputOctetsAll
# output octets limitation
counterChilliSpotMaxOutputOctetsDaily
counterChilliSpotMaxOutputOctetsWeekly
counterChilliSpotMaxOutputOctetsMonthly
counterChilliSpotMaxOutputOctetsQuarterly
counterChilliSpotMaxOutputOctetsYearly
counterChilliSpotMaxOutputOctetsAll
/etc/freeradius/sql/mysql/counter.conf:
mv /etc/freeradius/sql/mysql/counter.conf /etc/freeradius/sql/mysql/counter.conf.org
cp daloradius/contrib/configs/freeradius-2.1.8/cfg1/raddbsql/mysql/counter.conf /etc/freeradius/sql/mysql/counter.conf
sqlモジュールはcounter.confに追加していけば使えるようです。
freeradiusを再起動します。
まとめ
daloRADIUSの導入でWPA2-Enterpriseのユーザー管理が簡単になりました。daloRADIUSにはradius向けに様々なオプションがありユーザー認証だけでなく時間を区切ってアクセスを管理したり、料金プランを作ることもできます。WindowsではCA証明書をインストールしていないため警告が表示されますがサーバー偽装に対する警告です。CA証明書をインストールすればより安全な接続になります。WPA2-Personalの共有パスワードに不安があるとき、またある程度の規模でWI-FIネットワークを構築したい場合にはこのシステムが役に立つことでしょう。