Shell script for calculating Sec-WebSocket-Accept from Sec-WebSocket-Key
#!/bin/sh | |
# SPDX-License-Identifier: MIT | |
## Copyright (C) 2013 Przemyslaw Pawelczyk <przemoc@gmail.com> | |
## | |
## This script is licensed under the terms of the MIT license. | |
## https://opensource.org/licenses/MIT | |
_calcswsa() | |
{ | |
echo -n "$1"'258EAFA5-E914-47DA-95CA-C5AB0DC85B11' | sha1sum | awk '{print$1}' | xxd -r -p | base64 | |
} | |
if [ -t 0 -a -z "$1" ]; then | |
echo "usage: $0 [-] [SEC_WEBSOCKET_KEY]..." | |
echo | |
echo "For each given Sec-WebSocket-Key (provided on the standard input or as a command-line argument; in that order) returns Sec-WebSocket-Accept in a new line." | |
fi | |
if [ "$1" = "-" -o ! -t 0 ]; then | |
while read -r LINE; do | |
for KEY in $LINE; do | |
_calcswsa "$KEY" | |
done | |
done | |
if [ "$1" = "-" ]; then | |
shift | |
fi | |
fi | |
while [ -n "$1" ]; do | |
_calcswsa "$1" | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.