4.XSDK 调用时 SID授权信息获取失败
本帖最后由 btsome 于 2022-7-31 10:13 编辑在使用 4.X 版本的 1800 设备,调用 SDK api 时进行授权信息获取发现每次验证 SID 有效性时总是提示失败
提示:{"id":1,"jsonrpc":"2.0","error":{"message":"Access denied","code":-32000}}
获取 SID 命令如下:
host=$1
username=$2
password=$3
ret="$(curl -k http://$host/rpc -d '{"jsonrpc":"2.0","method":"challenge","params":{"username":"root"},"id":1}' 2>/dev/null)"
salt="$(echo $ret|awk -F "salt" '{print $2}'|cut -d '"' -f 3)"
nonce="$(echo $ret|awk -F "nonce" '{print $2}'|cut -d '"' -f 3)"
alg="$(echo $ret|awk -F "alg" '{print $2}'|awk -F ":|," '{print $2}')"
pw=$(openssl passwd -$alg -salt "$salt" "$password")
hash=$(echo -n "$username:$pw:$nonce" | md5sum | cut -d' ' -f1)
echo $hash
btsome 发表于 2022-7-31 09:57
操作环境:ubuntu20.04
操作方式:你给的脚本里面应该是生成了 hash,不是直接生成 SID 吧?echo hash 这是 ...
有俩个问题
一是脚本中缺少login操作
而是没有处理好json中的转义字符
现在已修正,修正后的脚本如下,API文档也已经同步修改
#!/bin/sh
host=$1
username=$2
password=$3
which jq 2>&1 >/dev/null || {
echo pleaseinstall jq
exit 1
}
ret="$(curl -k http://$host/rpc -d "{\"jsonrpc\":\"3.0\",\"method\":\"challenge\",\"params\":{\"username\":\"${username}\"},\"id\":1}" 2>/dev/null|jq -c)"
salt="$(echo $ret|awk -F "salt" '{print $2}'|cut -d '"' -f 3)"
nonce="$(echo $ret|awk -F "nonce" '{print $2}'|cut -d '"' -f 3)"
alg="$(echo $ret|awk -F "alg" '{print $2}'|awk -F ":|," '{print $2}')"
pw=$(openssl passwd -$alg -salt "$salt" "$password")
hash=$(echo -n "$username:$pw:$nonce" | md5sum | cut -d' ' -f1)
ret="$(curl -k http://$host/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"login\",\"params\":{\"username\":\"${username}\",\"hash\":\"${hash}\"},\"id\":1}" 2>/dev/null)"
echo $ret
AX1800还是AXT1800呢? 萝卜大侠 发表于 2022-7-29 10:05
AX1800还是AXT1800呢?
GL-AXT1800 btsome 发表于 2022-7-29 12:08
GL-AXT1800
好像是字符串中的转义符导致的,我看下咋解决 萝卜大侠 发表于 2022-7-29 15:56
好像是字符串中的转义符导致的,我看下咋解决
今天看看给处理下吧 同时程序员。。。。。我这功能停了好久了 SID获取的脚本有点问题,下午看了一下,没找到问题,明天继续看 我试了下例子中的脚本,如果在linux下执行生成的SID是没有问题的,但是在windows环境下执行生成就有问题 操作环境:ubuntu20.04
操作方式:你给的脚本里面应该是生成了 hash,不是直接生成 SID 吧?echo hash 这是 hash 吗?
我看你前端登录的时候,需要在登录接口传 hash 然后再生成 SID
你说你尝试可以,是怎样验证的?获取到的 hash 可以直接调用接口获取内容?不行吧?
页:
[1]