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.

131 lines
4.3 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 (comma seperated list)
  9. # export DEPLOY_VMWAREUAG_PORT="9443"
  10. # export DEPLOY_VMWAREUAG_SSL_VERIFY="yes"
  11. #
  12. #
  13. ######## Public functions #####################
  14. #domain keyfile certfile cafile fullchain
  15. vmwareuag_deploy() {
  16. _cdomain="$1"
  17. _ckey="$2"
  18. _ccert="$3"
  19. _cca="$4"
  20. _cfullchain="$5"
  21. # Some defaults
  22. DEPLOY_VMWAREUAG_USERNAME_DEFAULT="admin"
  23. DEPLOY_VMWAREUAG_SSL_VERIFY_DEFAULT="yes"
  24. DEPLOY_VMWAREUAG_PORT_DEFAULT="9443"
  25. if [ -f "${DOMAIN_CONF}" ]; then
  26. # shellcheck disable=SC1090
  27. . "${DOMAIN_CONF}"
  28. fi
  29. _debug _cdomain "${_cdomain}"
  30. _debug _ckey "${_ckey}"
  31. _debug _ccert "${_ccert}"
  32. _debug _cca "${_cca}"
  33. _debug _cfullchain "${_cfullchain}"
  34. # USERNAME is optional. If not provided then assume "${DEPLOY_VMWAREUAG_USERNAME_DEFAULT}"
  35. if [ -n "${DEPLOY_VMWAREUAG_USERNAME}" ]; then
  36. Le_Deploy_vmwareuag_username="${DEPLOY_VMWAREUAG_USERNAME}"
  37. _savedomainconf Le_Deploy_vmwareuag_username "${Le_Deploy_vmwareuag_username}"
  38. elif [ -z "${Le_Deploy_vmwareuag_username}" ]; then
  39. Le_Deploy_vmwareuag_username="${DEPLOY_VMWAREUAG_USERNAME_DEFAULT}"
  40. fi
  41. # PASSWORD is required.
  42. if [ -n "${DEPLOY_VMWAREUAG_PASSWORD}" ]; then
  43. Le_Deploy_vmwareuag_password="${DEPLOY_VMWAREUAG_PASSWORD}"
  44. _savedomainconf Le_Deploy_vmwareuag_password "${Le_Deploy_vmwareuag_password}"
  45. elif [ -z "${Le_Deploy_vmwareuag_password}" ]; then
  46. _err "DEPLOY_VMWAREUAG_PASSWORD is required"
  47. return 1
  48. fi
  49. # HOST is required.
  50. if [ -n "${DEPLOY_VMWAREUAG_HOST}" ]; then
  51. Le_Deploy_vmwareuag_host="${DEPLOY_VMWAREUAG_HOST}"
  52. _savedomainconf Le_Deploy_vmwareuag_host "${Le_Deploy_vmwareuag_host}"
  53. elif [ -z "${Le_Deploy_vmwareuag_host}" ]; then
  54. _err "DEPLOY_VMWAREUAG_HOST is required"
  55. return 1
  56. fi
  57. # SSL_VERIFY is optional. If not provided then assume "${DEPLOY_VMWAREUAG_SSL_VERIFY_DEFAULT}"
  58. if [ -n "${DEPLOY_VMWAREUAG_SSL_VERIFY}" ]; then
  59. Le_Deploy_vmwareuag_ssl_verify="${DEPLOY_VMWAREUAG_SSL_VERIFY}"
  60. _savedomainconf Le_Deploy_vmwareuag_ssl_verify "${Le_Deploy_vmwareuag_ssl_verify}"
  61. elif [ -z "${Le_Deploy_vmwareuag_ssl_verify}" ]; then
  62. Le_Deploy_vmwareuag_ssl_verify="${DEPLOY_VMWAREUAG_SSL_VERIFY_DEFAULT}"
  63. fi
  64. # PORT is optional. If not provided then assume "${DEPLOY_VMWAREUAG_PORT_DEFAULT}"
  65. if [ -n "${DEPLOY_VMWAREUAG_PORT}" ]; then
  66. Le_Deploy_vmwareuag_port="${DEPLOY_VMWAREUAG_PORT}"
  67. _savedomainconf Le_Deploy_vmwareuag_port "${Le_Deploy_vmwareuag_port}"
  68. elif [ -z "${Le_Deploy_vmwareuag_port}" ]; then
  69. Le_Deploy_vmwareuag_port="${DEPLOY_VMWAREUAG_PORT_DEFAULT}"
  70. fi
  71. # Set variables for later use
  72. _user="${Le_Deploy_vmwareuag_username}:${Le_Deploy_vmwareuag_password}"
  73. _contenttype="Content-Type: application/json"
  74. _privatekeypem="$(cat "${_ckey}" | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}')"
  75. _certchainpem="$(cat "${_ccert}" "${_cca}" | awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}')"
  76. _port="${Le_Deploy_vmwareuag_port}"
  77. _path="/rest/v1/config/certs/ssl/end_user"
  78. _debug _user "${_user}"
  79. _debug _contenttype "${_contenttype}"
  80. _debug _privatekeypem "${_privatekeypem}"
  81. _debug _certchainpem "${_certchainpem}"
  82. _debug _port "${_port}"
  83. _debug _path "${_path}"
  84. # Create JSON request
  85. _jsonreq=(_mktemp)
  86. _debug _jsonreq "${_jsonreq}"
  87. printf '{ "privateKeyPem": "%s", "certChainPem": "%s" }' "${_privatekeypem}" "${_certchainpem}" > "${_jsonreq}"
  88. _debug JSON "$(cat "${_jsonreq}")"
  89. # Send request via curl
  90. if command -v curl; then
  91. _info "Using curl"
  92. if [ "${Le_Deploy_vmwareuag_ssl_verify}" = "yes" ]; then
  93. _opts=""
  94. else
  95. _opts="-k"
  96. fi
  97. _oldifs=${IFS}
  98. IFS=,
  99. for _host in ${Le_Deploy_vmwareuag_host}; do
  100. _url="https://${_host}:${_port}${_path}"
  101. _debug _url "${_url}"
  102. curl ${_opts} -X PUT -H "${_contenttype}" -d "@${_jsonreq}" -u "${_user}" "${_url}"
  103. done
  104. IFS=${_oldifs}
  105. # Remove JSON request file
  106. [ -f "${_jsonreq}" ] && rm -f "${_jsonreq}"
  107. elif command -v wget; then
  108. _info "Using wget"
  109. _err "Not implemented"
  110. # Remove JSON request file
  111. [ -f "${_jsonreq}" ] && rm -f "${_jsonreq}"
  112. return 1
  113. fi
  114. return 0
  115. }