You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

  1. #!/bin/bash
  2. ######################################################
  3. # Name: refresh-NebulaCA
  4. # Description: Creates a new cert for a node based
  5. # on the node cert provided.
  6. #
  7. # Created By: HMSheets
  8. ######################################################
  9. invalid_args_msg () {
  10. echo "Invalid Parameter(s) Entered: $1"
  11. exit
  12. }
  13. help_msg () {
  14. echo "Usage of refresh-NebulaCA <flags>: refresh an existing nebula ca"
  15. echo " -n|--caname"
  16. echo " Name to use for the new CA. Used in the CA cert file and in the filename"
  17. echo " -r|--rootpath"
  18. echo " Root path of existing CA"
  19. echo " -f|--cafilename"
  20. echo " Filename of the existing CA"
  21. echo " -i|--issuer"
  22. echo " Name of the Org Issuing and authorizing the creation of the new Nebula CA"
  23. echo " -h|--help"
  24. echo " This help text, but you already knew that... right?!?!"
  25. exit
  26. }
  27. POSITIONAL=()
  28. while [[ $# -gt 0 ]]
  29. do
  30. key="$1"
  31. case $key in
  32. -h|--help)
  33. help_msg
  34. ;;
  35. -n|--caname)
  36. CANAME="$2"
  37. shift # past argument
  38. shift # past value
  39. ;;
  40. -r|--rootpath)
  41. ROOTPATH="$2"
  42. shift # past argument
  43. shift # past value
  44. ;;
  45. -f|--cafilename)
  46. CAFILENAME="$2"
  47. shift # past argument
  48. shift # past value
  49. ;;
  50. # -k|--cakeyname)
  51. # CAKEYNAME="$2"
  52. # shift # past argument
  53. # shift # past value
  54. # ;;
  55. -i|--issuer)
  56. ISSUER="$2"
  57. shift # past argument
  58. shift # past value
  59. ;;
  60. *) # unknown option
  61. invalid_args_msg #catch all
  62. ;;
  63. esac
  64. done
  65. set -- "${POSITIONAL[@]}" # restore positional parameters
  66. DATETIME=$(date '+%Y%m%d-%H%M%S')
  67. #CANAME=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s .[].details.name | sed 's/["]//g')
  68. #CAIPS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.ips | sed 's/[]["]//g')
  69. #NODEGROUPS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.groups | sed 's/[]["]//g') # | sed 's/,/ /g'))
  70. CERTISCASTATUS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${CAFILENAME} -json | jq -s --compact-output .[].details.isCa)
  71. # Create new file name variable
  72. NEWFILENAME="${CANAME}_${DATETIME}"
  73. if [[ $CERTISCASTATUS == false ]]; then
  74. echo "Certificate is a Node Certificate. Try again by providing the CA Certificate."
  75. exit
  76. fi
  77. if [[ $CERTISCASTATUS == true ]]; then
  78. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  79. echo "Node Name: ${CANAME}"
  80. echo "Node IPs: ${ISSUER}"
  81. #echo "Node Groups: ${NODEGROUPS[@]}"
  82. echo "Certificate isCa Status: ${CERTISCASTATUS}"
  83. echo "DateTime: ${DATETIME}"
  84. echo "NEWFILENAME: ${NEWFILENAME}"
  85. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  86. ${ROOTPATH}/nebula-cert sign -name ${CANAME} -out-crt ${ROOTPATH}/${NEWFILENAME}.crt -out-key ${ROOTPATH}/${NEWFILENAME}.key
  87. fi