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. # 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-alibaba-cloud-cdn-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. Ali_CDN_API="https://cdn.aliyuncs.com/"
  17. ali_cdn_deploy() {
  18. _cdomain="$1"
  19. _ckey="$2"
  20. _ccert="$3"
  21. _cca="$4"
  22. _cfullchain="$5"
  23. _debug _cdomain "$_cdomain"
  24. _debug _ckey "$_ckey"
  25. _debug _ccert "$_ccert"
  26. _debug _cca "$_cca"
  27. _debug _cfullchain "$_cfullchain"
  28. # Load dnsapi/dns_ali.sh to reduce the duplicated codes
  29. # https://github.com/acmesh-official/acme.sh/pull/5205#issuecomment-2357867276
  30. dnsapi_ali="$(_findHook "$_cdomain" "$_SUB_FOLDER_DNSAPI" dns_ali)"
  31. # shellcheck source=/dev/null
  32. if ! . "$dnsapi_ali"; then
  33. _err "Error loading file $dnsapi_ali. Please check your API file and try again."
  34. return 1
  35. fi
  36. _prepare_ali_credentials || return 1
  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. # domain pub pri
  58. _set_cdn_domain_ssl_certificate_query() {
  59. endpoint=$Ali_CDN_API
  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. }