From c9febbdd876888e2b16c1b6b57f7658c63bea91e Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 19 Oct 2016 22:14:42 +0800 Subject: [PATCH 1/6] fix for centos ncat and debian default netcat (#330) --- acme.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/acme.sh b/acme.sh index 09920730..0ea9584f 100755 --- a/acme.sh +++ b/acme.sh @@ -1231,14 +1231,29 @@ _startserver() { _debug "_NC" "$_NC" + #for centos ncat + if _contains "$nchelp" "nmap.org" ; then + _debug "Using ncat: nmap.org" + if [ "$DEBUG" ] ; then + if printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort ; then + return + fi + else + if printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort > /dev/null 2>&1; then + return + fi + fi + _err "ncat listen error." + fi + # while true ; do if [ "$DEBUG" ] ; then - if ! printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort ; then - printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC -p $Le_HTTPPort ; + if ! printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC -p $Le_HTTPPort ; then + printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort ; fi else - if ! printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort > /dev/null 2>&1; then - printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC -p $Le_HTTPPort > /dev/null 2>&1 + if ! printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC -p $Le_HTTPPort > /dev/null 2>&1; then + printf "HTTP/1.1 200 OK\r\n\r\n$content" | $_NC $Le_HTTPPort > /dev/null 2>&1 fi fi if [ "$?" != "0" ] ; then From ecf0a710e13cc233d897c6634e0f632dbae2f0ed Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 21 Oct 2016 18:26:35 +0800 Subject: [PATCH 2/6] fix typo --- acme.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acme.sh b/acme.sh index 0ea9584f..1e6b0a56 100755 --- a/acme.sh +++ b/acme.sh @@ -939,13 +939,13 @@ _post() { elif _exists "wget" ; then _debug "WGET" "$WGET" if [ "$needbase64" ] ; then - if [ "$httpmethod"="POST" ] ; then + if [ "$httpmethod" = "POST" ] ; then response="$($WGET -S -O - --user-agent="$USER_AGENT" --header "$_H5" --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" --post-data="$body" "$url" 2>"$HTTP_HEADER" | _base64)" else response="$($WGET -S -O - --user-agent="$USER_AGENT" --header "$_H5" --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" --method $httpmethod --body-data="$body" "$url" 2>"$HTTP_HEADER" | _base64)" fi else - if [ "$httpmethod"="POST" ] ; then + if [ "$httpmethod" = "POST" ] ; then response="$($WGET -S -O - --user-agent="$USER_AGENT" --header "$_H5" --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" --post-data="$body" "$url" 2>"$HTTP_HEADER")" else response="$($WGET -S -O - --user-agent="$USER_AGENT" --header "$_H5" --header "$_H4" --header "$_H3" --header "$_H2" --header "$_H1" --method $httpmethod --body-data="$body" "$url" 2>"$HTTP_HEADER")" From 9774b01b0ed721bc49caf915ad6a50c85eacec85 Mon Sep 17 00:00:00 2001 From: neil Date: Sun, 23 Oct 2016 14:56:52 +0800 Subject: [PATCH 3/6] 2.6.1 support IDN (#335) * Support IDN * fix deactivate idn name * 2.6.1 support IDN --- acme.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/acme.sh b/acme.sh index 1e6b0a56..5a0ee4e7 100755 --- a/acme.sh +++ b/acme.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -VER=2.6.0 +VER=2.6.1 PROJECT_NAME="acme.sh" @@ -482,6 +482,42 @@ _createkey() { fi } + +#domain +_is_idn() { + _is_idn_d="$1" + echo "$_is_idn_d" | grep "[^0-9a-zA-Z.,]" >/dev/null 2>&1 +} + +#aa.com +#aa.com,bb.com,cc.com +_idn() { + __idn_d="$1" + if ! _is_idn "$__idn_d" ; then + printf "%s" "$__idn_d" + return 0 + fi + + if _exists idn ; then + if _contains "$__idn_d" ',' ; then + _i_first="1" + for f in $(echo "$__idn_d" | tr ',' ' ') ; do + [ -z "$f" ] && continue + if [ -z "$_i_first" ] ; then + printf "%s" "," + else + _i_first="" + fi + idn "$f" | tr -d "\r\n" + done + else + idn "$__idn_d" | tr -d "\r\n" + fi + else + _err "Please install idn to process IDN names." + fi +} + #_createcsr cn san_list keyfile csrfile conf _createcsr() { _debug _createcsr @@ -502,6 +538,8 @@ _createcsr() { #single domain _info "Single domain" "$domain" else + domainlist="$(_idn $domainlist)" + _debug2 domainlist "$domainlist" if _contains "$domainlist" "," ; then alt="DNS:$(echo $domainlist | sed "s/,/,DNS:/g")" else @@ -515,7 +553,10 @@ _createcsr() { _savedomainconf Le_OCSP_Stable "$Le_OCSP_Stable" printf -- "\nbasicConstraints = CA:FALSE\n1.3.6.1.5.5.7.1.24=DER:30:03:02:01:05" >> "$csrconf" fi - openssl req -new -sha256 -key "$csrkey" -subj "/CN=$domain" -config "$csrconf" -out "$csr" + + _csr_cn="$(_idn "$domain")" + _debug2 _csr_cn "$_csr_cn" + openssl req -new -sha256 -key "$csrkey" -subj "/CN=$_csr_cn" -config "$csrconf" -out "$csr" } #_signcsr key csr conf cert @@ -2144,7 +2185,7 @@ issue() { _info "Getting new-authz for domain" $d - if ! _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$d\"}}" ; then + if ! _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$(_idn "$d")\"}}" ; then _err "Can not get domain token." _clearup _on_issue_err @@ -3027,7 +3068,7 @@ _deactivate() { do _info "Deactivate: $_d_domain" _d_i="$(_math $_d_i + 1)" - if ! _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$_d_domain\"}}" ; then + if ! _send_signed_request "$API/acme/new-authz" "{\"resource\": \"new-authz\", \"identifier\": {\"type\": \"dns\", \"value\": \"$(_idn "$_d_domain")\"}}" ; then _err "Can not get domain token." return 1 fi @@ -3727,6 +3768,10 @@ _process() { _err "'$_dvalue' is not a valid domain for parameter '$1'" return 1 fi + if _is_idn "$_dvalue" && ! _exists idn ; then + _err "It seems that $_dvalue is an IDN( Internationalized Domain Names), please install 'idn' command first." + return 1 + fi if [ -z "$_domain" ] ; then _domain="$_dvalue" From aba5c634ae3865280c3496fabf48b5790434040d Mon Sep 17 00:00:00 2001 From: neilpang Date: Sun, 23 Oct 2016 15:04:52 +0800 Subject: [PATCH 4/6] minor, add output info for installing alias. fix https://github.com/Neilpang/acme.sh/issues/332 --- acme.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/acme.sh b/acme.sh index 5a0ee4e7..b283ff6b 100755 --- a/acme.sh +++ b/acme.sh @@ -3310,6 +3310,7 @@ _installalias() { _profile="$(_detect_profile)" if [ "$_profile" ] ; then _debug "Found profile: $_profile" + _info "Installing alias to '$_profile'" _setopt "$_profile" ". \"$_envfile\"" _info "OK, Close and reopen your terminal to start using $PROJECT_NAME" else @@ -3321,6 +3322,7 @@ _installalias() { _cshfile="$LE_WORKING_DIR/$PROJECT_ENTRY.csh" _csh_profile="$HOME/.cshrc" if [ -f "$_csh_profile" ] ; then + _info "Installing alias to '$_csh_profile'" _setopt "$_cshfile" "setenv LE_WORKING_DIR" " " "\"$LE_WORKING_DIR\"" _setopt "$_cshfile" "alias $PROJECT_ENTRY" " " "\"$LE_WORKING_DIR/$PROJECT_ENTRY\"" _setopt "$_csh_profile" "source \"$_cshfile\"" @@ -3329,6 +3331,7 @@ _installalias() { #for tcsh _tcsh_profile="$HOME/.tcshrc" if [ -f "$_tcsh_profile" ] ; then + _info "Installing alias to '$_tcsh_profile'" _setopt "$_cshfile" "setenv LE_WORKING_DIR" " " "\"$LE_WORKING_DIR\"" _setopt "$_cshfile" "alias $PROJECT_ENTRY" " " "\"$LE_WORKING_DIR/$PROJECT_ENTRY\"" _setopt "$_tcsh_profile" "source \"$_cshfile\"" From 9aa3be7f9f585ad25f40eed66483f82db0d433a1 Mon Sep 17 00:00:00 2001 From: neilpang Date: Sun, 23 Oct 2016 15:10:09 +0800 Subject: [PATCH 5/6] add _uninstallalias --- acme.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/acme.sh b/acme.sh index b283ff6b..4096288d 100755 --- a/acme.sh +++ b/acme.sh @@ -3447,26 +3447,36 @@ uninstall() { fi _initpath + _uninstallalias + + rm -f $LE_WORKING_DIR/$PROJECT_ENTRY + _info "The keys and certs are in $LE_WORKING_DIR, you can remove them by yourself." + +} + +_uninstallalias() { + _initpath + _profile="$(_detect_profile)" if [ "$_profile" ] ; then + _info "Uninstalling alias from: '$_profile'" text="$(cat $_profile)" echo "$text" | sed "s|^.*\"$LE_WORKING_DIR/$PROJECT_NAME.env\"$||" > "$_profile" fi _csh_profile="$HOME/.cshrc" if [ -f "$_csh_profile" ] ; then + _info "Uninstalling alias from: '$_csh_profile'" text="$(cat $_csh_profile)" echo "$text" | sed "s|^.*\"$LE_WORKING_DIR/$PROJECT_NAME.csh\"$||" > "$_csh_profile" fi _tcsh_profile="$HOME/.tcshrc" if [ -f "$_tcsh_profile" ] ; then + _info "Uninstalling alias from: '$_csh_profile'" text="$(cat $_tcsh_profile)" echo "$text" | sed "s|^.*\"$LE_WORKING_DIR/$PROJECT_NAME.csh\"$||" > "$_tcsh_profile" fi - - rm -f $LE_WORKING_DIR/$PROJECT_ENTRY - _info "The keys and certs are in $LE_WORKING_DIR, you can remove them by yourself." } From 049be10406501f9f9d294cd18841818ff1e3d226 Mon Sep 17 00:00:00 2001 From: neilpang Date: Sun, 23 Oct 2016 20:36:32 +0800 Subject: [PATCH 6/6] fix idn to support European chars https://github.com/Neilpang/acme.sh/issues/331#issuecomment-255583889 --- acme.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/acme.sh b/acme.sh index 4096288d..3eccc3c7 100755 --- a/acme.sh +++ b/acme.sh @@ -486,7 +486,10 @@ _createkey() { #domain _is_idn() { _is_idn_d="$1" - echo "$_is_idn_d" | grep "[^0-9a-zA-Z.,]" >/dev/null 2>&1 + _debug2 _is_idn_d "$_is_idn_d" + _idn_temp=$(printf "%s" "$_is_idn_d" | tr -d "[0-9a-zA-Z.,-]") + _debug2 _idn_temp "$_idn_temp" + [ "$_idn_temp" ] } #aa.com