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.

105 lines
3.5 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 exported:
  5. #
  6. # export DEPLOY_VMWAREUAG_USERNAME="admin"
  7. # export DEPLOY_VMWAREUAG_PASSWORD="" - required
  8. # export DEPLOY_VMWAREUAG_HOST="" - required (space seperated list) host:port
  9. # export DEPLOY_VMWAREUAG_HTTPS_INSECURE="1" - 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. if [ -f "${DOMAIN_CONF}" ]; then
  24. # shellcheck disable=SC1090
  25. . "${DOMAIN_CONF}"
  26. fi
  27. _debug _cdomain "${_cdomain}"
  28. _debug _ckey "${_ckey}"
  29. _debug _ccert "${_ccert}"
  30. _debug _cca "${_cca}"
  31. _debug _cfullchain "${_cfullchain}"
  32. # USERNAME is optional. If not provided then assume "${DEPLOY_VMWAREUAG_USERNAME_DEFAULT}"
  33. if [ -n "${DEPLOY_VMWAREUAG_USERNAME}" ]; then
  34. Le_Deploy_vmwareuag_username="${DEPLOY_VMWAREUAG_USERNAME}"
  35. _savedomainconf Le_Deploy_vmwareuag_username "${Le_Deploy_vmwareuag_username}"
  36. elif [ -z "${Le_Deploy_vmwareuag_username}" ]; then
  37. Le_Deploy_vmwareuag_username="${DEPLOY_VMWAREUAG_USERNAME_DEFAULT}"
  38. fi
  39. # PASSWORD is required.
  40. if [ -n "${DEPLOY_VMWAREUAG_PASSWORD}" ]; then
  41. Le_Deploy_vmwareuag_password="${DEPLOY_VMWAREUAG_PASSWORD}"
  42. _savedomainconf Le_Deploy_vmwareuag_password "${Le_Deploy_vmwareuag_password}"
  43. elif [ -z "${Le_Deploy_vmwareuag_password}" ]; then
  44. _err "DEPLOY_VMWAREUAG_PASSWORD is required"
  45. return 1
  46. fi
  47. # HOST is required.
  48. if [ -n "${DEPLOY_VMWAREUAG_HOST}" ]; then
  49. Le_Deploy_vmwareuag_host="${DEPLOY_VMWAREUAG_HOST}"
  50. _savedomainconf Le_Deploy_vmwareuag_host "${Le_Deploy_vmwareuag_host}"
  51. elif [ -z "${Le_Deploy_vmwareuag_host}" ]; then
  52. _err "DEPLOY_VMWAREUAG_HOST is required"
  53. return 1
  54. fi
  55. # HTTPS_INSECURE is optional. If not provided then assume "${DEPLOY_VMWAREUAG_HTTPS_INSECURE_DEFAULT}"
  56. if [ -n "${DEPLOY_VMWAREUAG_HTTPS_INSECURE}" ]; then
  57. Le_Deploy_vmwareuag_https_insecure="${DEPLOY_VMWAREUAG_HTTPS_INSECURE}"
  58. _savedomainconf Le_Deploy_vmwareuag_https_insecure "${Le_Deploy_vmwareuag_https_insecure}"
  59. elif [ -z "${Le_Deploy_vmwareuag_https_insecure}" ]; then
  60. Le_Deploy_vmwareuag_https_insecure="${DEPLOY_VMWAREUAG_HTTPS_INSECURE}"
  61. fi
  62. # Set variables for later use
  63. _user="${Le_Deploy_vmwareuag_username}:${Le_Deploy_vmwareuag_password}"
  64. _privatekeypem="$(awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' <"${_ckey}")"
  65. _certchainpem="$(awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' <"${_cfullchain}")"
  66. _path="/rest/v1/config/certs/ssl/end_user"
  67. _debug _user "${_user}"
  68. _debug _privatekeypem "${_privatekeypem}"
  69. _debug _certchainpem "${_certchainpem}"
  70. _debug _path "${_path}"
  71. # Create JSON request
  72. _jsonreq="$(printf '{ "privateKeyPem": "%s", "certChainPem": "%s" }' "${_privatekeypem}" "${_certchainpem}")"
  73. _debug JSON "${_jsonreq}"
  74. # dont verify certs if config set
  75. _old_HTTPS_INSECURE="${HTTPS_INSECURE}"
  76. if [ "${Le_Deploy_vmwareuag_https_insecure}" = "1" ]; then
  77. HTTPS_INSECURE="1"
  78. fi
  79. # do post against UAG host(s)
  80. for _host in ${Le_Deploy_vmwareuag_host}; do
  81. _url="https://${_host}${_path}"
  82. _debug _url "${_url}"
  83. _post "${_jsonreq}" "${_url}" "" "PUT" "application/json"
  84. done
  85. # reset HTTP_INSECURE
  86. HTTPS_INSECURE="${_old_HTTPS_INSECURE}"
  87. return 0
  88. }