Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@przemoc

This comment has been minimized.

Show comment
Hide comment
@przemoc

przemoc Feb 6, 2018

commit 78adfbacbaa9dc465f82d560c3ee678a22fa2c68
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 14:48:41 +0100

    calcswsa.sh: Add copyright notice and MIT license notice.

commit 7b11ae6c4e0bdbd386bbe82e0a6b03bb5f4dcfcc
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 14:49:23 +0100

    Add SPDX License Identifier.

    The Software Package Data Exchange (SPDX) is a good initiative, it has
    matured over time and deserves accelerated adoption in open-source.

    https://spdx.org/learn
    https://spdx.org/using-spdx
    https://spdx.org/license-list
Owner

przemoc commented Feb 6, 2018

commit 78adfbacbaa9dc465f82d560c3ee678a22fa2c68
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 14:48:41 +0100

    calcswsa.sh: Add copyright notice and MIT license notice.

commit 7b11ae6c4e0bdbd386bbe82e0a6b03bb5f4dcfcc
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 14:49:23 +0100

    Add SPDX License Identifier.

    The Software Package Data Exchange (SPDX) is a good initiative, it has
    matured over time and deserves accelerated adoption in open-source.

    https://spdx.org/learn
    https://spdx.org/using-spdx
    https://spdx.org/license-list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment