OTS info first draft

This commit is contained in:
kexkey
2019-08-21 17:35:08 -04:00
committed by kexkey
parent 117e62c23c
commit b060fa08b9
5 changed files with 175 additions and 3 deletions

View File

@@ -9,8 +9,12 @@ serve_ots_stamp() {
local request=${1}
local hash=$(echo "${request}" | jq -r ".hash")
trace "[serve_ots_stamp] hash=${hash}"
local callbackUrl=$(echo "${request}" | jq -r ".callbackUrl")
[ "${callbackUrl}" = "null" ] && callbackUrl=
local callbackUrl
callbackUrl=$(echo "${request}" | jq -er ".callbackUrl")
if [ "$?" -ne "0" ]; then
# callbackUrl tag null, so there's no callbackUrl provided
callbackUrl=
fi
trace "[serve_ots_stamp] callbackUrl=${callbackUrl}"
local result
@@ -204,7 +208,7 @@ serve_ots_backoffice() {
trace "[serve_ots_backoffice] url=${url}"
# Call back newly upgraded stamps if url provided
if [ ${#url} -gt 0 ]; then
if [ -n ${url} ]; then
trace "[serve_ots_backoffice] url is not empty, now trying to call it!"
notify_web "${url}"
@@ -301,3 +305,88 @@ request_ots_verify() {
echo "${result}"
return ${returncode}
}
serve_ots_info() {
trace "Entering serve_ots_info()..."
local request=${1}
local hash
hash=$(echo "${request}" | jq -e ".hash" | tr -d '"')
if [ "$?" -ne "0" ]; then
# Hash tag null, so there's no hash provided
hash=
fi
trace "[serve_ots_info] hash=${hash}"
local base64otsfile
base64otsfile=$(echo "${request}" | jq -e ".base64otsfile" | tr -d '"')
if [ "$?" -ne "0" ]; then
# base64otsfile tag null, so there's no base64otsfile provided
base64otsfile=
fi
trace "[serve_ots_info] base64otsfile=${base64otsfile}"
# If file is provided, we will execute info on it
# If file not provided, we will check for hash.ots in our folder and execute info on it
if [ -z "${base64otsfile}" ]; then
if [ -f otsfiles/${hash}.ots ]; then
trace "[serve_ots_info] Constructing base64otsfile from provided hash, file otsfiles/${hash}.ots"
base64otsfile=$(cat otsfiles/${hash}.ots | base64 | tr -d '\n')
else
trace "[serve_ots_info] File otsfiles/${hash}.ots does not exists!"
echo "{\"method\":\"ots_info\",\"result\":\"error\",\"message\":\"OTS File not found\"}"
return 1
fi
fi
local result
local message
local returncode
trace "[serve_ots_info] request_ots_info \"${base64otsfile}\""
result=$(request_ots_info "${base64otsfile}")
returncode=$?
trace_rc ${returncode}
if [ "${returncode}" -eq "0" ]; then
result=$(echo ${result} | jq ".result")
result="{\"method\":\"ots_info\",\"result\":\"success\",\"message\":${result}}"
else
result="{\"method\":\"ots_info\",\"result\":\"error\",\"message\":${result}}"
fi
trace "[serve_ots_info] result=${result}"
# Output response to stdout before exiting with return code
echo "${result}"
return ${returncode}
}
request_ots_info() {
# Request the OTS server to verify
local base64otsfile=${1}
trace "[request_ots_info] base64otsfile=${base64otsfile}"
local returncode
local result
local data
# BODY {"base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
data="{\"base64otsfile\":\"${base64otsfile}\"}"
trace "[request_ots_info] data=${data}"
trace "[request_ots_info] Parsing..."
trace "[request_ots_info] curl -s -d \"${data}\" ${OTSCLIENT_CONTAINER}/info"
result=$(curl -s -d "${data}" ${OTSCLIENT_CONTAINER}/info)
returncode=$?
trace_rc ${returncode}
trace "[request_ots_info] OTS info result=${result}"
if [ "${returncode}" -ne 0 ]; then
trace "[request_ots_info] OTS info error"
fi
echo "${result}"
return ${returncode}
}

View File

@@ -407,6 +407,20 @@ main() {
response_to_client "${response}" ${?}
break
;;
ots_info)
# POST http://192.168.111.152:8080/ots_info
# BODY {"hash":"1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7"}
# BODY {"base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
# BODY {"hash":"1ddfb769eb0b8876bc570e25580e6a53afcf973362ee1ee4b54a807da2e5eed7","base64otsfile":"AE9wZW5UaW1lc3RhbXBzAABQcm9vZ...gABYiWDXPXGQEDxNch"}
# curl -v -d "{\"hash\":\"a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8\"}" localhost:8888/ots_info
# curl -v -d "{\"base64otsfile\":\"$(cat a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8.ots | base64 | tr -d '\n')\"}" localhost:8888/ots_info
# curl -v -d "{\"hash\":\"a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8\",\"base64otsfile\":\"$(cat a6ea81a46fec3d02d40815b8667b388351edecedc1cc9f97aab55b566db7aac8.ots | base64 | tr -d '\n')\"}" localhost:8888/ots_info
response=$(serve_ots_info "${line}")
response_to_client "${response}" ${?}
break
;;
esac
break
fi