Last active
February 6, 2018 13:50
-
-
Save przemoc/6146235 to your computer and use it in GitHub Desktop.
Shell script for calculating Sec-WebSocket-Accept from Sec-WebSocket-Key
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 | |
# 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 |
Author
przemoc
commented
Feb 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment