get-cert 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. #
  3. # This script will extract the necessary certificate from the IMAP server
  4. # It assumes that an attacker isn't trying to spoof you when you connect
  5. # to the IMAP server! You're better off downloading the certificate
  6. # from a trusted source.
  7. #
  8. # Copyright (C) 2003 Theodore Ts'o <tytso@alum.mit.edu>
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. #
  23. HOST=$1
  24. TMPFILE=/tmp/get-cert.$$
  25. ERRFILE=/tmp/get-cert-err.$$
  26. CERTFILE=/tmp/cert.$$
  27. echo QUIT | openssl s_client -connect $HOST:993 -showcerts \
  28. > $TMPFILE 2> $ERRFILE
  29. sed -e '1,/^-----BEGIN CERTIFICATE-----/d' \
  30. -e '/^-----END CERTIFICATE-----/,$d' < $TMPFILE > $CERTFILE
  31. if test -s $CERTFILE ; then
  32. echo -----BEGIN CERTIFICATE-----
  33. cat $CERTFILE
  34. echo -----END CERTIFICATE-----
  35. else
  36. echo "Couldn't retrieve certificate. Openssl reported the following errors"
  37. cat $ERRFILE
  38. fi
  39. /bin/rm -f $TMPFILE $ERRFILE $CERTFILE