Created
October 11, 2017 18:46
-
-
Save stampycode/95d630c2626438816f82a230e425c17d to your computer and use it in GitHub Desktop.
hammer a Vault server with encrypt + decrypt requests
This file contains hidden or 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/bash | |
set -e | |
ITERATIONS=2000 | |
BYTES=3000 | |
pppp() { | |
PLAINTEXT=$(head -c${BYTES} /dev/random |base64) | |
CIPHERTEXT=$( | |
curl -s --tlsv1 --header "X-Vault-Token: ${VAULT_TOKEN}" \ | |
--request POST \ | |
--data "{\"plaintext\":\"${PLAINTEXT}\"}" \ | |
${VAULT_ADDR}/v1/transit/encrypt/test |jq -r '.data.ciphertext' 2>.stderr | |
) | |
DECRYPTED=$( | |
curl -s --tlsv1 --header "X-Vault-Token: ${VAULT_TOKEN}" \ | |
--request POST \ | |
--data "{\"ciphertext\":\"${CIPHERTEXT}\"}" \ | |
${VAULT_ADDR}/v1/transit/decrypt/test |jq -r '.data.plaintext' 2>.stderr | |
) | |
if [[ "${DECRYPTED}" != "${PLAINTEXT}" ]] ; then | |
echo "E" | |
else | |
echo "." | |
fi | |
} | |
############### | |
# The watcher reads data from a fifo, until the parent is killed. | |
# It enables continuous yet non-blocking reads. | |
############### | |
watch() { | |
NUM=$1 | |
FILE=$2 | |
MYPID=$$ | |
( | |
eval "exec $NUM<>$FILE" | |
echo "running pipe cleaner" | |
while [[ 1 ]] ; do | |
ps -p "${MYPID}" &>/dev/null || break | |
read -t1 -n1 -u${NUM} out && [[ "" != "${out}" ]] && echo -n $out | |
done | |
) & | |
disown %1 | |
} | |
rm -f .dots .stderr | |
mkfifo .dots | |
mkfifo .stderr | |
watch 7 .dots | |
watch 9 .stderr | |
sleep 0.1 | |
################ | |
# Iterate over the primary connect function, but limit requests to 20 procs in parallel | |
# keep hitting the host until the request count is reached | |
################ | |
echo "" > times.out | |
echo "running processes..." | |
for i in `seq 1 ${ITERATIONS}`; do | |
( | |
#{ time process 1>.dots 2>.stderr ; } 2>&1 |grep real |cut -b6- >> times.out | |
{ time pppp 1>.dots 2>.stderr ; } 2>&1 |grep real |cut -b6- >> times.out | |
) & | |
while [ `jobs -rp |wc -l` -gt 20 ] ; do | |
sleep 0.1 | |
done | |
done | |
wait | |
echo "done" | |
cat times.out | |
rm -f times.out .dots .stderr .jobs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment