Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Darren Tucker | 442a383 | 2004-12-13 18:08:32 +1100 | [diff] [blame] | 3 | # $Id: findssl.sh,v 1.3 2004/12/13 07:08:33 dtucker Exp $ |
| 4 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 5 | # findssl.sh |
| 6 | # Search for all instances of OpenSSL headers and libraries |
| 7 | # and print their versions. |
| 8 | # Intended to help diagnose OpenSSH's "OpenSSL headers do not |
| 9 | # match your library" errors. |
| 10 | # |
| 11 | # Written by Darren Tucker (dtucker at zip dot com dot au) |
| 12 | # This file is placed in the public domain. |
| 13 | # |
Darren Tucker | 442a383 | 2004-12-13 18:08:32 +1100 | [diff] [blame] | 14 | # Release history: |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 15 | # 2002-07-27: Initial release. |
| 16 | # 2002-08-04: Added public domain notice. |
| 17 | # 2003-06-24: Incorporated readme, set library paths. First cvs version. |
Darren Tucker | 442a383 | 2004-12-13 18:08:32 +1100 | [diff] [blame] | 18 | # 2004-12-13: Add traps to cleanup temp files, from Amarendra Godbole. |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 19 | # |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 20 | # "OpenSSL headers do not match your library" are usually caused by |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 21 | # OpenSSH's configure picking up an older version of OpenSSL headers |
| 22 | # or libraries. You can use the following # procedure to help identify |
| 23 | # the cause. |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 24 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 25 | # The output of configure will tell you the versions of the OpenSSL |
| 26 | # headers and libraries that were picked up, for example: |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 27 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 28 | # checking OpenSSL header version... 90604f (OpenSSL 0.9.6d 9 May 2002) |
| 29 | # checking OpenSSL library version... 90602f (OpenSSL 0.9.6b [engine] 9 Jul 2001) |
| 30 | # checking whether OpenSSL's headers match the library... no |
| 31 | # configure: error: Your OpenSSL headers do not match your library |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 32 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 33 | # Now run findssl.sh. This should identify the headers and libraries |
| 34 | # present and their versions. You should be able to identify the |
| 35 | # libraries and headers used and adjust your CFLAGS or remove incorrect |
| 36 | # versions. The output will show OpenSSL's internal version identifier |
| 37 | # and should look something like: |
| 38 | |
| 39 | # $ ./findssl.sh |
| 40 | # Searching for OpenSSL header files. |
| 41 | # 0x0090604fL /usr/include/openssl/opensslv.h |
| 42 | # 0x0090604fL /usr/local/ssl/include/openssl/opensslv.h |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 43 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 44 | # Searching for OpenSSL shared library files. |
| 45 | # 0x0090602fL /lib/libcrypto.so.0.9.6b |
| 46 | # 0x0090602fL /lib/libcrypto.so.2 |
| 47 | # 0x0090581fL /usr/lib/libcrypto.so.0 |
| 48 | # 0x0090602fL /usr/lib/libcrypto.so |
| 49 | # 0x0090581fL /usr/lib/libcrypto.so.0.9.5a |
| 50 | # 0x0090600fL /usr/lib/libcrypto.so.0.9.6 |
| 51 | # 0x0090600fL /usr/lib/libcrypto.so.1 |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 52 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 53 | # Searching for OpenSSL static library files. |
| 54 | # 0x0090602fL /usr/lib/libcrypto.a |
| 55 | # 0x0090604fL /usr/local/ssl/lib/libcrypto.a |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 56 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 57 | # In this example, I gave configure no extra flags, so it's picking up |
| 58 | # the OpenSSL header from /usr/include/openssl (90604f) and the library |
| 59 | # from /usr/lib/ (90602f). |
| 60 | |
| 61 | # |
| 62 | # Adjust these to suit your compiler. |
| 63 | # You may also need to set the *LIB*PATH environment variables if |
| 64 | # DEFAULT_LIBPATH is not correct for your system. |
| 65 | # |
| 66 | CC=gcc |
| 67 | STATIC=-static |
| 68 | |
| 69 | # |
Darren Tucker | 442a383 | 2004-12-13 18:08:32 +1100 | [diff] [blame] | 70 | # Cleanup on interrupt |
| 71 | # |
| 72 | trap 'rm -f conftest.c' INT HUP TERM |
| 73 | |
| 74 | # |
Darren Tucker | a0472e0 | 2003-06-24 20:22:09 +1000 | [diff] [blame] | 75 | # Set up conftest C source |
| 76 | # |
| 77 | rm -f findssl.log |
| 78 | cat >conftest.c <<EOD |
| 79 | #include <stdio.h> |
| 80 | int main(){printf("0x%08xL\n", SSLeay());} |
| 81 | EOD |
| 82 | |
| 83 | # |
| 84 | # Set default library paths if not already set |
| 85 | # |
| 86 | DEFAULT_LIBPATH=/usr/lib:/usr/local/lib |
| 87 | LIBPATH=${LIBPATH:=$DEFAULT_LIBPATH} |
| 88 | LD_LIBRARY_PATH=${LD_LIBRARY_PATH:=$DEFAULT_LIBPATH} |
| 89 | LIBRARY_PATH=${LIBRARY_PATH:=$DEFAULT_LIBPATH} |
| 90 | export LIBPATH LD_LIBRARY_PATH LIBRARY_PATH |
| 91 | |
| 92 | # |
| 93 | # Search for OpenSSL headers and print versions |
| 94 | # |
| 95 | echo Searching for OpenSSL header files. |
| 96 | if [ -x "`which locate`" ] |
| 97 | then |
| 98 | headers=`locate opensslv.h` |
| 99 | else |
| 100 | headers=`find / -name opensslv.h -print 2>/dev/null` |
| 101 | fi |
| 102 | |
| 103 | for header in $headers |
| 104 | do |
| 105 | ver=`awk '/OPENSSL_VERSION_NUMBER/{printf \$3}' $header` |
| 106 | echo "$ver $header" |
| 107 | done |
| 108 | echo |
| 109 | |
| 110 | # |
| 111 | # Search for shared libraries. |
| 112 | # Relies on shared libraries looking like "libcrypto.s*" |
| 113 | # |
| 114 | echo Searching for OpenSSL shared library files. |
| 115 | if [ -x "`which locate`" ] |
| 116 | then |
| 117 | libraries=`locate libcrypto.s` |
| 118 | else |
| 119 | libraries=`find / -name 'libcrypto.s*' -print 2>/dev/null` |
| 120 | fi |
| 121 | |
| 122 | for lib in $libraries |
| 123 | do |
| 124 | (echo "Trying libcrypto $lib" >>findssl.log |
| 125 | dir=`dirname $lib` |
| 126 | LIBPATH="$dir:$LIBPATH" |
| 127 | LD_LIBRARY_PATH="$dir:$LIBPATH" |
| 128 | LIBRARY_PATH="$dir:$LIBPATH" |
| 129 | export LIBPATH LD_LIBRARY_PATH LIBRARY_PATH |
| 130 | ${CC} -o conftest conftest.c $lib 2>>findssl.log |
| 131 | if [ -x ./conftest ] |
| 132 | then |
| 133 | ver=`./conftest 2>/dev/null` |
| 134 | rm -f ./conftest |
| 135 | echo "$ver $lib" |
| 136 | fi) |
| 137 | done |
| 138 | echo |
| 139 | |
| 140 | # |
| 141 | # Search for static OpenSSL libraries and print versions |
| 142 | # |
| 143 | echo Searching for OpenSSL static library files. |
| 144 | if [ -x "`which locate`" ] |
| 145 | then |
| 146 | libraries=`locate libcrypto.a` |
| 147 | else |
| 148 | libraries=`find / -name libcrypto.a -print 2>/dev/null` |
| 149 | fi |
| 150 | |
| 151 | for lib in $libraries |
| 152 | do |
| 153 | libdir=`dirname $lib` |
| 154 | echo "Trying libcrypto $lib" >>findssl.log |
| 155 | ${CC} ${STATIC} -o conftest conftest.c -L${libdir} -lcrypto 2>>findssl.log |
| 156 | if [ -x ./conftest ] |
| 157 | then |
| 158 | ver=`./conftest 2>/dev/null` |
| 159 | rm -f ./conftest |
| 160 | echo "$ver $lib" |
| 161 | fi |
| 162 | done |
| 163 | |
| 164 | # |
| 165 | # Clean up |
| 166 | # |
| 167 | rm -f conftest.c |