home *** CD-ROM | disk | FTP | other *** search
/ ftp.jcu.edu.au / 2014.06.ftp.jcu.edu.au.tar / ftp.jcu.edu.au / v6.3.2b / SWBD63 / fabos-6.3.2b-10.ppc.rpm / fabos-6.3.2b.10.cpio.gz / fabos-6.3.2b.10.cpio / fabos / libexec / certvalidate < prev    next >
Text File  |  2010-11-10  |  2KB  |  68 lines

  1. #!/bin/sh
  2. #
  3. #    Copyright (c) 2006-2008 Brocade Communications Systems, Inc.
  4. #    All rights reserved.
  5. #
  6. #    File name:   certvalidate
  7. #    Module name: fabos/src/security/certvalidate.sh
  8. #
  9. #    This script validates the certificate against the private key of the switch
  10. #
  11. export PATH=/fabos/sbin:/fabos/bin:/bin:/usr/bin:/sbin:/fabos/cliexec
  12.  
  13. # commands
  14. OPENSSL_CMD=/usr/bin/openssl
  15.  
  16. # File locations and suffixes
  17. ROOT_DIR=/etc/fabos
  18. CERT_DIR=$ROOT_DIR/certs/sw0
  19. TMP_DIR=/tmp
  20. CRT_SUFFIX=.crt
  21. CER_SUFFIX=.cer
  22. PEM_SUFFIX=.pem
  23. PVT_KEY_FILE=$CERT_DIR/pvt_key
  24.  
  25. # usage /fabos/libexec/certValidate <certificate_name>
  26. if [ $# -ne 1 ]; then
  27.     exit 1
  28. fi
  29.  
  30. certFile=$1
  31.  
  32. cLen=`expr length $certFile`
  33. let dotIndex="$cLen"-3
  34. fileSuffix=`expr substr $certFile $dotIndex $cLen`
  35.  
  36. if [ ! -f $PVT_KEY_FILE ]; then
  37.     exit 1
  38. fi
  39.  
  40. if [ "$fileSuffix" == "$PEM_SUFFIX" ]; then
  41.     $OPENSSL_CMD x509 -in $CERT_DIR/$certFile -inform PEM -outform DER -out $TMP_DIR/$certFile.der > /dev/null 2>&1
  42.     if [ $? != 0 ]; then
  43.         exit 1
  44.     fi
  45.     rm $TMP_DIR/$certFile.der
  46.     certificate=$CERT_DIR/$certFile
  47.  
  48. elif [ "$fileSuffix" == "$CER_SUFFIX" ] || [ "$fileSuffix" == "$CRT_SUFFIX" ]; then
  49.  
  50.     $OPENSSL_CMD x509 -in $CERT_DIR/$certFile -inform DER -outform PEM -out $TMP_DIR/$certFile.pem > /dev/null 2>&1
  51.     if [ $? != 0 ]; then
  52.         exit 1
  53.     fi
  54.     certificate=$TMP_DIR/$certFile.pem
  55. else
  56.     # any other extension is not supported
  57.     exit 1
  58. fi
  59.  
  60. pvtkeyhash=`$OPENSSL_CMD rsa -noout -modulus -in $PVT_KEY_FILE | $OPENSSL_CMD md5`
  61. certkeyhash=`$OPENSSL_CMD x509 -noout -modulus -in $certificate | $OPENSSL_CMD md5`
  62.  
  63. if [ "$pvtkeyhash" != "$certkeyhash" ]; then
  64.     exit 1
  65. fi
  66.  
  67. exit 0
  68.