Skip to content

Instantly share code, notes, and snippets.

@holly
Created August 3, 2013 14:46
Show Gist options
  • Save holly/6146707 to your computer and use it in GitHub Desktop.
Save holly/6146707 to your computer and use it in GitHub Desktop.
for smtp auth telnet check easy tool
#!/bin/bash
set -e
_plain() {
local user=$1
local pass=$2
echo -ne "$user\0$user\0$pass" | openssl enc -base64 | tr -d '\n'; echo
}
_cram_md5() {
local user=$1
local pass=$2
local challenge=$3
decoded=$(echo $challenge | openssl enc -base64 -d)
hmac=$(echo -n $decoded | openssl md5 -hmac $pass | cut -d' ' -f2)
echo -n "$user $hmac" | openssl enc -base64 | tr -d '\n'; echo
}
usage() {
echo "Usage: $(basename $0) command \$user \$pass [\$challenge]" >&2
echo "command: [plain|cram_md5]"
exit 1
}
if [ $# -lt 3 ]; then
usage
fi
command=$1
shift
eval "_${command} $@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment