0

I am trying to use $timestamp and generate hash. I see $timestamp value is not getting assigned and it's always same.

My request:--

curl  -H "Authorization:EG1-HMAC-SHA256;timestamp=$(date +%Y%m%dT%H:%M:%S+0000);nonce=`cat /proc/sys/kernel/random/uuid`;signature=$(echo -n $timestamp | openssl dgst -binary -sha256 -hmac '+abhishek' | openssl enc -base64)"  https://test.com/abcd/v1/test/123/impulse -vv

Output[Request Authorization headers]

Authorization:EG1-HMAC-SHA256;timestamp=20180701T12:33:56+0000;nonce=8ed3eddf-27ac-4f19-ba81-0ecd07aeb50a;signature=6vMTTitxbU0/3DRXAEPej4HyqQTG+V/F5NLGNcqG2ys=

20180701T12:33:56+0000 is the correct value which i want to get substituted in '$(echo -n $timestamp' but it's not happening. $timestamp is not changing at all after the curl command execution.

To Test:-- I initially assigned 0 to timestamp. Executed the above curl command. checked echo $timestamp, it is still same[0].

I am new to linux shell. Any help will be highly appreciated.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
Abhi
  • 3
  • 1
  • `$timestamp is not changing at all after the curl command execution`. How should timestamp variable change after you execute it? The curl command takes argument as is, they can't change on the fly. Please use `$(...)` only, don't use \`. – KamilCuk Jul 01 '18 at 12:53
  • Also see [How to use Shellcheck](https://github.com/koalaman/shellcheck), [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041) (U&L.SE), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639) (SO), [How to debug bash script?](https://askubuntu.com/q/21136) (AskU), [Debugging Bash scripts](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html), etc. – jww Jul 01 '18 at 14:34
  • @KamilCuk Is there any way to make it work? – Abhi Jul 01 '18 at 17:48
  • @jww Thanks will look into it – Abhi Jul 01 '18 at 17:49

1 Answers1

1

It becomes simple when you clean it up and break it down into multiple lines:

url="https://test.com/abcd/v1/test/123/impulse"
timestamp="$(date +%Y%m%dT%H:%M:%S+0000)"
nonce="$(cat /proc/sys/kernel/random/uuid)"
signature="$(openssl dgst -binary -sha256 -hmac '+abhishek' <<< "${timestamp}" \
             | openssl enc -base64)"  

auth_header="Authorization:EG1-HMAC-SHA256"
auth_header="${auth_header};timestamp=${timestamp}"
auth_header="${auth_header};nonce=${nonce}"
auth_header="${auth_header};signature=${signature}"

curl -H "${auth_header}" "${url}" -vv
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • No luck... Tried this too same result.. "auth_header="${auth_header};timestamp=${timestamp}" comes proper but for signature it's not taking the correct timestamp. Not sure if i am missing something – Abhi Jul 01 '18 at 18:07
  • Debug output ++ openssl dgst -binary -sha256 -hmac +cY5lyspNSCBm2klDaoAzX+Ipqh21nbBk4esAQVRHaY= +++ timestamp ++ openssl enc -base64 a.sh: line 6: timestamp: command not found – Abhi Jul 01 '18 at 18:10