Skip to content

Commit eaf1100

Browse files
authored
Merge pull request #5310 from acmesh-official/dev
sync
2 parents fc7f861 + df93fb7 commit eaf1100

File tree

9 files changed

+230
-171
lines changed

9 files changed

+230
-171
lines changed

.github/workflows/dockerhub.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ concurrency:
1515
group: ${{ github.workflow }}-${{ github.ref }}
1616
cancel-in-progress: true
1717

18+
env:
19+
DOCKER_IMAGE: neilpang/acme.sh
1820

1921
jobs:
2022
CheckToken:
@@ -44,15 +46,18 @@ jobs:
4446
uses: actions/checkout@v4
4547
- name: Set up QEMU
4648
uses: docker/setup-qemu-action@v2
49+
- name: Extract Docker metadata
50+
id: meta
51+
uses: docker/[email protected]
52+
with:
53+
images: ${DOCKER_IMAGE}
4754
- name: Set up Docker Buildx
4855
uses: docker/setup-buildx-action@v2
4956
- name: login to docker hub
5057
run: |
5158
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
5259
- name: build and push the image
5360
run: |
54-
DOCKER_IMAGE=neilpang/acme.sh
55-
5661
if [[ $GITHUB_REF == refs/tags/* ]]; then
5762
DOCKER_IMAGE_TAG=${GITHUB_REF#refs/tags/}
5863
fi
@@ -66,8 +71,14 @@ jobs:
6671
fi
6772
fi
6873
74+
DOCKER_LABELS=()
75+
while read -r label; do
76+
DOCKER_LABELS+=(--label "${label}")
77+
done <<<"${DOCKER_METADATA_OUTPUT_LABELS}"
78+
6979
docker buildx build \
7080
--tag ${DOCKER_IMAGE}:${DOCKER_IMAGE_TAG} \
81+
"${DOCKER_LABELS[@]}" \
7182
--output "type=image,push=true" \
7283
--build-arg AUTO_UPGRADE=${AUTO_UPGRADE} \
7384
--platform linux/arm64/v8,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386,linux/ppc64le,linux/s390x .

acme.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22

3-
VER=3.0.9
3+
VER=3.1.0
44

55
PROJECT_NAME="acme.sh"
66

@@ -672,8 +672,10 @@ _hex_dump() {
672672
#0 1 2 3 4 5 6 7 8 9 - _ . ~
673673
#30 31 32 33 34 35 36 37 38 39 2d 5f 2e 7e
674674

675+
#_url_encode [upper-hex] the encoded hex will be upper-case if the argument upper-hex is followed
675676
#stdin stdout
676677
_url_encode() {
678+
_upper_hex=$1
677679
_hex_str=$(_hex_dump)
678680
_debug3 "_url_encode"
679681
_debug3 "_hex_str" "$_hex_str"
@@ -883,6 +885,9 @@ _url_encode() {
883885
;;
884886
#other hex
885887
*)
888+
if [ "$_upper_hex" = "upper-hex" ]; then
889+
_hex_code=$(printf "%s" "$_hex_code" | _upper_case)
890+
fi
886891
printf '%%%s' "$_hex_code"
887892
;;
888893
esac
@@ -5111,6 +5116,19 @@ $_authorizations_map"
51115116
_on_issue_err "$_post_hook" "$vlist"
51125117
return 1
51135118
fi
5119+
_retryafter=$(echo "$responseHeaders" | grep -i "^Retry-After *: *[0-9]\+ *" | cut -d : -f 2 | tr -d ' ' | tr -d '\r')
5120+
_sleep_overload_retry_sec=$_retryafter
5121+
if [ "$_sleep_overload_retry_sec" ]; then
5122+
if [ $_sleep_overload_retry_sec -le 600 ]; then
5123+
_sleep $_sleep_overload_retry_sec
5124+
else
5125+
_info "The retryafter=$_retryafter value is too large (> 600), will not retry anymore."
5126+
_clearupwebbroot "$_currentRoot" "$removelevel" "$token"
5127+
_clearup
5128+
_on_issue_err "$_post_hook" "$vlist"
5129+
return 1
5130+
fi
5131+
fi
51145132
done
51155133

51165134
done

deploy/ali_cdn.sh

Lines changed: 19 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/usr/bin/env sh
2+
# shellcheck disable=SC2034,SC2154
23

34
# Script to create certificate to Alibaba Cloud CDN
45
#
6+
# Docs: https://github.com/acmesh-official/acme.sh/wiki/deployhooks#33-deploy-your-certificate-to-cdn-or-dcdn-of-alibaba-cloud-aliyun
7+
#
58
# This deployment required following variables
69
# export Ali_Key="ALIACCESSKEY"
710
# export Ali_Secret="ALISECRETKEY"
11+
# The credentials are shared with all the Alibaba Cloud deploy hooks and dnsapi
12+
#
13+
# To specify the CDN domain that is different from the certificate CN, usually used for multi-domain or wildcard certificates
814
# export DEPLOY_ALI_CDN_DOMAIN="cdn.example.com"
9-
# If you have more than one domain, just
15+
# If you have multiple CDN domains using the same certificate, just
1016
# export DEPLOY_ALI_CDN_DOMAIN="cdn1.example.com cdn2.example.com"
1117
#
12-
# The credentials are shared with all domains, also shared with dns_ali api
18+
# For DCDN, see ali_dcdn deploy hook
1319

14-
Ali_API="https://cdn.aliyuncs.com/"
20+
Ali_CDN_API="https://cdn.aliyuncs.com/"
1521

1622
ali_cdn_deploy() {
1723
_cdomain="$1"
@@ -26,18 +32,16 @@ ali_cdn_deploy() {
2632
_debug _cca "$_cca"
2733
_debug _cfullchain "$_cfullchain"
2834

29-
Ali_Key="${Ali_Key:-$(_readaccountconf_mutable Ali_Key)}"
30-
Ali_Secret="${Ali_Secret:-$(_readaccountconf_mutable Ali_Secret)}"
31-
if [ -z "$Ali_Key" ] || [ -z "$Ali_Secret" ]; then
32-
Ali_Key=""
33-
Ali_Secret=""
34-
_err "You don't specify aliyun api key and secret yet."
35+
# Load dnsapi/dns_ali.sh to reduce the duplicated codes
36+
# https://github.com/acmesh-official/acme.sh/pull/5205#issuecomment-2357867276
37+
dnsapi_ali="$(_findHook "$_cdomain" "$_SUB_FOLDER_DNSAPI" dns_ali)"
38+
# shellcheck source=/dev/null
39+
if ! . "$dnsapi_ali"; then
40+
_err "Error loading file $dnsapi_ali. Please check your API file and try again."
3541
return 1
3642
fi
3743

38-
#save the api key and secret to the account conf file.
39-
_saveaccountconf_mutable Ali_Key "$Ali_Key"
40-
_saveaccountconf_mutable Ali_Secret "$Ali_Secret"
44+
_prepare_ali_credentials || return 1
4145

4246
_getdeployconf DEPLOY_ALI_CDN_DOMAIN
4347
if [ "$DEPLOY_ALI_CDN_DOMAIN" ]; then
@@ -47,8 +51,8 @@ ali_cdn_deploy() {
4751
fi
4852

4953
# read cert and key files and urlencode both
50-
_cert=$(_url_encode_upper <"$_cfullchain")
51-
_key=$(_url_encode_upper <"$_ckey")
54+
_cert=$(_url_encode upper-hex <"$_cfullchain")
55+
_key=$(_url_encode upper-hex <"$_ckey")
5256

5357
_debug2 _cert "$_cert"
5458
_debug2 _key "$_key"
@@ -64,82 +68,9 @@ ali_cdn_deploy() {
6468
return 0
6569
}
6670

67-
#################### Private functions below ##################################
68-
69-
# act ign mtd
70-
_ali_rest() {
71-
act="$1"
72-
ign="$2"
73-
mtd="$3"
74-
75-
signature=$(printf "%s" "$mtd&%2F&$(_ali_urlencode "$query")" | _hmac "sha1" "$(printf "%s" "$Ali_Secret&" | _hex_dump | tr -d " ")" | _base64)
76-
signature=$(_ali_urlencode "$signature")
77-
url="$Ali_API?$query&Signature=$signature"
78-
79-
if [ "$mtd" = "GET" ]; then
80-
response="$(_get "$url")"
81-
else
82-
# post payload is not supported yet because of signature
83-
response="$(_post "" "$url")"
84-
fi
85-
86-
_ret="$?"
87-
_debug2 response "$response"
88-
if [ "$_ret" != "0" ]; then
89-
_err "Error <$act>"
90-
return 1
91-
fi
92-
93-
if [ -z "$ign" ]; then
94-
message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")"
95-
if [ "$message" ]; then
96-
_err "$message"
97-
return 1
98-
fi
99-
fi
100-
}
101-
102-
_ali_urlencode() {
103-
_str="$1"
104-
_str_len=${#_str}
105-
_u_i=1
106-
while [ "$_u_i" -le "$_str_len" ]; do
107-
_str_c="$(printf "%s" "$_str" | cut -c "$_u_i")"
108-
case $_str_c in [a-zA-Z0-9.~_-])
109-
printf "%s" "$_str_c"
110-
;;
111-
*)
112-
printf "%%%02X" "'$_str_c"
113-
;;
114-
esac
115-
_u_i="$(_math "$_u_i" + 1)"
116-
done
117-
}
118-
119-
_ali_nonce() {
120-
#_head_n 1 </dev/urandom | _digest "sha256" hex | cut -c 1-31
121-
#Not so good...
122-
date +"%s%N" | sed 's/%N//g'
123-
}
124-
125-
_timestamp() {
126-
date -u +"%Y-%m-%dT%H%%3A%M%%3A%SZ"
127-
}
128-
129-
# stdin stdout
130-
_url_encode_upper() {
131-
encoded=$(_url_encode)
132-
133-
for match in $(echo "$encoded" | _egrep_o '%..' | sort -u); do
134-
upper=$(echo "$match" | _upper_case)
135-
encoded=$(echo "$encoded" | sed "s/$match/$upper/g")
136-
done
137-
138-
echo "$encoded"
139-
}
140-
14171
# domain pub pri
14272
_set_cdn_domain_ssl_certificate_query() {
73+
endpoint=$Ali_CDN_API
14374
query=''
14475
query=$query'AccessKeyId='$Ali_Key
14576
query=$query'&Action=SetCdnDomainSSLCertificate'

deploy/ali_dcdn.sh

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

0 commit comments

Comments
 (0)