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.

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