Advertisement
s243a

getWpaPSK() - /usr/sbin/wag-profiles.sh - puppylinux

Oct 2nd, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.43 KB | None | 0 0
  1. # Line #1158 of /usr/sbin/wag-profiles.sh
  2. # http://www.pearltrees.com/s243a/getwpapsk-profiles-puppylinux/id16403226
  3.  
  4. # A function to get the psk from wpa_passphrase (moved out of useWpaSupplicant
  5. getWpaPSK(){
  6.     # If key is not hex, then convert to hex
  7.     echo "$PROFILE_KEY" | grep -Eq "^[0-9a-fA-F]{64}$"
  8.     if [ $? -eq 0 ] ; then
  9.         PSK="$PROFILE_KEY"
  10.     else
  11.         #KEY_SIZE=`echo "${PROFILE_KEY}" | wc -c`
  12.         KEY_SIZE=${#PROFILE_KEY}
  13.         if [ $KEY_SIZE -lt 8 ] || [ $KEY_SIZE -gt 64 ] ; then
  14.             giveErrorDialog "Error!
  15. Shared key must be either
  16. - ASCII between 8 and 63 characters
  17. - 64 characters hexadecimal
  18. "
  19.             return 1
  20.         else #if [ $KEY_SIZE -lt 8 ] || [ $KEY_SIZE -gt 64 ]
  21.             # Dougal: add escaping of funny chars in passphrase
  22.             # also quote the inner subshell
  23.             # No! don't need subshell apparently, escaping chars is unneeded
  24.             #"$( echo "$PROFILE_KEY" | sed 's%\$%\\$%g ; s%`%\\`%g ; s%"%\\"%g' )"
  25.             ##  Strage: the first grep below was enough for me, but a user got
  26.             ##+ errors, because it didn't filter out the "#psk" line!
  27.             PSK=$(wpa_passphrase "$PROFILE_ESSID" "$PROFILE_KEY" | \
  28.                    grep -F "psk=" | grep -Fv '#psk' | cut -d"=" -f2 )
  29.             echo "PSK is |$PSK|" >> $DEBUG_OUTPUT
  30.             # make sure we got something!
  31.             if [ ! "$PSK" ] ; then
  32.               giveErrorDialog "$L_MESSAGE_Bad_PSK"
  33.               return 1
  34.             fi
  35.         fi #if [ $KEY_SIZE -lt 8 ] || [ $KEY_SIZE -gt 64 ] ; then
  36.     fi #if [ $? -eq 0 ] ; then #check for hex
  37.     return 0
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement