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.

88 lines
2.7 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034,SC2154
  3. # Script to create certificate to Alibaba Cloud CDN
  4. #
  5. # Docs: https://github.com/acmesh-official/acme.sh/wiki/deployhooks#33-deploy-your-certificate-to-cdn-or-dcdn-of-alibaba-cloud-aliyun
  6. #
  7. # This deployment required following variables
  8. # export Ali_Key="ALIACCESSKEY"
  9. # export Ali_Secret="ALISECRETKEY"
  10. # The credentials are shared with all the Alibaba Cloud deploy hooks and dnsapi
  11. #
  12. # To specify the CDN domain that is different from the certificate CN, usually used for multi-domain or wildcard certificates
  13. # export DEPLOY_ALI_CDN_DOMAIN="cdn.example.com"
  14. # If you have multiple CDN domains using the same certificate, just
  15. # export DEPLOY_ALI_CDN_DOMAIN="cdn1.example.com cdn2.example.com"
  16. #
  17. # For DCDN, see ali_dcdn deploy hook
  18. Ali_CDN_API="https://cdn.aliyuncs.com/"
  19. ali_cdn_deploy() {
  20. _cdomain="$1"
  21. _ckey="$2"
  22. _ccert="$3"
  23. _cca="$4"
  24. _cfullchain="$5"
  25. _debug _cdomain "$_cdomain"
  26. _debug _ckey "$_ckey"
  27. _debug _ccert "$_ccert"
  28. _debug _cca "$_cca"
  29. _debug _cfullchain "$_cfullchain"
  30. # Load dnsapi/dns_ali.sh to reduce the duplicated codes
  31. # https://github.com/acmesh-official/acme.sh/pull/5205#issuecomment-2357867276
  32. dnsapi_ali="$(_findHook "$_cdomain" "$_SUB_FOLDER_DNSAPI" dns_ali)"
  33. # shellcheck source=/dev/null
  34. if ! . "$dnsapi_ali"; then
  35. _err "Error loading file $dnsapi_ali. Please check your API file and try again."
  36. return 1
  37. fi
  38. _prepare_ali_credentials || return 1
  39. _getdeployconf DEPLOY_ALI_CDN_DOMAIN
  40. if [ "$DEPLOY_ALI_CDN_DOMAIN" ]; then
  41. _savedeployconf DEPLOY_ALI_CDN_DOMAIN "$DEPLOY_ALI_CDN_DOMAIN"
  42. else
  43. DEPLOY_ALI_CDN_DOMAIN="$_cdomain"
  44. fi
  45. # read cert and key files and urlencode both
  46. _cert=$(_url_encode upper-hex <"$_cfullchain")
  47. _key=$(_url_encode upper-hex <"$_ckey")
  48. _debug2 _cert "$_cert"
  49. _debug2 _key "$_key"
  50. ## update domain ssl config
  51. for domain in $DEPLOY_ALI_CDN_DOMAIN; do
  52. _set_cdn_domain_ssl_certificate_query "$domain" "$_cert" "$_key"
  53. if _ali_rest "Set CDN domain SSL certificate for $domain" "" POST; then
  54. _info "Domain $domain certificate has been deployed successfully"
  55. fi
  56. done
  57. return 0
  58. }
  59. # domain pub pri
  60. _set_cdn_domain_ssl_certificate_query() {
  61. endpoint=$Ali_CDN_API
  62. query=''
  63. query=$query'AccessKeyId='$Ali_Key
  64. query=$query'&Action=SetCdnDomainSSLCertificate'
  65. query=$query'&CertType=upload'
  66. query=$query'&DomainName='$1
  67. query=$query'&Format=json'
  68. query=$query'&SSLPri='$3
  69. query=$query'&SSLProtocol=on'
  70. query=$query'&SSLPub='$2
  71. query=$query'&SignatureMethod=HMAC-SHA1'
  72. query=$query"&SignatureNonce=$(_ali_nonce)"
  73. query=$query'&SignatureVersion=1.0'
  74. query=$query'&Timestamp='$(_timestamp)
  75. query=$query'&Version=2018-05-10'
  76. }