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.

86 lines
2.6 KiB

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