最近做了不少需要联调的项目,常遇到接口digest认证问题,对接时常有digest请求不对的情况。为了防止扯皮,写了一个脚本用来校验digest和试错。记录一下。
HA1=MD5(A1)=MD5(username:realm:password)
HA2=MD5(A2)=MD5(method:uri)
response=MD5(HA1:nonce:nc:cnonce:qop:HA2)
#! /bin/bash
username=username""
password="password"
realm="realm"
method="GET" #may be POST
uri="/uri/path"
nonce="fQcWUysgr3pyTEjX7cEkyA==" #根据实际情况填
nc=00000001 #根据实际情况填
cnonce="ICAgICAgICAgICAgICAgICAgICAgICAgMTAzOTY1ODg=" #根据实际情况填
qop=auth #根据实际情况填
loglevel=info #please use "debug" to check detail logs
if [ "$1" ];then
nonce=$1
echo nonce is: $nonce
fi
if [ "$2" ];then
cnonce=$2
echo cnonce is: $cnonce
fi
HA1=$(echo -n $username:$realm:$password|openssl md5|cut -d" " -f2)
HD=$nonce:$nc:$cnonce:$qop
HA2=$(echo -n $method:$uri|openssl md5|cut -d" " -f2)
response=$(echo -n $HA1:$HD:$HA2|openssl md5|cut -d" " -f2)
if [ $loglevel == "debug" ];then
echo $username:$realm:$password
echo "HA1 is:" $HA1
echo HD is: $HD
echo $method:$uri
echo "HA2 is:" $HA2
echo $HA1:$HD:$HA2
fi
标签:nonce,cnonce,检验,echo,HA1,HA2,认证,digest
From: https://www.cnblogs.com/kevin4X/p/17031072.html