Created
December 4, 2024 16:01
-
-
Save Snawoot/a56ed5aa20aa7c4c5048f34148c9316b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
require() { | |
if ! command -v "$1" > /dev/null 2>/dev/null ; then | |
>&2 echo "$1 utility not found!" | |
exit 1 | |
fi | |
} | |
require openssl | |
require xxd | |
require tr | |
require base64 | |
require date | |
if [ $# -ne 3 ]; then | |
>&2 echo "Usage: $0 <hex secret> <username> <duration>" | |
>&2 echo "Example: $0 0123456789abcdef test \"2 hours\"" | |
exit 2 | |
fi | |
secret="$1" | |
username="$2" | |
duration="$3" | |
prefix="dumbproxy grant token v1" | |
ts="$(date -d "$duration" +%s)" | |
hex_ts="$(printf "%016x" "$ts")" | |
hex_digest="$(\ | |
( | |
echo -n "$prefix" | |
echo -n "$username" | |
echo -n "$hex_ts" | xxd -r -p | |
) | openssl mac -macopt "hexkey:$secret" -digest sha256 HMAC | |
)" | |
password="$(\ | |
( | |
echo -n "$hex_ts" | xxd -r -p | |
echo -n "$hex_digest" | xxd -r -p | |
) | base64 -w 0 | tr '+/' '-_' | tr -d '=' | |
)" | |
echo "Username: $username" | |
echo "Password: $password" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment