IsraelTorres

UUIDgenkey.sh

Sep 19th, 2011
214
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # ./UUIDgenkey.sh
  3. # Israel Torres hakin9@israeltorres.org
  4. # Tue Aug 23 12:53:46 PDT 2011
  5. # UUIDgenkey - For My Eyes Only"
  6. #
  7. # see function usage/example below
  8. #
  9. # this function runs system_profiler to get our version; here we look for Mac OS X
  10. function getOSCheck {
  11. system_profiler SPSoftwareDataType | grep 'System Version' | grep -q 'Mac OS X'
  12. }
  13.  
  14. # this function gets the Mac's universally unique identifier (UUID) to use as the 36 character password
  15. function getUniqueID {
  16. myUUID=$(system_profiler SPHardwareDataType | grep 'Hardware UUID' | cut -d ':' -f 2 | sed 's/^ *//')
  17. }
  18.  
  19. # this function assigns a fake UUID to the variable myUUID for demonstration purposes only/testing
  20. function setDEMOUniqueID { # FOR DEMO ONLY
  21. myUUID='01234567-ABCD-0123-ABCD-0123456789AB'
  22. }
  23.  
  24. # this function encrypts the string using AES-256 using myUUID as the password
  25. function passEncrypt {
  26. PLAIN=$1
  27. SECRET=$(echo $PLAIN | openssl enc -aes-256-cbc -salt -pass pass:$myUUID | xxd -u -p |  tr -d '\n')
  28. echo $SECRET
  29. }
  30.  
  31. # this function decrypts the string using AES-256 using myUUID as the password
  32. function passDecrypt {
  33. CIPHER=$1
  34. SECRET=$(echo $CIPHER | xxd -r -p | openssl enc -d -aes-256-cbc -pass pass:$myUUID)
  35. echo $SECRET
  36. }
  37.  
  38. # this function exits the shell script if it is a non-Mac OS X system
  39. function validateOS {
  40. getOSCheck; if [ $? -ne 0 ]; then
  41. echo "Mac OS X check failed"
  42. exit 1
  43. fi
  44. }
  45.  
  46. # this function displays the usage and examples if parameter requirements aren't fulfilled
  47. function usage {
  48. echo "usage: $0 '-e|-d|-r|-f' 'string'"
  49. echo "example: $0 -e encryptstring"
  50. echo "example: $0 -d decryptstring"
  51. echo "example: $0 -r encryptstringwithDEMOUUID"
  52. echo "example: $0 -f decryptstringwithDEMOUUID"
  53. exit 1
  54. }
  55.  
  56. # this begin the main conditional flow
  57. validateOS
  58.  
  59. if [ ! $# -ne 2 ]; then
  60.     operation=$1
  61.     stringvar=$2
  62.     if [ $operation == "-e" ]; then
  63.         getUniqueID
  64.         passEncrypt "$stringvar"
  65.         exit $?
  66.     fi
  67.     if [ $operation == "-d" ]; then
  68.         getUniqueID
  69.         passDecrypt "$stringvar"
  70.         exit $?
  71.     fi
  72.     if [ $operation == "-r" ]; then
  73.         setDEMOUniqueID
  74.         passEncrypt "$stringvar"
  75.         exit $?
  76.     fi
  77.     if [ $operation == "-f" ]; then
  78.         setDEMOUniqueID
  79.         passDecrypt "$stringvar"
  80.         exit $?
  81.     fi
  82.  
  83.     usage
  84.  
  85. else
  86.     usage
  87. fi
  88.  
  89. #EOF
RAW Paste Data