home *** CD-ROM | disk | FTP | other *** search
/ ftp.sberbank.sumy.ua / 2014.11.ftp.sberbank.sumy.ua.tar / ftp.sberbank.sumy.ua / incoming / sxtech / regen_sslkeys < prev    next >
Text File  |  2014-08-29  |  3KB  |  149 lines

  1. #!/bin/sh
  2.  
  3. GUI_CERT=/var/eq/eqssl/server
  4. SIBD_CERT=/var/eq/eqssl/sibd
  5.  
  6. key_check()
  7. {
  8.     REMOVE=0
  9.  
  10.     if [ ! -f $SERVER_CRT -o ! -f $SERVER_KEY ]; then
  11.     PROBLEM="is missing."
  12.     REMOVE=1
  13.     return
  14.     fi
  15.  
  16.     # Get and validate various parameters of old certificate and key.
  17.  
  18.     ISSUER=$(openssl x509 -issuer -noout -in $SERVER_CRT | \
  19.          awk '{$1=""; print}')
  20.     O="$(echo $ISSUER | awk -F '[/=]' '{print $9}')"
  21.     OU="$(echo $ISSUER | awk -F '[/=]' '{print $11}')"
  22.  
  23.     SERIAL=$(openssl x509 -serial -noout -in $SERVER_CRT | \
  24.          awk -F= '{print $2}')
  25.  
  26.     if [ "$O"        = "Snake Oil, Ltd" -a \
  27.      "$OU"        = "Certificate Authority" -a \
  28.      "$SERIAL"    = "01" ]; then
  29.     PROBLEM="is an old Apache example key (unsafe)."
  30.         REMOVE=1
  31.     return
  32.     fi
  33.  
  34.     if [ "$SERIAL" = "00" -a "$1" = "-s" ]; then
  35.     PROBLEM="has an invalid serial number."
  36.     REMOVE=1
  37.     return
  38.     fi
  39.  
  40.     KEYMOD=$(openssl rsa -modulus -in $SERVER_KEY -noout | \
  41.          awk -F= '{print $2}')
  42.     CERTMOD=$(openssl x509 -modulus -in $SERVER_CRT -noout | \
  43.           awk -F= '{print $2}')
  44.  
  45.     if [ "$KEYMOD" != "$CERTMOD" ]; then
  46.     PROBLEM="is corrupt (private and public key do not match)."
  47.     REMOVE=1
  48.     return
  49.     fi
  50. }
  51.  
  52. get_ans()
  53. {
  54.     ANSWER="x"
  55.     while [ $ANSWER = "x" ] 
  56.     do
  57.         while read line
  58.         do
  59.        ANSWER="$line"
  60.     done < $inputfile 
  61.     sleep 1
  62.     done
  63.     echo "x" > $inputfile 
  64.     return
  65. }
  66.  
  67. key_clear()
  68. {
  69.     if [ "$PROMPT" != 1 ]; then
  70.     ANSWER=y
  71.     else
  72.     if [ "$inputfile" = "" ]; then
  73.         read -p "Enter 'Y' to acknowledge this message and continue: " \
  74.         ANSWER
  75.     else
  76.        echo "Enter 'y' to acknowledge this message and continue? [y/n]"
  77.        echo 
  78.        get_ans
  79.     fi
  80.     fi
  81.     if [ "$ANSWER" = "Y" -o "$ANSWER" = "y" ]; then
  82.  
  83.     if mount | grep ' / .*read' > /dev/null; then
  84.         mount -u -w /
  85.         REMOUNT=1
  86.     fi
  87.  
  88.     rm -f $SERVER_CRT
  89.     rm -f $SERVER_KEY
  90.     rm -f /.master$SERVER_CRT
  91.     rm -f /.master$SERVER_KEY
  92.     sync
  93.     if [ "$REMOUNT" = "1" ]; then
  94.         mount -u -r /
  95.     fi
  96.     else
  97.     echo "****ABORT*****"
  98.     exit 1
  99.     fi
  100. }
  101.  
  102. check_all_keys()
  103. {
  104.     SERVER_CRT=$SIBD_CERT.crt
  105.     SERVER_KEY=$SIBD_CERT.key
  106.     key_check
  107.     if [ $REMOVE -eq 1 ]; then
  108.     if [ $SIBNUM -eq 2 ]; then
  109.         cat << ZOG
  110. 
  111. Your failover SSL certificate $PROBLEM
  112. This means that your failover peers currently cannot communicate with each
  113. other over SSL.  At the next reboot of this Equalizer its failover certificate
  114. will be regenerated to re-enable failover operation.  Please see the
  115. Technical Note at http://docs.coyotepoint.com for additional steps to
  116. follow after the reboot.
  117. ZOG
  118.         PROMPT=1
  119.     fi
  120.     key_clear
  121.     fi
  122.  
  123.     SERVER_CRT=$GUI_CERT.crt
  124.     SERVER_KEY=$GUI_CERT.key
  125.     key_check -s
  126.     if [ $REMOVE -eq 1 ]; then
  127.         cat << ZOG
  128. ^G^G
  129. Your GUI SSL certificate $PROBLEM
  130. This means that the Equalizer GUI is currently inaccessible over HTTPS
  131. with some or all browsers.  At the next reboot of this Equalizer its
  132. GUI certificate will be regenerated.
  133. ZOG
  134.     PROMPT=1
  135.     key_clear
  136.     fi
  137. }
  138.  
  139. while getopts G: o
  140.     do case "$o" in
  141.     G)    inputfile="$OPTARG";;
  142.     [?])    echo "Usage: $0 [-G] file ..."
  143.         exit 1;;
  144.     esac
  145. done
  146.  
  147. SIBNUM=$(grep sibling /var/eq/eq.conf | wc -l)
  148. check_all_keys
  149.