findssl.sh 4.7 KB

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