{"id":1698,"date":"2015-11-13T00:18:10","date_gmt":"2015-11-12T16:18:10","guid":{"rendered":"http:\/\/boweihe.me\/?p=1698"},"modified":"2015-11-13T00:18:10","modified_gmt":"2015-11-12T16:18:10","slug":"use-an-openwrt-router-to-log-in-802-1x-mschapv2-wired-network-at-sutd","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=1698","title":{"rendered":"Use an OpenWrt Router to log in 802.1x (MSCHAPV2) wired network at SUTD  (eduroam)"},"content":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u57fa\u4e8eOpenWrt\u7684\u8def\u7531\u5668\u8fdb\u884c802.1X\u6709\u7ebf\u7f51\u767b\u5f55\u9a8c\u8bc1\uff08\u5373\u4f5c\u4e3a802.1X \u5ba2\u6237\u7aef\uff09\u3002<br \/>\nThis post tells my experience on trying to connect to a wired network at Singapore University of Technology and Design (SUTD) by using a OpenWrt-powered router (a modified TPLink WR-703n).<\/p>\n<h1>Prerequisites<\/h1>\n<p>What you need is a router which runs <strong>OpenWrt<\/strong> (or other unix-based OS like dd-wrt). For me I have a hardware-hacked TPLink Wr703n (technically it was a WR-702n but their mainboards are same). My modified router has 64 MB ram and 8MB ROM, which allows me to install and run OpenWrt (currently version 14.04) and some necessary apps.<br \/>\nYou should know the fundamental about OpenWrt. If not, please visit\u00a0<a href=\"https:\/\/wiki.openwrt.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/wiki.openwrt.org\/ <\/a>\u00a0for help.<\/p>\n<h1>Steps<\/h1>\n<p>Before start, please do not power off your device unless it&#8217;s requested explicitly.<br \/>\nFirst, build up a SSH connection to your router, for me on Windows, I connect my router (192.168.1.1) via <a href=\"http:\/\/www.putty.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Putty<\/a>.<br \/>\nIf this is the first time that you log in via SSH terminal, you should firstly set up the root password at http:\/\/192.168.1.1\/ on your internet browser (this IP\u00a0address might vary on different devices)<\/p>\n<h2>Remove wpad-mini<\/h2>\n<p>We will have to remove the mini version of wpad (wpad = wpa_supplicant + hostapd) since it is not powerful enough to handle a 802.1X authentication. So on your SSH terminal, after you&#8217;ve successfully logged in, type this<\/p>\n<pre class=\"lang:default decode:true\">opkg remove wpad-mini<\/pre>\n<h2>Install wpad<\/h2>\n<p>Then install the full version of wpad, you may download it from<\/p>\n<pre class=\"\">https:\/\/downloads.openwrt.org\/barrier_breaker\/14.07\/ar71xx\/generic\/packages\/base\/wpad_2014-06-03.1-3_ar71xx.ipk<\/pre>\n<p>and you must find a way to transfer it to your router. For me I choose HFS (http:\/\/www.rejetto.com\/hfs\/) to build a small http file server on my personal computer. and then I use the &#8216;wget&#8217; commend to download the file<\/p>\n<pre class=\"lang:default decode:true\">cd \/tmp\nwget http:\/\/YOUR_HFS_SERVER_IP\/wpad_2014-06-03.1-3_ar71xx.ipk<\/pre>\n<p>then install it<\/p>\n<pre class=\"lang:default decode:true \">opkg install wpad_2014-06-03.1-3_ar71xx.ipk<\/pre>\n<p><strong>OR\u00a0<\/strong>if you have Internet connection on your router (oh you must be kidding) you can directly type<\/p>\n<pre class=\"lang:default decode:true\">opkg update\nopkg install wpad<\/pre>\n<h2>Configuration<\/h2>\n<h3>(For wr-703n only)<\/h3>\n<p><span style=\"color: #993366;\">You may need to set up a wireless connection on your router first, please search on Google to enable your WiFi port. Or you may explore the &#8216;Network&#8217; &#8211;&gt; &#8216;Wifi&#8217; page, it&#8217;s easy to get started!<\/span><br \/>\nBy default, OpenWrt uses the only ethernet port on the little wr-703n as a LAN port, buy in this time we need to set it to a WAN port. It means that we&#8217;ll use an Ethernet wire to connect the world, and use the wireless signal to connect your devices, e.g. your laptops, cellphones, pads&#8230;<br \/>\n[INTERNET] \u00a0&lt;&#8212;-wired conn.&#8212;&gt; [ROUTER] &lt;&#8212;-wireless conn.&#8212;-&gt; [DEVICES]<br \/>\n<span style=\"color: #000000;\">This configuration can be easily done on OpenWrt&#8217;s web interface, visit\u00a0http:\/\/YOUR_ROUTER&#8217;s_IP\/ (for me it is 192.168.1.1 ) on your browser and enter your password.<\/span><br \/>\nThen go to &#8216;Networks&#8217; &#8211;&gt; &#8216;Interfaces&#8217;, there should be only one interface called &#8216;LAN&#8217;. And we need to add the &#8216;wan&#8217; interface. so click on the button &#8216;Add new interface&#8217; below\u00a0<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_add_new_interface.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1706 alignnone\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_add_new_interface.jpg\" alt=\"openwrt_add_new_interface\" width=\"210\" height=\"44\" \/><\/a><br \/>\nThen set it as follow:<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_add_wan_interface.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1707\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_add_wan_interface.jpg\" alt=\"openwrt_add_wan_interface\" width=\"803\" height=\"426\" \/><\/a><br \/>\nand click &#8216;submit&#8217;.<br \/>\nNext, we need to cease the bond between port <em>eth0<\/em> and interface <em>LAN.\u00a0<\/em>Turn back to the interface page, and click the &#8216;Edit&#8217;\u00a0<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_edit_interface.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1708\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_edit_interface.jpg\" alt=\"openwrt_edit_interface\" width=\"149\" height=\"46\" \/><\/a>on <strong>LAN<\/strong> interface.<br \/>\nThen click on the &#8216;Physical Settings&#8217; page\u00a0<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_interface_lan.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-1709\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_interface_lan-1024x316.jpg\" alt=\"openwrt_interface_lan\" width=\"660\" height=\"204\" \/><\/a><br \/>\nand set the physical ports binding as follow (Un-tick &#8216;eth0&#8217; and tick wireless network):<br \/>\n<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_wr703_lan_phy.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1710\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_wr703_lan_phy.jpg\" alt=\"openwrt_wr703_lan_phy\" width=\"1004\" height=\"414\" \/><\/a><br \/>\nthen click on &#8216;Save and Apply&#8217; button in the bottom.<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_saveandapply.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1711\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/openwrt_saveandapply.jpg\" alt=\"openwrt_saveandapply\" width=\"140\" height=\"44\" \/><\/a><br \/>\nThen restart your router.<br \/>\n<span style=\"color: #ff6600;\">NOTICE: From now on you can only connect your router through wireless connection, the Ethernet port is set as a WAN port.<\/span><\/p>\n<h3>wpa_supplicant<\/h3>\n<p>The next step is to set up 802.1X authentication.<br \/>\nThe wpa_supplicant module will be used to maintain the authentication process, so we need a configuration file first.<br \/>\nType these in your monitor to start vi (a built-in text editor):<\/p>\n<pre class=\"lang:sh decode:true \">vi \/etc\/config\/wpa.conf<\/pre>\n<p>then key in &#8216;i&#8217; to start the insert mode. Copy the following text<\/p>\n<pre class=\"lang:sh decode:true\" title=\"wpa_supplicant config file\">ctrl_interface=\/var\/run\/wpa_supplicant\nctrl_interface_group=root\nap_scan=0\nnetwork={\n        key_mgmt=IEEE8021X\n        eap=MSCHAPV2   #THIS LINE IS IMPORTANT!\n        eapol_flags=0\n        identity=\"YOUR USERNAME\"\n        password=\"YOUR PASSWORD\"\n        phase1=\"peaplabel=1\"\n        phase2=\"auth=MSCHAPV2\"  #THIS LINE MAYBE USELESS\n}\n<\/pre>\n<p>and then, on your puppy terminal, use the right button of your mouse to paste them into vi text editor. Next, press &#8216;Ese&#8217; button on your keyboard and input <strong><span style=\"color: #0000ff;\">:wq<\/span> <\/strong>to quit vi editor with the file written to your router.<\/p>\n<h1>Connection<\/h1>\n<p>Finally it&#8217;s time to build up connection, first <strong>un<\/strong>plug your Ethernet wire from the router if you&#8217;ve did so.<br \/>\nThen in the putty terminal, type<\/p>\n<pre class=\"lang:sh decode:true \">killall wpa_supplicant # Kill all wpa_supplicant programs on-the-run\nwpa_supplicant -D wired -i eth0 -c \/etc\/config\/wpa.conf &amp;<\/pre>\n<p>The second line is the key, it tries to authenticate with the server using your configuration file on the wired port <em>eth0<\/em>.<br \/>\nAnd now please <strong>plug<\/strong> your Ethernet wire into the router, then the best part starts like this&#8230;<br \/>\n<a href=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/wr703-8021x-conn.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1717\" src=\"http:\/\/boweihe.me\/wp-content\/uploads\/2015\/11\/wr703-8021x-conn.jpg\" alt=\"wr703-8021x-conn\" width=\"821\" height=\"213\" \/><\/a><br \/>\nOnce you see &#8216;SUCCESS&#8217; in those output you may press the Enter key to resume from shell execution.<br \/>\nIt&#8217;s done.<br \/>\nIn case you may encounter some error in the process, try change the parameters in your configuration file because not all 802.1x are the same. I once faced the credential error then found out that it&#8217;s the bad parameter in the &#8216;EAP&#8217; setting.<\/p>\n<pre class=\"lang:sh decode:true\" title=\"wpa_supplicant config file\">#eap=PEAP # It was PEAP but turns out to be a failure\neap=MSCHAPV2 # This is the right thing to bypass credentials<\/pre>\n<h1>Enable Service Autostart<\/h1>\n<p>Here are the scripts to auto-startup the 802.1x auth after the router finished booting. In your puppy terminal, type<\/p>\n<pre class=\"lang:default decode:true\">vi \/etc\/init.d\/wpa<\/pre>\n<p>Then push &#8216;I&#8217; button on the keyboard to insert<\/p>\n<pre class=\"lang:default decode:true\">#!\/bin\/sh \/etc\/rc.common\nSTART=99\nstart() {\n    echo start\n    wpa_supplicant -D wired -i eth0 -c \/etc\/config\/wpa.conf &amp;\n}<\/pre>\n<p>and push &#8216;Esc&#8217;, and type in <strong><span style=\"color: #0000ff;\">:wq <\/span><\/strong><span style=\"color: #000000;\">to quit the editor.<\/span><br \/>\nBack to the command terminal, type in<\/p>\n<pre class=\"lang:sh decode:true\">chmod +x \/etc\/init.d\/wpa\nchmod 755 \/etc\/init.d\/wpa\n\/etc\/init.d\/wpa enable # Enable autostart<\/pre>\n<p>&nbsp;<\/p>\n<h1>References<\/h1>\n<ul>\n<li><a href=\"https:\/\/forum.openwrt.org\/viewtopic.php?id=28524\" target=\"_blank\" rel=\"noopener noreferrer\">WRT160NL Wired 802.1x PEAP surfnet\/Eduroam\/securew2 wpa_supplicant\u00a0<\/a><\/li>\n<li><a href=\"http:\/\/7yue7.net\/?p=239\" target=\"_blank\" rel=\"noopener noreferrer\">TL-WR703N\u8def\u7531\u5237DD-WRT\u81ea\u5236\u7cfb\u7edf\u767b\u5f55802.1X<\/a><\/li>\n<li><a href=\"http:\/\/www.cnblogs.com\/kkzxak47\/archive\/2013\/03\/16\/2961964.html\" target=\"_blank\" rel=\"noopener noreferrer\">\u65e0\u7ebf\u8def\u7531\u5668\u4e0a\u5b89\u88c5OpenWRT\uff0c\u5728\u9700\u8981\u6807\u51c6802.1x\u8ba4\u8bc1\u7684\u7f51\u7edc\u4e2d\u65e0\u7ebf\u4e0a\u7f51<\/a><\/li>\n<li><a href=\"https:\/\/wiki.openwrt.org\/doc\/techref\/initscripts\" target=\"_blank\" rel=\"noopener noreferrer\">Init Scripts<\/a><\/li>\n<li>Google keywords: OpenWrt\u00a0eduroam 802.1x MSCHAP<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u57fa\u4e8eOpenWrt\u7684\u8def\u7531\u5668\u8fdb\u884c802.1X\u6709\u7ebf\u7f51\u767b\u5f55\u9a8c\u8bc1\uff08\u5373\u4f5c\u4e3a802.1X \u5ba2\u6237\u7aef\uff09\u3002 This post tells my experience on trying to connect to a wired network at Singapore University of Technology and Design (SUTD) by using a OpenWrt-powered router (a modified TPLink WR-703n). Prerequisites What you need is a router which runs OpenWrt (or other unix-based OS like dd-wrt). For me I have a hardware-hacked TPLink [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[15,82,107,127],"class_list":["post-1698","post","type-post","status-publish","format-standard","hentry","category-technical","tag-802-1x","tag-openwrt","tag-sutd","tag-wr703n"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1698"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1698\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}