findssl.sh revision 180744
154561Sbp#!/bin/sh 254561Sbp# 354561Sbp# $Id: findssl.sh,v 1.4 2007/02/19 11:44:25 dtucker Exp $ 454561Sbp# 554561Sbp# findssl.sh 654561Sbp# Search for all instances of OpenSSL headers and libraries 754561Sbp# and print their versions. 854561Sbp# Intended to help diagnose OpenSSH's "OpenSSL headers do not 954561Sbp# match your library" errors. 1054561Sbp# 1154561Sbp# Written by Darren Tucker (dtucker at zip dot com dot au) 1254561Sbp# This file is placed in the public domain. 1354561Sbp# 1454561Sbp# Release history: 1554561Sbp# 2002-07-27: Initial release. 1654561Sbp# 2002-08-04: Added public domain notice. 1754561Sbp# 2003-06-24: Incorporated readme, set library paths. First cvs version. 1854561Sbp# 2004-12-13: Add traps to cleanup temp files, from Amarendra Godbole. 1954561Sbp# 2054561Sbp# "OpenSSL headers do not match your library" are usually caused by 2154561Sbp# OpenSSH's configure picking up an older version of OpenSSL headers 2254561Sbp# or libraries. You can use the following # procedure to help identify 2354561Sbp# the cause. 2454561Sbp# 2554561Sbp# The output of configure will tell you the versions of the OpenSSL 2654561Sbp# headers and libraries that were picked up, for example: 2754561Sbp# 2854561Sbp# checking OpenSSL header version... 90604f (OpenSSL 0.9.6d 9 May 2002) 2954561Sbp# checking OpenSSL library version... 90602f (OpenSSL 0.9.6b [engine] 9 Jul 2001) 3059061Sbp# checking whether OpenSSL's headers match the library... no 3154561Sbp# configure: error: Your OpenSSL headers do not match your library 3254561Sbp# 33139097Sbrueffer# Now run findssl.sh. This should identify the headers and libraries 3454561Sbp# present and their versions. You should be able to identify the 3584530Syar# libraries and headers used and adjust your CFLAGS or remove incorrect 3654561Sbp# versions. The output will show OpenSSL's internal version identifier 3776175Sschweikh# and should look something like: 3854561Sbp 39139097Sbrueffer# $ ./findssl.sh 4097481Sru# Searching for OpenSSL header files. 4198235Skeramida# 0x0090604fL /usr/include/openssl/opensslv.h 4254561Sbp# 0x0090604fL /usr/local/ssl/include/openssl/opensslv.h 4354561Sbp# 44123899Sbrueffer# Searching for OpenSSL shared library files. 4554561Sbp# 0x0090602fL /lib/libcrypto.so.0.9.6b 4697481Sru# 0x0090602fL /lib/libcrypto.so.2 4797481Sru# 0x0090581fL /usr/lib/libcrypto.so.0 4854561Sbp# 0x0090602fL /usr/lib/libcrypto.so 4954561Sbp# 0x0090581fL /usr/lib/libcrypto.so.0.9.5a 5054561Sbp# 0x0090600fL /usr/lib/libcrypto.so.0.9.6 5154561Sbp# 0x0090600fL /usr/lib/libcrypto.so.1 5254561Sbp# 5354561Sbp# Searching for OpenSSL static library files. 5454561Sbp# 0x0090602fL /usr/lib/libcrypto.a 5554561Sbp# 0x0090604fL /usr/local/ssl/lib/libcrypto.a 5654561Sbp# 5754561Sbp# In this example, I gave configure no extra flags, so it's picking up 5854561Sbp# the OpenSSL header from /usr/include/openssl (90604f) and the library 5954561Sbp# from /usr/lib/ (90602f). 6054561Sbp 6154561Sbp# 6254561Sbp# Adjust these to suit your compiler. 6354561Sbp# You may also need to set the *LIB*PATH environment variables if 6454561Sbp# DEFAULT_LIBPATH is not correct for your system. 6554561Sbp# 66123899SbruefferCC=gcc 6754561SbpSTATIC=-static 6854561Sbp 6954561Sbp# 7054561Sbp# Cleanup on interrupt 7154561Sbp# 7254561Sbptrap 'rm -f conftest.c' INT HUP TERM 7354561Sbp 74123899Sbrueffer# 7554561Sbp# Set up conftest C source 76123899Sbrueffer# 7754561Sbprm -f findssl.log 78123899Sbrueffercat >conftest.c <<EOD 7995106Sbp#include <stdio.h> 80123899Sbruefferint main(){printf("0x%08xL\n", SSLeay());} 81123899SbruefferEOD 82123899Sbrueffer 8397481Sru# 8497481Sru# Set default library paths if not already set 8595106Sbp# 8654561SbpDEFAULT_LIBPATH=/usr/lib:/usr/local/lib 8754561SbpLIBPATH=${LIBPATH:=$DEFAULT_LIBPATH} 8854561SbpLD_LIBRARY_PATH=${LD_LIBRARY_PATH:=$DEFAULT_LIBPATH} 89123899SbruefferLIBRARY_PATH=${LIBRARY_PATH:=$DEFAULT_LIBPATH} 9054561Sbpexport LIBPATH LD_LIBRARY_PATH LIBRARY_PATH 9154561Sbp 9254561Sbp# not all platforms have a 'which' command 9354561Sbpif which ls >/dev/null 2>/dev/null; then 94123899Sbrueffer : which is defined 9559061Sbpelse 9654561Sbp which () { 9754561Sbp saveIFS="$IFS" 9854561Sbp IFS=: 9976175Sschweikh for p in $PATH; do 10054561Sbp if test -x "$p/$1" -a -f "$p/$1"; then 10154561Sbp IFS="$saveIFS" 10254561Sbp echo "$p/$1" 10354561Sbp return 0 10454561Sbp fi 10554561Sbp done 10659061Sbp IFS="$saveIFS" 10767627Sasmodai return 1 108208027Suqs } 109208027Suqsfi 110208027Suqs 111208027Suqs# 112# Search for OpenSSL headers and print versions 113# 114echo Searching for OpenSSL header files. 115if [ -x "`which locate`" ] 116then 117 headers=`locate opensslv.h` 118else 119 headers=`find / -name opensslv.h -print 2>/dev/null` 120fi 121 122for header in $headers 123do 124 ver=`awk '/OPENSSL_VERSION_NUMBER/{printf \$3}' $header` 125 echo "$ver $header" 126done 127echo 128 129# 130# Search for shared libraries. 131# Relies on shared libraries looking like "libcrypto.s*" 132# 133echo Searching for OpenSSL shared library files. 134if [ -x "`which locate`" ] 135then 136 libraries=`locate libcrypto.s` 137else 138 libraries=`find / -name 'libcrypto.s*' -print 2>/dev/null` 139fi 140 141for lib in $libraries 142do 143 (echo "Trying libcrypto $lib" >>findssl.log 144 dir=`dirname $lib` 145 LIBPATH="$dir:$LIBPATH" 146 LD_LIBRARY_PATH="$dir:$LIBPATH" 147 LIBRARY_PATH="$dir:$LIBPATH" 148 export LIBPATH LD_LIBRARY_PATH LIBRARY_PATH 149 ${CC} -o conftest conftest.c $lib 2>>findssl.log 150 if [ -x ./conftest ] 151 then 152 ver=`./conftest 2>/dev/null` 153 rm -f ./conftest 154 echo "$ver $lib" 155 fi) 156done 157echo 158 159# 160# Search for static OpenSSL libraries and print versions 161# 162echo Searching for OpenSSL static library files. 163if [ -x "`which locate`" ] 164then 165 libraries=`locate libcrypto.a` 166else 167 libraries=`find / -name libcrypto.a -print 2>/dev/null` 168fi 169 170for lib in $libraries 171do 172 libdir=`dirname $lib` 173 echo "Trying libcrypto $lib" >>findssl.log 174 ${CC} ${STATIC} -o conftest conftest.c -L${libdir} -lcrypto 2>>findssl.log 175 if [ -x ./conftest ] 176 then 177 ver=`./conftest 2>/dev/null` 178 rm -f ./conftest 179 echo "$ver $lib" 180 fi 181done 182 183# 184# Clean up 185# 186rm -f conftest.c 187