#!/bin/sh

# Usage: keycheck.sh <serial number>
#if [ "$#" -ne 1 ]; then
#    echo ""
#    echo "Illegal number of parameters."
#    echo "Usage: keycheck.sh <serial number>"
#    echo ""
#    exit 0
#fi

# Extract serial number from identity config file

SERIAL_NUMBER=$1

# Build key check URL inserting base64 MD5 hash of the key
# This will be evaluated on the server and return 200 if key hash matches the 
# key with the same serial number on the server.

B64_KEY_HASH=`openssl dgst -md5 -binary /Insight/keys/id.key | base64`

#echo "B64_KEY_HASH=$B64_KEY_HASH"

URLENC_KEY_HASH=`php -r "echo urlencode(\"$B64_KEY_HASH\");"`

#echo "URLENC_KEY_HASH=$URLENC_KEY_HASH"


URL="https://collector.millerwelds.com/Auth/ValidateDeviceRegistration?Base64EncodedSharedKeyHash=$URLENC_KEY_HASH&DeviceSerial=$SERIAL_NUMBER" 

#echo "URL=$URL"

# Submit the URL to the server using wget
wget -O keycheckout.txt -S $URL



