Last active
October 10, 2018 20:29
-
-
Save jpbochi/a1723214452eeccaca0de1728bc0c14b to your computer and use it in GitHub Desktop.
bash SSH encrypt/decrypt/sign
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
#!/usr/bin/env sh | |
set -eu | |
# some inspiration from https://raymii.org/s/tutorials/Sign_and_verify_text_files_to_public_keys_via_the_OpenSSL_Command_Line.html | |
MESSAGE=$1 | |
ID_FILE=$(ssh -G [email protected] | grep identityfile | cut -d' ' -f2 | xargs -I % sh -c 'test -r % && echo % || true' | head) | |
echo >&2 '>>> decrypting with this identity file:' $ID_FILE | |
set -o pipefail | |
printf $MESSAGE | base64 --decode | openssl rsautl -decrypt -inkey $ID_FILE |
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
#!/usr/bin/env sh | |
set -eu | |
# some inspiration from https://raymii.org/s/tutorials/Sign_and_verify_text_files_to_public_keys_via_the_OpenSSL_Command_Line.html | |
# MESSAGE=$(pbpaste | tr -d '\n') | |
MESSAGE=$1 | |
ID_FILE=$(ssh -G [email protected] | grep identityfile | cut -d' ' -f2 | xargs -I % sh -c 'test -r % && echo % || true' | head) | |
echo >&2 '>>> encrypting with this identity file:' $ID_FILE | |
set -o pipefail | |
printf $MESSAGE | openssl rsautl -encrypt -inkey ./le-github-app.2018-05-11.private-key.pem | base64 | tr -d '\n' |
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
#!/usr/bin/env sh | |
set -eu | |
# some inspiration from https://raymii.org/s/tutorials/Sign_and_verify_text_files_to_public_keys_via_the_OpenSSL_Command_Line.html | |
MESSAGE=$1 | |
ID_FILE=$(ssh -G [email protected] | grep identityfile | cut -d' ' -f2 | xargs -I % sh -c 'test -r % && echo % || true' | head) | |
echo >&2 '>>> signing with this identity file:' $ID_FILE | |
set -o pipefail | |
SIGNATURE=$(printf $MESSAGE | openssl dgst -sha256 -sign $ID_FILE | base64 | tr -d '\n') | |
ESCAPED_MESSAGE=$(printf $MESSAGE | sed 's/"/\\"/g') | |
echo '{"message":"'$ESCAPED_MESSAGE'","signature":"'$SIGNATURE'"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
more complete version at https://github.com/jpbochi/id-check