Skip to content

Instantly share code, notes, and snippets.

@dlenski
Last active January 20, 2021 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlenski/d6d4df40c8dd538339f750902d68bcfb to your computer and use it in GitHub Desktop.
Save dlenski/d6d4df40c8dd538339f750902d68bcfb to your computer and use it in GitHub Desktop.
Make a working RSA token from seed, expiration date, and serial number
#!/bin/bash
# Takes SN, EXPIRATION, and SEED environment variables
# (SEED must be 32 hex digits) and converts them to
# an RSA SecurID token in CTF format.
#
# Requires:
# stoken >=v0.9
# perl5
# base64
# Show input parameters:
echo "Serial Number: $SN"
echo "Expiration (YYYY/MM/DD): $EXPIRATION"
echo "Seed (hex): $SEED"
# Convert seed to base64 and show it:
SEED_B64=$(echo -n "$SEED" |
perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie' |
base64)
echo "Seed (base64): $SEED_B64"
# Use `stoken export --template` to mash it into a working .sdtid token:
tf1=$(mktemp)
echo "<TKNBatch><TKN><SN>$SN</SN><Death>$EXPIRATION</Death><Seed>=$SEED_B64</Seed></TKN></TKNBatch>" > $tf1
tf2=$(mktemp)
stoken export --random --sdtid --template $tf1 > $tf2
# Show it as RSA SecurID v2 CTF:
echo -n "Compressed token format (v2): "
stoken export --file $tf2
@dlenski
Copy link
Author

dlenski commented Jan 30, 2020

Incorporated into rsa_ct_kip as of dlenski/rsa_ct_kip@fb0ba0a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment