xref: /freebsd/crypto/openssh/contrib/findssl.sh (revision 02e9120893770924227138ba49df1edb3896112a)
1#!/bin/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
37# $ ./findssl.sh
38# Searching for OpenSSL header files.
39# 0x0090604fL /usr/include/openssl/opensslv.h
40# 0x0090604fL /usr/local/ssl/include/openssl/opensslv.h
41#
42# Searching for OpenSSL shared library files.
43# 0x0090602fL /lib/libcrypto.so.0.9.6b
44# 0x0090602fL /lib/libcrypto.so.2
45# 0x0090581fL /usr/lib/libcrypto.so.0
46# 0x0090602fL /usr/lib/libcrypto.so
47# 0x0090581fL /usr/lib/libcrypto.so.0.9.5a
48# 0x0090600fL /usr/lib/libcrypto.so.0.9.6
49# 0x0090600fL /usr/lib/libcrypto.so.1
50#
51# Searching for OpenSSL static library files.
52# 0x0090602fL /usr/lib/libcrypto.a
53# 0x0090604fL /usr/local/ssl/lib/libcrypto.a
54#
55# In  this  example, I gave configure no extra flags, so it's picking up
56# the  OpenSSL header from /usr/include/openssl (90604f) and the library
57# from /usr/lib/ (90602f).
58
59#
60# Adjust these to suit your compiler.
61# You may also need to set the *LIB*PATH environment variables if
62# DEFAULT_LIBPATH is not correct for your system.
63#
64CC=gcc
65STATIC=-static
66
67#
68# Cleanup on interrupt
69#
70trap 'rm -f conftest.c' INT HUP TERM
71
72#
73# Set up conftest C source
74#
75rm -f findssl.log
76cat >conftest.c <<EOD
77#include <stdio.h>
78int main(){printf("0x%08xL\n", SSLeay());}
79EOD
80
81#
82# Set default library paths if not already set
83#
84DEFAULT_LIBPATH=/usr/lib:/usr/local/lib
85LIBPATH=${LIBPATH:=$DEFAULT_LIBPATH}
86LD_LIBRARY_PATH=${LD_LIBRARY_PATH:=$DEFAULT_LIBPATH}
87LIBRARY_PATH=${LIBRARY_PATH:=$DEFAULT_LIBPATH}
88export LIBPATH LD_LIBRARY_PATH LIBRARY_PATH
89
90# not all platforms have a 'which' command
91if which ls >/dev/null 2>/dev/null; then
92    : which is defined
93else
94    which () {
95	saveIFS="$IFS"
96	IFS=:
97	for p in $PATH; do
98	    if test -x "$p/$1" -a -f "$p/$1"; then
99		IFS="$saveIFS"
100		echo "$p/$1"
101		return 0
102	    fi
103	done
104	IFS="$saveIFS"
105	return 1
106    }
107fi
108
109#
110# Search for OpenSSL headers and print versions
111#
112echo Searching for OpenSSL header files.
113if [ -x "`which locate`" ]
114then
115	headers=`locate opensslv.h`
116else
117	headers=`find / -name opensslv.h -print 2>/dev/null`
118fi
119
120for header in $headers
121do
122	ver=`awk '/OPENSSL_VERSION_NUMBER/{printf \$3}' $header`
123	echo "$ver $header"
124done
125echo
126
127#
128# Search for shared libraries.
129# Relies on shared libraries looking like "libcrypto.s*"
130#
131echo Searching for OpenSSL shared library files.
132if [ -x "`which locate`" ]
133then
134	libraries=`locate libcrypto.s`
135else
136	libraries=`find / -name 'libcrypto.s*' -print 2>/dev/null`
137fi
138
139for lib in $libraries
140do
141	(echo "Trying libcrypto $lib" >>findssl.log
142	dir=`dirname $lib`
143	LIBPATH="$dir:$LIBPATH"
144	LD_LIBRARY_PATH="$dir:$LIBPATH"
145	LIBRARY_PATH="$dir:$LIBPATH"
146	export LIBPATH LD_LIBRARY_PATH LIBRARY_PATH
147	${CC} -o conftest conftest.c $lib 2>>findssl.log
148	if [ -x ./conftest ]
149	then
150		ver=`./conftest 2>/dev/null`
151		rm -f ./conftest
152		echo "$ver $lib"
153	fi)
154done
155echo
156
157#
158# Search for static OpenSSL libraries and print versions
159#
160echo Searching for OpenSSL static library files.
161if [ -x "`which locate`" ]
162then
163	libraries=`locate libcrypto.a`
164else
165	libraries=`find / -name libcrypto.a -print 2>/dev/null`
166fi
167
168for lib in $libraries
169do
170	libdir=`dirname $lib`
171	echo "Trying libcrypto $lib" >>findssl.log
172	${CC} ${STATIC} -o conftest conftest.c -L${libdir} -lcrypto 2>>findssl.log
173	if [ -x ./conftest ]
174	then
175		ver=`./conftest 2>/dev/null`
176		rm -f ./conftest
177		echo "$ver $lib"
178	fi
179done
180
181#
182# Clean up
183#
184rm -f conftest.c
185