Advertisement
ZZ9

MakeOpenVPN.sh

ZZ9
Apr 30th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #!/bin/bash
  2. # Default Variable Declarations
  3. DEFAULT="Default.txt"
  4. FILEEXT=".ovpn"
  5. CRT=".crt"
  6. KEY=".3des.key"
  7. CA="ca.crt"
  8. TA="ta.key"
  9. #Ask for a Client name
  10. echo "Please enter an existing Client Name:"
  11. read NAME
  12. #1st Verify that client’s Public Key Exists
  13. if [ ! -f $NAME$CRT ]; then
  14. echo "[ERROR]: Client Public Key Certificate not found: $NAME$CRT"
  15. exit
  16. fi
  17. echo "Client’s cert found: $NAME$CR"
  18. #Then, verify that there is a private key for that client
  19. if [ ! -f $NAME$KEY ]; then
  20. echo "[ERROR]: Client 3des Private Key not found: $NAME$KEY"
  21. exit
  22. fi
  23. echo "Client’s Private Key found: $NAME$KEY"
  24.  
  25. #Confirm the CA public key exists
  26. if [ ! -f $CA ]; then
  27. echo "[ERROR]: CA Public Key not found: $CA"
  28. exit
  29. fi
  30. echo "CA public Key found: $CA"
  31.  
  32. #Confirm the tls-auth ta key file exists
  33. if [ ! -f $TA ]; then
  34. echo "[ERROR]: tls-auth Key not found: $TA"
  35. exit
  36. fi
  37. echo "tls-auth Private Key found: $TA"
  38. #Ready to make a new .opvn file - Start by populating with the
  39. default file
  40. cat $DEFAULT > $NAME$FILEEXT
  41. #Now, append the CA Public Cert
  42. echo "<ca>" >> $NAME$FILEEXT
  43. cat $CA >> $NAME$FILEEXT
  44. echo "</ca>" >> $NAME$FILEEXT
  45.  
  46. #Next append the client Public Cert
  47. echo "<cert>" >> $NAME$FILEEXT
  48. cat $NAME$CRT | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >> $NAME$FILEEXT
  49. echo "</cert>" >> $NAME$FILEEXT
  50. #Then, append the client Private Key
  51. echo "<key>" >> $NAME$FILEEXT
  52. cat $NAME$KEY >> $NAME$FILEEXT
  53. echo "</key>" >> $NAME$FILEEXT
  54. #Finally, append the TA Private Key
  55. echo "<tls-auth>" >> $NAME$FILEEXT
  56. cat $TA >> $NAME$FILEEXT
  57. echo "</tls-auth>" >> $NAME$FILEEXT
  58. echo "Done! $NAME$FILEEXT Successfully Created."
  59.  
  60. #Script written by Eric Jodoin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement