risfeng / aliyun-ddns-shell

阿里云域名解析动态更新IP Shell脚本
MIT License
333 stars 101 forks source link

阿里,虽然会报更新成功,但实际没有 #26

Open faonecze opened 2 years ago

faonecze commented 2 years ago

运行后都正常提示而且说,更新成功。 但是查看日志dns值并没有修改更新.

dyxp520 commented 2 years ago

我也一样,显示如下

阿里云UpdateDomainRecord接口请求处理失败,返回代码:SignatureDoesNotMatch消息:Specified signature is not matched with our calculation. server string to sign is:GET&%2F&AccessKeyId%3DLTAI5tDqtFAQbdxPCD5QVF99%26Action%3DUpdateDomainRecord%26Format%3Djson%26RR%3Dddns%26RecordId%3D741592597507382272%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3Daeac180f-67b8-45ee-b273-754563fd2ec3%26SignatureVersion%3D1.0%26TTL%3D600%26Timestamp%3D2022-02-13T07%253A37%253A01Z%26Type%3DAAAA%26Value%3D240e%253A361%253Ab286%253A600%253A215%253A18ff%253Afe01%253A8131%26Version%3D2015-01-09

itlihuaxin commented 2 years ago

查看阿里云API文档,错误信息才会返回Code,所以修改710行 fun_send_request 为 if [[ "$response" =~ 'Code' ]]; then fun_wirte_log "${message_warning_tag}阿里云$2接口请求处理失败,返回代码:${code}消息:${message}" else fun_wirte_log "${message_success_tag}阿里云$2接口请求处理成功,返回消息:${message}" fi

userhjp commented 2 years ago

@liliangliang176 大佬求解,我也遇到这个问题了,你解决了木有,卡了大半天了0.0

xiaobai403 commented 2 years ago

问题复现

ipv6用户在使用该脚本的时候,会出现SignatureDoesNotMatch的错误。这会造成dns修改失败。

问题定位

该脚本缺少了对ipv6地址的预处理。即没有预先将ipv6地址中的:替换为%3A,这回造成本地签名和阿里云服务器签名不一致的问题。

脚本对ipv6地址的签名(Value部分):

Value%3D2409%3Axxxx%3Axxxx%3A6970%3A215%3Axxxx%3Axxxx%3A8102

阿里云对ipv6地址的签名(Value部分):

Value%3D2409%253Axxxx%253Axxxx%253A6970%253A215%253Axxxx%253Axxxx%253A8102

通过对比,我们可以清楚的看出,脚本将":"编码为了"%3A",而阿里云将":"编码为了"%253A"。也就是说阿里云对":"进行了两次编码,而脚本只进行了一次。

解决方法

  1. 在脚本940行之后,添加以下代码

    fun_get_ip_encryption() {
       local ip=$var_local_wan_ip
       echo -n "$ip" | fun_ip_encode
    }
    
    fun_ip_encode() {
       out=""
       while read -n1 c
       do
           case ${c} in
               [a-zA-Z0-9]) out="$out$c" ;;
               :) out="$out""%3A" ;;
           esac
       done
       echo -n ${out}
    }
  2. 修改第777行中的Value=$var_local_wan_ipValue=$(fun_get_ip_encryption)