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.

99 lines
3.4 KiB

  1. #!/usr/bin/env sh
  2. # Script for acme.sh to deploy certificates to a VMware UAG appliance
  3. #
  4. # The following variables can be used:
  5. #
  6. # export DEPLOY_VMWAREUAG_USERNAME="admin" - optional
  7. # export DEPLOY_VMWAREUAG_PASSWORD="" - required
  8. # export DEPLOY_VMWAREUAG_HOST="" - required - host:port - comma seperated list
  9. # export DEPLOY_VMWAREUAG_HTTPS_INSECURE="1" - optional - defaults to insecure
  10. #
  11. #
  12. ######## Public functions #####################
  13. #domain keyfile certfile cafile fullchain
  14. vmwareuag_deploy() {
  15. _cdomain="$1"
  16. _ckey="$2"
  17. _ccert="$3"
  18. _cca="$4"
  19. _cfullchain="$5"
  20. # Some defaults
  21. DEPLOY_VMWAREUAG_USERNAME_DEFAULT="admin"
  22. DEPLOY_VMWAREUAG_HTTPS_INSECURE="1"
  23. _debug _cdomain "${_cdomain}"
  24. _debug _ckey "${_ckey}"
  25. _debug _ccert "${_ccert}"
  26. _debug _cca "${_cca}"
  27. _debug _cfullchain "${_cfullchain}"
  28. # USERNAME is optional. If not provided then assume "${DEPLOY_VMWAREUAG_USERNAME_DEFAULT}"
  29. if [ -n "${DEPLOY_VMWAREUAG_USERNAME}" ]; then
  30. Le_Deploy_vmwareuag_username="${DEPLOY_VMWAREUAG_USERNAME}"
  31. _savedomainconf Le_Deploy_vmwareuag_username "${Le_Deploy_vmwareuag_username}"
  32. elif [ -z "${Le_Deploy_vmwareuag_username}" ]; then
  33. Le_Deploy_vmwareuag_username="${DEPLOY_VMWAREUAG_USERNAME_DEFAULT}"
  34. fi
  35. # PASSWORD is required.
  36. if [ -n "${DEPLOY_VMWAREUAG_PASSWORD}" ]; then
  37. Le_Deploy_vmwareuag_password="${DEPLOY_VMWAREUAG_PASSWORD}"
  38. _savedomainconf Le_Deploy_vmwareuag_password "${Le_Deploy_vmwareuag_password}"
  39. elif [ -z "${Le_Deploy_vmwareuag_password}" ]; then
  40. _err "DEPLOY_VMWAREUAG_PASSWORD is required"
  41. return 1
  42. fi
  43. # HOST is required.
  44. if [ -n "${DEPLOY_VMWAREUAG_HOST}" ]; then
  45. Le_Deploy_vmwareuag_host="${DEPLOY_VMWAREUAG_HOST}"
  46. _savedomainconf Le_Deploy_vmwareuag_host "${Le_Deploy_vmwareuag_host}"
  47. elif [ -z "${Le_Deploy_vmwareuag_host}" ]; then
  48. _err "DEPLOY_VMWAREUAG_HOST is required"
  49. return 1
  50. fi
  51. # HTTPS_INSECURE is optional. If not provided then assume "${DEPLOY_VMWAREUAG_HTTPS_INSECURE_DEFAULT}"
  52. if [ -n "${DEPLOY_VMWAREUAG_HTTPS_INSECURE}" ]; then
  53. Le_Deploy_vmwareuag_https_insecure="${DEPLOY_VMWAREUAG_HTTPS_INSECURE}"
  54. _savedomainconf Le_Deploy_vmwareuag_https_insecure "${Le_Deploy_vmwareuag_https_insecure}"
  55. elif [ -z "${Le_Deploy_vmwareuag_https_insecure}" ]; then
  56. Le_Deploy_vmwareuag_https_insecure="${DEPLOY_VMWAREUAG_HTTPS_INSECURE}"
  57. fi
  58. # Set variables for later use
  59. _user="${Le_Deploy_vmwareuag_username}:${Le_Deploy_vmwareuag_password}"
  60. # convert key and fullchain into "single line pem" for JSON request
  61. _privatekeypem="$(tr '\n' '\000' <"${_ckey}" | sed 's/\x0/\\n/g')"
  62. _certchainpem="$(tr '\n' '\000' <"${_cfullchain}" | sed 's/\x0/\\n/g')"
  63. # api path
  64. _path="/rest/v1/config/certs/ssl/end_user"
  65. _debug _user "${_user}"
  66. _debug _privatekeypem "${_privatekeypem}"
  67. _debug _certchainpem "${_certchainpem}"
  68. _debug _path "${_path}"
  69. # Create JSON request
  70. _jsonreq="$(printf '{ "privateKeyPem": "%s", "certChainPem": "%s" }' "${_privatekeypem}" "${_certchainpem}")"
  71. _debug _jsonreq "${_jsonreq}"
  72. # dont verify certs if config set
  73. if [ "${Le_Deploy_vmwareuag_https_insecure}" = "1" ]; then
  74. # shellcheck disable=SC2034
  75. HTTPS_INSECURE="1"
  76. fi
  77. # do post against UAG host(s)
  78. for _host in $(echo "${Le_Deploy_vmwareuag_host}" | tr ',' ' '); do
  79. _url="https://${_host}${_path}"
  80. _debug _url "${_url}"
  81. _post "${_jsonreq}" "${_url}" "" "PUT" "application/json"
  82. done
  83. return 0
  84. }