Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
More resilient JWT decoding in dev tools
Browse files Browse the repository at this point in the history
Also better dependency checking/error messages.
Now using the step crypto helper instead of manual
decoding the token, which solves the base64
padding issues we were hitting with formatting a
decoded token for inspection.

Signed-off-by: Elliot Murphy <[email protected]>
  • Loading branch information
statik committed Jul 27, 2019
1 parent 7874b28 commit 01c3e71
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 16 deletions.
23 changes: 23 additions & 0 deletions dc
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
#!/bin/bash

set -e

USAGE='dc <docker-compose commands>'
DESCRIPTION='
Convenience alias for docker-compose.
Dependencies: requires docker-compose command to be installed.'

function usage() {
echo "$USAGE" "$DESCRIPTION" >&2
}

type docker-compose >/dev/null 2>&1 || {
echo >&2 "Error: docker-compose must be installed. Aborting."
usage
exit 1
}
[ $# -eq 0 ] || {
usage
exit 1
}

exec docker-compose $*
25 changes: 25 additions & 0 deletions dca
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
#!/bin/bash

set -e

USAGE='dca <docker-compose commands>'
DESCRIPTION='
Layers in a docker-compose command for access to additional dev
containers. Specify any normal docker-compose command such as
run or build.
Dependencies: requires docker-compose command to be installed.'

function usage() {
echo "$USAGE" "$DESCRIPTION" >&2
}

type docker-compose >/dev/null 2>&1 || {
echo >&2 "Error: docker-compose must be installed. Aborting."
usage
exit 1
}
[ $# -eq 0 ] || {
usage
exit 1
}

exec docker-compose -f docker-compose.yml -f docker-compose.admin.yml $*
42 changes: 26 additions & 16 deletions dump-token
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#!/bin/bash
set -e

USAGE='dump-token'
DESCRIPTION='
Decodes a JWT from Haven GRC.
This is useful for inspecting the claims present in the token when
working on claim mappers in keycloak.
Dependencies: requires step command to be installed: try brew install step'

function usage() {
echo "$USAGE" "$DESCRIPTION" >&2
}

type step >/dev/null 2>&1 || {
echo >&2 "Error: step cli must be installed. Aborting."
usage
exit 1
}
[ $# -eq 0 ] || {
usage
exit 1
}

TOKEN=`./get-token`
IFS=. read header payload signature <<<"${TOKEN}"
# echo length of payload is ${#payload}
# base64 strings should have = padding to make them a multiple of 3
# since we extract a chunk from the middle of the JWT it has no padding
# we add padding as needed to avoid a warning from base64 decode command
padding=""
if (( ${#payload} % 3 == 1 ))
then
# echo "Adding a double ="
padding="="
elif (( ${#payload} % 3 == 2 ))
then
# echo "Adding a double =="
padding="=="
fi
printf "%s%s" $payload $padding|base64 --decode|jq .

echo ${TOKEN} | step crypto jwt inspect --insecure

0 comments on commit 01c3e71

Please sign in to comment.