Use .netrc for corp wifi password?

227 Views Asked by At

I use a .netrc file for authentication args for git. I have test automation that configures an Android device before executing tests, and I need the device joined to a corp wifi network. I've scripted this by adding the following parameters to the wpa_supplicant.conf and pushing it back:

WIRELESS_CTRL_INTERFACE=wlan0
WIRELESS_SSID=ST-DEV
WIRELESS_KEY_MGMT="WPA-EAP IEEE8021X"
WIRELESS_EAP=PEAP
WIRELESS_USER=[me]
WIRELESS_PASSWORD=[my password]

I'd like to use .netrc for this, if possible, so the config script can be checked into source and shared with the team and they can use their credentials, and we'll only need to update our .netrc when our passwords expire.

But it looks like .netrc matches remote machine names. Is there a way to get .netrc to see my SSID ST-DEV as a machine name token and populate the two credential variables when the script is executed with what I safely store in .netrc so that the updated wpa_supplicant.conf pushed back to the Android device remains current?

1

There are 1 best solutions below

0
On

Figured it out: use awk to parse .netrc, assign the credentials to the variables, write them to wpa_supplicant.conf and push it to the device. Works!

WIRELESS_CTRL_INTERFACE=wlan0
WIRELESS_SSID=ST-DEV
WIRELESS_KEY_MGMT="WPA-EAP IEEE8021X"
WIRELESS_EAP=PEAP
WIRELESS_USER=$(awk '$1 == "login" { print $2}' /home/[me]/.netrc)
WIRELESS_PASSWORD=$(awk '$1 == "password" { print $2}' /home/[me]/.netrc)

You'll need awk. You'll also want your script to rm the local copy of wpa_supplicant.conf once complete because your password is still in plaintext there (yep, Android stores your wifi passwords in plaintext).