3 # Copyright 2007. Petar Zhivkov Petrov
4 # pesho.petrov@gmail.com
9 echo "Usage: $0 clientName serverName"
14 _count="`echo "$1" | sed -e "s/[^$2]//g" | tr -d "\n" | wc -c`"
21 read -p "$1" _password
24 countChars "$_password" ":"
25 if [ $_count != 0 ]; then
26 echo "Sorry, password must not contain \":\" characters"
36 local clientLower="`echo "$1" | tr "[:upper:]" "[:lower:]"`"
37 local serverLower="`echo "$2" | tr "[:upper:]" "[:lower:]"`"
38 local secret="`md5 -qs "$clientLower:$serverLower:$3"`"
39 _secret="\$md5\$$secret"
42 if [ $# -eq 1 -a "X$1" = "X-v" ]; then
43 echo "Csup authentication key generator"
46 elif [ $# -ne 2 ]; then
55 # Client name must contain exactly one '@' and at least one '.'.
56 # It must not contain a ':'.
59 countChars "$clientName" "@"
62 countChars "$clientName" "."
64 if [ $aCount -ne 1 -o $dotCount -eq 0 ]; then
65 echo "Client name must have the form of an e-mail address,"
66 echo "e.g., \"user@domain.com\""
70 countChars "$clientName" ":"
72 if [ $colonCount -gt 0 ]; then
73 echo "Client name must not contain \":\" characters"
78 # Server name must not contain '@' and must have at least one '.'.
79 # It also must not contain a ':'.
82 countChars "$serverName" "@"
85 countChars "$serverName" "."
87 if [ $aCount != 0 -o $dotCount = 0 ]; then
88 echo "Server name must be a fully-qualified domain name."
89 echo "e.g., \"host.domain.com\""
93 countChars "$serverName" ":"
95 if [ $colonCount -gt 0 ]; then
96 echo "Server name must not contain \":\" characters"
101 # Ask for password and generate secret.
105 readPassword "Enter password: "
106 makeSecret "$clientName" "$serverName" "$_password"
109 readPassword "Enter same password again: "
110 makeSecret "$clientName" "$serverName" "$_password"
113 if [ "X$secret" = "X$secret2" ]; then
116 echo "Passwords did not match. Try again."
122 echo "Send this line to the server administrator at $serverName:"
123 echo "-------------------------------------------------------------------------------"
124 echo "$clientName:$secret::"
125 echo "-------------------------------------------------------------------------------"
126 echo "Be sure to send it using a secure channel!"
128 echo "Add this line to your file \"$HOME/.csup/auth\", replacing \"XXX\""
129 echo "with the password you typed in:"
130 echo "-------------------------------------------------------------------------------"
131 echo "$serverName:$clientName:XXX:"
132 echo "-------------------------------------------------------------------------------"
133 echo "Make sure the file is readable and writable only by you!"